Allow other chars than : to be used for commandline
This commit is contained in:
parent
891fa581fd
commit
c0f01d9219
@ -61,7 +61,7 @@ class QuteBrowser(QApplication):
|
||||
self.mainwindow.tabs.keypress.connect(self.keyparser.handle)
|
||||
self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.run)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(
|
||||
self.mainwindow.status.cmd.returnPressed.connect(
|
||||
self.mainwindow.tabs.setFocus)
|
||||
self.commandparser.error.connect(self.mainwindow.status.disp_error)
|
||||
self.keyparser.commandparser.error.connect(
|
||||
|
@ -9,6 +9,9 @@ from PyQt5.QtCore import QObject, pyqtSignal
|
||||
from qutebrowser.commands.utils import (CommandParser, ArgumentCountError,
|
||||
NoSuchCommandError)
|
||||
|
||||
# Possible chars for starting a commandline input
|
||||
startchars = ":/?"
|
||||
|
||||
|
||||
class KeyParser(QObject):
|
||||
"""Parser for vim-like key sequences."""
|
||||
@ -61,8 +64,8 @@ class KeyParser(QObject):
|
||||
|
||||
self.keystring += txt
|
||||
|
||||
if self.keystring == ':':
|
||||
self.set_cmd_text.emit('')
|
||||
if any(self.keystring == c for c in startchars):
|
||||
self.set_cmd_text.emit(self.keystring)
|
||||
self.keystring = ''
|
||||
return
|
||||
|
||||
@ -102,7 +105,7 @@ class KeyParser(QObject):
|
||||
except ArgumentCountError:
|
||||
logging.debug('Filling statusbar with partial command {}'.format(
|
||||
cmdstr_hay))
|
||||
self.set_cmd_text.emit(cmdstr_hay + ' ')
|
||||
self.set_cmd_text.emit(':{} '.format(cmdstr_hay))
|
||||
return
|
||||
|
||||
def _match_key(self, cmdstr_needle):
|
||||
|
@ -5,6 +5,8 @@ from PyQt5.QtWidgets import QLineEdit, QShortcut
|
||||
from PyQt5.QtCore import pyqtSignal, Qt
|
||||
from PyQt5.QtGui import QValidator, QKeySequence
|
||||
|
||||
import qutebrowser.commands.keys as keys
|
||||
|
||||
|
||||
class Command(QLineEdit):
|
||||
"""The commandline part of the statusbar."""
|
||||
@ -28,7 +30,7 @@ class Command(QLineEdit):
|
||||
self.statusbar = statusbar
|
||||
self.setStyleSheet("border: 0px; padding-left: 1px")
|
||||
self.setValidator(Validator())
|
||||
self.returnPressed.connect(self.process_cmd)
|
||||
self.returnPressed.connect(self.process_cmdline)
|
||||
self.textEdited.connect(self._histbrowse_stop)
|
||||
|
||||
for (key, handler) in [
|
||||
@ -43,18 +45,19 @@ class Command(QLineEdit):
|
||||
sc.setContext(Qt.WidgetWithChildrenShortcut)
|
||||
sc.activated.connect(handler)
|
||||
|
||||
def process_cmd(self):
|
||||
def process_cmdline(self):
|
||||
"""Handle the command in the status bar."""
|
||||
self._histbrowse_stop()
|
||||
text = self.text().lstrip(':')
|
||||
text = self.text()
|
||||
if not self.history or text != self.history[-1]:
|
||||
self.history.append(text)
|
||||
self.setText('')
|
||||
self.got_cmd.emit(text)
|
||||
if text[0] == ':':
|
||||
self.got_cmd.emit(text.lstrip(':'))
|
||||
|
||||
def set_cmd(self, text):
|
||||
"""Preset the statusbar to some text."""
|
||||
self.setText(':' + text)
|
||||
self.setText(text)
|
||||
self.setFocus()
|
||||
|
||||
def append_cmd(self, text):
|
||||
@ -85,7 +88,7 @@ class Command(QLineEdit):
|
||||
history already.
|
||||
"""
|
||||
|
||||
pre = self.text().strip().lstrip(':')
|
||||
pre = self.text().strip()
|
||||
logging.debug('Preset text: "{}"'.format(pre))
|
||||
if pre:
|
||||
self._tmphist = [e for e in self.history if e.startswith(pre)]
|
||||
@ -138,8 +141,7 @@ class Validator(QValidator):
|
||||
|
||||
Returns a tuple (status, string, pos) as a QValidator should.\
|
||||
"""
|
||||
|
||||
if string.startswith(':'):
|
||||
if any(string.startswith(c) for c in keys.startchars):
|
||||
return (QValidator.Acceptable, string, pos)
|
||||
else:
|
||||
return (QValidator.Invalid, string, pos)
|
||||
|
Loading…
Reference in New Issue
Block a user