Make alt+backspace delete the previous word

i.e. alt+backspace now sends ^W (werase). THis matches the behavior of
terminal.app and gnome-terminal. Fixes #264
This commit is contained in:
Kovid Goyal 2018-01-05 21:08:42 +05:30
parent 88e9c21a3b
commit fdcfcfa1b9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 25 additions and 19 deletions

36
kitty/keys.h generated
View File

@ -487,12 +487,12 @@ static inline const char*
key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) { key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
switch(mode) { switch(mode) {
case NORMAL: case NORMAL:
switch(action & 3) { case 3: return NULL; switch(action & 3) { case 3: return NULL;
case 0: // RELEASE case 0: // RELEASE
return NULL; return NULL;
case 1: // PRESS case 1: // PRESS
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 50: // ESCAPE case 50: // ESCAPE
@ -920,7 +920,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x02\x1b\x09"; return "\x02\x1b\x09";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x33\x7e"; return "\x06\x1b\x5b\x32\x3b\x33\x7e";
case 55: // DELETE case 55: // DELETE
@ -1071,7 +1071,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x03\x1b\x5b\x5a"; return "\x03\x1b\x5b\x5a";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x34\x7e"; return "\x06\x1b\x5b\x32\x3b\x34\x7e";
case 55: // DELETE case 55: // DELETE
@ -1690,7 +1690,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
} // end switch(mods) } // end switch(mods)
case 2: // REPEAT case 2: // REPEAT
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 50: // ESCAPE case 50: // ESCAPE
@ -2118,7 +2118,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x02\x1b\x09"; return "\x02\x1b\x09";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x33\x7e"; return "\x06\x1b\x5b\x32\x3b\x33\x7e";
case 55: // DELETE case 55: // DELETE
@ -2269,7 +2269,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x03\x1b\x5b\x5a"; return "\x03\x1b\x5b\x5a";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x34\x7e"; return "\x06\x1b\x5b\x32\x3b\x34\x7e";
case 55: // DELETE case 55: // DELETE
@ -2891,12 +2891,12 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case APPLICATION: case APPLICATION:
switch(action & 3) { case 3: return NULL; switch(action & 3) { case 3: return NULL;
case 0: // RELEASE case 0: // RELEASE
return NULL; return NULL;
case 1: // PRESS case 1: // PRESS
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 50: // ESCAPE case 50: // ESCAPE
@ -3324,7 +3324,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x02\x1b\x09"; return "\x02\x1b\x09";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x33\x7e"; return "\x06\x1b\x5b\x32\x3b\x33\x7e";
case 55: // DELETE case 55: // DELETE
@ -3475,7 +3475,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x03\x1b\x5b\x5a"; return "\x03\x1b\x5b\x5a";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x34\x7e"; return "\x06\x1b\x5b\x32\x3b\x34\x7e";
case 55: // DELETE case 55: // DELETE
@ -4094,7 +4094,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
} // end switch(mods) } // end switch(mods)
case 2: // REPEAT case 2: // REPEAT
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 50: // ESCAPE case 50: // ESCAPE
@ -4522,7 +4522,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x02\x1b\x09"; return "\x02\x1b\x09";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x33\x7e"; return "\x06\x1b\x5b\x32\x3b\x33\x7e";
case 55: // DELETE case 55: // DELETE
@ -4673,7 +4673,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case 52: // TAB case 52: // TAB
return "\x03\x1b\x5b\x5a"; return "\x03\x1b\x5b\x5a";
case 53: // BACKSPACE case 53: // BACKSPACE
return "\x02\x1b\x7f"; return "\x01\x17";
case 54: // INSERT case 54: // INSERT
return "\x06\x1b\x5b\x32\x3b\x34\x7e"; return "\x06\x1b\x5b\x32\x3b\x34\x7e";
case 55: // DELETE case 55: // DELETE
@ -5295,9 +5295,9 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
case EXTENDED: case EXTENDED:
switch(action & 3) { case 3: return NULL; switch(action & 3) { case 3: return NULL;
case 0: // RELEASE case 0: // RELEASE
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 0: // SPACE case 0: // SPACE
@ -9061,7 +9061,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
} // end switch(mods) } // end switch(mods)
case 1: // PRESS case 1: // PRESS
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 0: // SPACE case 0: // SPACE
@ -12825,7 +12825,7 @@ key_lookup(uint8_t key, KeyboardMode mode, uint8_t mods, uint8_t action) {
} // end switch(mods) } // end switch(mods)
case 2: // REPEAT case 2: // REPEAT
switch (mods & 0xf) { switch (mods & 0xf) {
case 0x0: case 0x0:
switch(key & 0x7f) { default: return NULL; switch(key & 0x7f) { default: return NULL;
case 0: // SPACE case 0: // SPACE

View File

@ -26,7 +26,13 @@ def modify_complex_key(name, amt):
control_codes = {} control_codes = {}
smkx_key_map = {} smkx_key_map = {}
alt_codes = {defines.GLFW_KEY_TAB: b'\033\t', defines.GLFW_KEY_ENTER: b'\033\r', defines.GLFW_KEY_ESCAPE: b'\033\033', defines.GLFW_KEY_BACKSPACE: b'\033\177'} alt_codes = {
defines.GLFW_KEY_TAB: b'\033\t',
defines.GLFW_KEY_ENTER: b'\033\r',
defines.GLFW_KEY_ESCAPE: b'\033\033',
# alt+bs matches iTerm and gnome-terminal
defines.GLFW_KEY_BACKSPACE: b'\x17'
}
shift_alt_codes = alt_codes.copy() shift_alt_codes = alt_codes.copy()
shift_alt_codes[defines.GLFW_KEY_TAB] = key_as_bytes('kcbt') shift_alt_codes[defines.GLFW_KEY_TAB] = key_as_bytes('kcbt')
alt_mods = (defines.GLFW_MOD_ALT, defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT) alt_mods = (defines.GLFW_MOD_ALT, defines.GLFW_MOD_SHIFT | defines.GLFW_MOD_ALT)