Skip to content

Commit e3d6a83

Browse files
committed
[textinput] Enable Xterm-like movement between words, i.e. using Ctrl+{Left,Right}
Enable fast word movement à la Xterm (using Ctrl+Left and Ctrl+Right). Most users coming from a GUI (GTK+, Win32, etc.) will find this convenient, but also Archlinux users, given that the default `inputrc` file for GNU Readline providesthese bindings (see https://wiki.archlinux.org/title/Readline#Fast_word_movement).
1 parent b553d38 commit e3d6a83

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

core/textinput/src/textinput/KeyBinding.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace textinput {
3737
return C(In.GetRaw());
3838
}
3939
// else
40-
return ToCommandExtended(In.GetExtendedInput(), HadEscPending);
40+
return ToCommandExtended(In.GetExtendedInput(), In.GetModifier(),
41+
HadEscPending);
4142
}
4243

4344
Editor::Command
@@ -113,6 +114,7 @@ namespace textinput {
113114

114115
Editor::Command
115116
KeyBinding::ToCommandExtended(InputData::EExtendedInput EI,
117+
unsigned char modifier,
116118
bool HadEscPending) {
117119
// Convert extended input into the corresponding Command.
118120
typedef Editor::Command C;
@@ -122,8 +124,12 @@ namespace textinput {
122124
case InputData::kEIEnd: return C(Editor::kMoveEnd);
123125
case InputData::kEIUp: return C(Editor::kCmdHistOlder);
124126
case InputData::kEIDown: return C(Editor::kCmdHistNewer);
125-
case InputData::kEILeft: return C(Editor::kMoveLeft);
126-
case InputData::kEIRight: return C(Editor::kMoveRight);
127+
case InputData::kEILeft:
128+
return (modifier & InputData::kModCtrl)
129+
? C(Editor::kMovePrevWord) : C(Editor::kMoveLeft);
130+
case InputData::kEIRight:
131+
return (modifier & InputData::kModCtrl)
132+
? C(Editor::kMoveNextWord) : C(Editor::kMoveRight);
127133
case InputData::kEIPgUp: return C(Editor::kCmdIgnore);
128134
case InputData::kEIPgDown: return C(Editor::kCmdIgnore);
129135
case InputData::kEIBackSpace:

core/textinput/src/textinput/KeyBinding.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace textinput {
4242
Editor::Command ToCommandCtrl(char In, bool HadEscPending);
4343
Editor::Command ToCommandEsc(char In);
4444
Editor::Command ToCommandExtended(InputData::EExtendedInput EI,
45+
unsigned char modifier,
4546
bool HadEscPending);
4647
bool fEscPending; // Dangling ESC is waiting to be processed
4748
bool fEscCmdEnabled; // Single ESC has a meaning

0 commit comments

Comments
 (0)