diff --git a/qutebrowser/misc/readline.py b/qutebrowser/misc/readline.py index cb0ffd996..e527a9abe 100644 --- a/qutebrowser/misc/readline.py +++ b/qutebrowser/misc/readline.py @@ -158,7 +158,23 @@ class ReadlineBridge: widget = self._widget() if widget is None: return - widget.cursorWordBackward(True) + cursor_position = widget.cursorPosition() + text = widget.text() + + target_position = cursor_position + + is_word_boundary = True + while is_word_boundary and target_position > 0: + is_word_boundary = text[target_position - 1] == " " + target_position -= 1 + + is_word_boundary = False + while not is_word_boundary and target_position > 0: + is_word_boundary = text[target_position - 1] == " " + target_position -= 1 + + moveby = cursor_position - target_position - 1 + widget.cursorBackward(True, moveby) self._deleted[widget] = widget.selectedText() widget.del_() diff --git a/tests/unit/misc/test_readline.py b/tests/unit/misc/test_readline.py index 5bd414f16..f59828779 100644 --- a/tests/unit/misc/test_readline.py +++ b/tests/unit/misc/test_readline.py @@ -234,6 +234,8 @@ def test_rl_kill_line(lineedit, bridge, 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 |', 'github.com/foo/bar ', 'open -t |'), + ('open -t |github.com/foo/bar', '-t ', 'open |github.com/foo/bar'), fixme(('test delfoobar', 'delete', 'test |foobar')), ('test delfoobar', 'del', 'test |ete foobar'), # wrong ])