Merge branch 'rcorre-unix_filename_rubout'
This commit is contained in:
commit
9eec3f25fb
@ -22,6 +22,8 @@ Added
|
||||
|
||||
- New `:rl-backward-kill-word` command which does what `:rl-unix-word-rubout`
|
||||
did before v0.8.0.
|
||||
- New `:rl-unix-filename-rubout` command which is similar to readline's
|
||||
`unix-filename-rubout`.
|
||||
|
||||
Changed
|
||||
~~~~~~~
|
||||
|
@ -955,6 +955,7 @@ How many steps to zoom out.
|
||||
|<<rl-forward-word,rl-forward-word>>|Move forward to the end of the next word.
|
||||
|<<rl-kill-line,rl-kill-line>>|Remove chars from the cursor to the end of the line.
|
||||
|<<rl-kill-word,rl-kill-word>>|Remove chars from the cursor to the end of the current word.
|
||||
|<<rl-unix-filename-rubout,rl-unix-filename-rubout>>|Remove chars from the cursor to the previous path separator.
|
||||
|<<rl-unix-line-discard,rl-unix-line-discard>>|Remove chars backward from the cursor to the beginning of the line.
|
||||
|<<rl-unix-word-rubout,rl-unix-word-rubout>>|Remove chars from the cursor to the beginning of the word.
|
||||
|<<rl-yank,rl-yank>>|Paste the most recently deleted text.
|
||||
@ -1248,6 +1249,12 @@ Remove chars from the cursor to the end of the current word.
|
||||
|
||||
This acts like readline's kill-word.
|
||||
|
||||
[[rl-unix-filename-rubout]]
|
||||
=== rl-unix-filename-rubout
|
||||
Remove chars from the cursor to the previous path separator.
|
||||
|
||||
This acts like readline's unix-filename-rubout.
|
||||
|
||||
[[rl-unix-line-discard]]
|
||||
=== rl-unix-line-discard
|
||||
Remove chars backward from the cursor to the beginning of the line.
|
||||
|
@ -148,14 +148,8 @@ 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_unix_word_rubout(self):
|
||||
"""Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's unix-word-rubout. Whitespace is used as a
|
||||
word delimiter.
|
||||
"""
|
||||
def _rubout(self, delim):
|
||||
"""Delete backwards using the characters in delim as boundaries."""
|
||||
widget = self._widget()
|
||||
if widget is None:
|
||||
return
|
||||
@ -164,14 +158,14 @@ class ReadlineBridge:
|
||||
|
||||
target_position = cursor_position
|
||||
|
||||
is_word_boundary = True
|
||||
while is_word_boundary and target_position > 0:
|
||||
is_word_boundary = text[target_position - 1] == " "
|
||||
is_boundary = True
|
||||
while is_boundary and target_position > 0:
|
||||
is_boundary = text[target_position - 1] in delim
|
||||
target_position -= 1
|
||||
|
||||
is_word_boundary = False
|
||||
while not is_word_boundary and target_position > 0:
|
||||
is_word_boundary = text[target_position - 1] == " "
|
||||
is_boundary = False
|
||||
while not is_boundary and target_position > 0:
|
||||
is_boundary = text[target_position - 1] in delim
|
||||
target_position -= 1
|
||||
|
||||
moveby = cursor_position - target_position - 1
|
||||
@ -179,6 +173,25 @@ 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_unix_word_rubout(self):
|
||||
"""Remove chars from the cursor to the beginning of the word.
|
||||
|
||||
This acts like readline's unix-word-rubout. Whitespace is used as a
|
||||
word delimiter.
|
||||
"""
|
||||
self._rubout([' '])
|
||||
|
||||
@cmdutils.register(instance='readline-bridge', hide=True,
|
||||
modes=[typ.KeyMode.command, typ.KeyMode.prompt])
|
||||
def rl_unix_filename_rubout(self):
|
||||
"""Remove chars from the cursor to the previous path separator.
|
||||
|
||||
This acts like readline's unix-filename-rubout.
|
||||
"""
|
||||
self._rubout([' ', '/'])
|
||||
|
||||
@cmdutils.register(instance='readline-bridge', hide=True,
|
||||
modes=[typ.KeyMode.command, typ.KeyMode.prompt])
|
||||
def rl_backward_kill_word(self):
|
||||
|
@ -96,6 +96,26 @@ class LineEdit(QLineEdit):
|
||||
return ''.join(chars)
|
||||
|
||||
|
||||
def _validate_deletion(lineedit, bridge, method, text, deleted, rest):
|
||||
"""Run and validate a text deletion method on the ReadLine bridge.
|
||||
|
||||
Args:
|
||||
lineedit: The LineEdit instance.
|
||||
bridge: The ReadlineBridge instance.
|
||||
method: Reference to the method on the bridge to test.
|
||||
text: The starting 'augmented' text (see LineEdit.set_aug_text)
|
||||
deleted: The text that should be deleted when the method is invoked.
|
||||
rest: The augmented text that should remain after method is invoked.
|
||||
"""
|
||||
lineedit.set_aug_text(text)
|
||||
method()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lineedit(qtbot, monkeypatch):
|
||||
"""Fixture providing a LineEdit."""
|
||||
@ -206,13 +226,8 @@ def test_rl_backward_delete_char(text, expected, lineedit, bridge):
|
||||
])
|
||||
def test_rl_unix_line_discard(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete from the cursor to the beginning of the line and yank back."""
|
||||
lineedit.set_aug_text(text)
|
||||
bridge.rl_unix_line_discard()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_unix_line_discard, text,
|
||||
deleted, rest)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text, deleted, rest', [
|
||||
@ -222,13 +237,8 @@ def test_rl_unix_line_discard(lineedit, bridge, text, deleted, rest):
|
||||
])
|
||||
def test_rl_kill_line(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete from the cursor to the end of line and yank back."""
|
||||
lineedit.set_aug_text(text)
|
||||
bridge.rl_kill_line()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_kill_line, text, deleted,
|
||||
rest)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text, deleted, rest', [
|
||||
@ -241,13 +251,21 @@ def test_rl_kill_line(lineedit, bridge, text, deleted, rest):
|
||||
])
|
||||
def test_rl_unix_word_rubout(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete to word beginning and see if it comes back with yank."""
|
||||
lineedit.set_aug_text(text)
|
||||
bridge.rl_unix_word_rubout()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_unix_word_rubout, text,
|
||||
deleted, rest)
|
||||
|
||||
|
||||
@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'),
|
||||
('open foo/bar.baz|', 'bar.baz', 'open foo/|'),
|
||||
])
|
||||
def test_rl_unix_filename_rubout(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete filename segment and see if it comes back with yank."""
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_unix_filename_rubout, text,
|
||||
deleted, rest)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text, deleted, rest', [
|
||||
@ -260,13 +278,8 @@ def test_rl_unix_word_rubout(lineedit, bridge, text, deleted, rest):
|
||||
])
|
||||
def test_rl_kill_word(lineedit, bridge, text, deleted, rest):
|
||||
"""Delete to word end and see if it comes back with yank."""
|
||||
lineedit.set_aug_text(text)
|
||||
bridge.rl_kill_word()
|
||||
assert bridge._deleted[lineedit] == deleted
|
||||
assert lineedit.aug_text() == rest
|
||||
lineedit.clear()
|
||||
bridge.rl_yank()
|
||||
assert lineedit.aug_text() == deleted + '|'
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_kill_word, text, deleted,
|
||||
rest)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('text, deleted, rest', [
|
||||
@ -276,16 +289,12 @@ def test_rl_kill_word(lineedit, bridge, text, deleted, rest):
|
||||
('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
|
||||
('open foo/bar.baz|', 'baz', 'open foo/bar.|'),
|
||||
])
|
||||
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 + '|'
|
||||
_validate_deletion(lineedit, bridge, bridge.rl_backward_kill_word, text,
|
||||
deleted, rest)
|
||||
|
||||
|
||||
def test_rl_yank_no_text(lineedit, bridge):
|
||||
|
Loading…
Reference in New Issue
Block a user