From c1094b66609ff9e750560cf4f24651e1992806a8 Mon Sep 17 00:00:00 2001 From: Justin Partain Date: Thu, 26 Oct 2017 09:16:56 -0400 Subject: [PATCH] Feature - incremental_search Added config option to find on a page incrementally, renewing the search each time a new character is entered. --- qutebrowser/config/configdata.yml | 5 +++++ qutebrowser/mainwindow/statusbar/command.py | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 1318e8979..4843ad7c8 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -43,6 +43,11 @@ ignore_case: default: smart desc: When to find text on a page case-insensitively. +incremental_search: + type: Bool + default: False + desc: Find text on a page incrementally, renewing the search for each typing character. + new_instance_open_target: type: name: String diff --git a/qutebrowser/mainwindow/statusbar/command.py b/qutebrowser/mainwindow/statusbar/command.py index af2dc3dc9..1a42001c4 100644 --- a/qutebrowser/mainwindow/statusbar/command.py +++ b/qutebrowser/mainwindow/statusbar/command.py @@ -26,7 +26,8 @@ from qutebrowser.keyinput import modeman, modeparsers from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.misc import cmdhistory, editor from qutebrowser.misc import miscwidgets as misc -from qutebrowser.utils import usertypes, log, objreg, message +from qutebrowser.utils import usertypes, log, objreg +from qutebrowser.config import config class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): @@ -45,6 +46,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): update_completion: Emitted when the completion should be shown/updated. show_cmd: Emitted when command input should be shown. hide_cmd: Emitted when command input can be hidden. + update_search: Emitted when search term could be updated. """ got_cmd = pyqtSignal([str], [str, int]) @@ -53,6 +55,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): update_completion = pyqtSignal() show_cmd = pyqtSignal() hide_cmd = pyqtSignal() + update_search = pyqtSignal() def __init__(self, *, win_id, private, parent=None): misc.CommandLineEdit.__init__(self, parent=parent) @@ -66,6 +69,8 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): self.cursorPositionChanged.connect(self.update_completion) self.textChanged.connect(self.update_completion) self.textChanged.connect(self.updateGeometry) + self.textChanged.connect(self.update_search) + self.update_search.connect(self.incrementSearch) def prefix(self): """Get the currently entered command prefix.""" @@ -238,3 +243,13 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit): text = 'x' width = self.fontMetrics().width(text) return QSize(width, height) + + def incrementSearch(self): + if config.val.incremental_search == True: + search_prefixes = { + '/': 'search -- ', + '?': 'search -r -- ', + } + if self.prefix() == '/' or self.prefix() == '?': + text = self.text() + self.got_cmd[str].emit(search_prefixes[text[0]] + text[1:])