Implement readline's backward-kill-word.
This restores the previous behavior of `unix-word-rubout` as `backward-kill-word`, which is closer to the naming used in readline. It is bound to <Alt-Backspace> by default, though <Ctrl-Backspace> will also work due to a builtin binding. Resolves #1698.
This commit is contained in:
parent
f9c09a1f43
commit
6bcdacf1ce
@ -946,6 +946,7 @@ How many steps to zoom out.
|
||||
|<<repeat-command,repeat-command>>|Repeat the last executed command.
|
||||
|<<rl-backward-char,rl-backward-char>>|Move back a character.
|
||||
|<<rl-backward-delete-char,rl-backward-delete-char>>|Delete the character before the cursor.
|
||||
|<<rl-backward-kill-word,rl-backward-kill-word>>|Remove chars from the cursor to the beginning of the word.
|
||||
|<<rl-backward-word,rl-backward-word>>|Move back to the start of the current or previous word.
|
||||
|<<rl-beginning-of-line,rl-beginning-of-line>>|Move to the start of the line.
|
||||
|<<rl-delete-char,rl-delete-char>>|Delete the character after the cursor.
|
||||
@ -1193,6 +1194,12 @@ Delete the character before the cursor.
|
||||
|
||||
This acts like readline's backward-delete-char.
|
||||
|
||||
[[rl-backward-kill-word]]
|
||||
=== rl-backward-kill-word
|
||||
Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's backward-kill-word. Any non-alphanumeric character is considered a word delimiter.
|
||||
|
||||
[[rl-backward-word]]
|
||||
=== rl-backward-word
|
||||
Move back to the start of the current or previous word.
|
||||
@ -1251,7 +1258,7 @@ This acts like readline's unix-line-discard.
|
||||
=== rl-unix-word-rubout
|
||||
Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's unix-word-rubout.
|
||||
This acts like readline's unix-word-rubout. Whitespace is used as a word delimiter.
|
||||
|
||||
[[rl-yank]]
|
||||
=== rl-yank
|
||||
|
@ -1587,7 +1587,8 @@ KEY_DATA = collections.OrderedDict([
|
||||
('rl-unix-line-discard', ['<Ctrl-U>']),
|
||||
('rl-kill-line', ['<Ctrl-K>']),
|
||||
('rl-kill-word', ['<Alt-D>']),
|
||||
('rl-unix-word-rubout', ['<Ctrl-W>', '<Alt-Backspace>']),
|
||||
('rl-unix-word-rubout', ['<Ctrl-W>']),
|
||||
('rl-backward-kill-word', ['<Alt-Backspace>']),
|
||||
('rl-yank', ['<Ctrl-Y>']),
|
||||
('rl-delete-char', ['<Ctrl-?>']),
|
||||
('rl-backward-delete-char', ['<Ctrl-H>']),
|
||||
|
@ -153,7 +153,8 @@ class ReadlineBridge:
|
||||
def rl_unix_word_rubout(self):
|
||||
"""Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's unix-word-rubout.
|
||||
This acts like readline's unix-word-rubout. Whitespace is used as a
|
||||
word delimiter.
|
||||
"""
|
||||
widget = self._widget()
|
||||
if widget is None:
|
||||
@ -178,6 +179,21 @@ class ReadlineBridge:
|
||||
self._deleted[widget] = widget.selectedText()
|
||||
widget.del_()
|
||||
|
||||
@cmdutils.register(instance='readline-bridge', hide=True,
|
||||
modes=[typ.KeyMode.command, typ.KeyMode.prompt])
|
||||
def rl_backward_kill_word(self):
|
||||
"""Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's backward-kill-word. Any non-alphanumeric
|
||||
character is considered a word delimiter.
|
||||
"""
|
||||
widget = self._widget()
|
||||
if widget is None:
|
||||
return
|
||||
widget.cursorWordBackward(True)
|
||||
self._deleted[widget] = widget.selectedText()
|
||||
widget.del_()
|
||||
|
||||
@cmdutils.register(instance='readline-bridge', hide=True,
|
||||
modes=[typ.KeyMode.command, typ.KeyMode.prompt])
|
||||
def rl_kill_word(self):
|
||||
|
@ -269,6 +269,25 @@ def test_rl_kill_word(lineedit, bridge, text, deleted, rest):
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text, deleted, rest', [
|
||||
('test delete|foobar', 'delete', 'test |foobar'),
|
||||
('test delete |foobar', 'delete ', 'test |foobar'),
|
||||
('open -t github.com/foo/bar |', 'bar ', 'open -t github.com/foo/|'),
|
||||
('open -t |github.com/foo/bar', 't ', 'open -|github.com/foo/bar'),
|
||||
fixme(('test del<ete>foobar', 'delete', 'test |foobar')),
|
||||
('test del<ete >foobar', 'del', 'test |ete foobar'), # wrong
|
||||
])
|
||||
def test_rl_backward_kill_word(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete to word beginning and see if it comes back with yank."""
|
||||
lineedit.set_aug_text(text)
|
||||
bridge.rl_backward_kill_word()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
|
||||
|
||||
def test_rl_yank_no_text(lineedit, bridge):
|
||||
"""Test yank without having deleted anything."""
|
||||
lineedit.clear()
|
||||
|
Loading…
Reference in New Issue
Block a user