Use NeighborList for history in statusbar.
This commit is contained in:
parent
7fc45728a9
commit
82f7e46459
@ -28,6 +28,7 @@ from PyQt5.QtGui import QPainter, QKeySequence, QValidator
|
|||||||
import qutebrowser.utils.config as config
|
import qutebrowser.utils.config as config
|
||||||
import qutebrowser.commands.keys as keys
|
import qutebrowser.commands.keys as keys
|
||||||
from qutebrowser.utils.url import urlstring
|
from qutebrowser.utils.url import urlstring
|
||||||
|
from qutebrowser.utils.types import NeighborList
|
||||||
|
|
||||||
|
|
||||||
class StatusBar(QWidget):
|
class StatusBar(QWidget):
|
||||||
@ -218,8 +219,7 @@ class _Command(QLineEdit):
|
|||||||
history: The command history, with newer commands at the bottom.
|
history: The command history, with newer commands at the bottom.
|
||||||
_statusbar: The statusbar (parent) QWidget.
|
_statusbar: The statusbar (parent) QWidget.
|
||||||
_shortcuts: Defined QShortcuts to prevent GCing.
|
_shortcuts: Defined QShortcuts to prevent GCing.
|
||||||
_tmphist: The temporary history for history browsing
|
_tmphist: The temporary history for history browsing as NeighborList.
|
||||||
_histpos: The current position inside _tmphist
|
|
||||||
_validator: The current command validator.
|
_validator: The current command validator.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
@ -257,8 +257,7 @@ class _Command(QLineEdit):
|
|||||||
super().__init__(statusbar)
|
super().__init__(statusbar)
|
||||||
# FIXME
|
# FIXME
|
||||||
self._statusbar = statusbar
|
self._statusbar = statusbar
|
||||||
self._histpos = None
|
self._tmphist = None
|
||||||
self._tmphist = []
|
|
||||||
self.setStyleSheet("""
|
self.setStyleSheet("""
|
||||||
QLineEdit {
|
QLineEdit {
|
||||||
border: 0px;
|
border: 0px;
|
||||||
@ -297,45 +296,49 @@ class _Command(QLineEdit):
|
|||||||
pre = self.text().strip()
|
pre = self.text().strip()
|
||||||
logging.debug('Preset text: "{}"'.format(pre))
|
logging.debug('Preset text: "{}"'.format(pre))
|
||||||
if pre:
|
if pre:
|
||||||
self._tmphist = [e for e in self.history if e.startswith(pre)]
|
items = [e for e in self.history if e.startswith(pre)]
|
||||||
else:
|
else:
|
||||||
self._tmphist = self.history
|
items = self.history
|
||||||
self._histpos = len(self._tmphist) - 1
|
if not items:
|
||||||
|
raise ValueError("No history found!")
|
||||||
|
self._tmphist = NeighborList(items)
|
||||||
|
return self._tmphist.lastitem()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _histbrowse_stop(self):
|
def _histbrowse_stop(self):
|
||||||
"""Stop browsing the history."""
|
"""Stop browsing the history."""
|
||||||
self._histpos = None
|
self._tmphist = None
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _on_key_up_pressed(self):
|
def _on_key_up_pressed(self):
|
||||||
"""Handle Up presses (go back in history)."""
|
"""Handle Up presses (go back in history)."""
|
||||||
logging.debug("history up [pre]: pos {}".format(self._histpos))
|
if self._tmphist is None:
|
||||||
if self._histpos is None:
|
try:
|
||||||
self._histbrowse_start()
|
item = self._histbrowse_start()
|
||||||
elif self._histpos <= 0:
|
except ValueError:
|
||||||
return
|
# no history
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
self._histpos -= 1
|
try:
|
||||||
if not self._tmphist:
|
item = self._tmphist.previtem()
|
||||||
return
|
except IndexError:
|
||||||
logging.debug("history up: {} / len {} / pos {}".format(
|
# at beginning of history
|
||||||
self._tmphist, len(self._tmphist), self._histpos))
|
return
|
||||||
self.set_cmd_text(self._tmphist[self._histpos])
|
if item:
|
||||||
|
self.set_cmd_text(item)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _on_key_down_pressed(self):
|
def _on_key_down_pressed(self):
|
||||||
"""Handle Down presses (go forward in history)."""
|
"""Handle Down presses (go forward in history)."""
|
||||||
logging.debug("history up [pre]: pos {}".format(self._histpos,
|
if not self._tmphist:
|
||||||
self._tmphist, len(self._tmphist), self._histpos))
|
|
||||||
if (self._histpos is None or
|
|
||||||
self._histpos >= len(self._tmphist) - 1 or
|
|
||||||
not self._tmphist):
|
|
||||||
return
|
return
|
||||||
self._histpos += 1
|
try:
|
||||||
logging.debug("history up: {} / len {} / pos {}".format(
|
item = self._tmphist.nextitem()
|
||||||
self._tmphist, len(self._tmphist), self._histpos))
|
except IndexError:
|
||||||
self.set_cmd_text(self._tmphist[self._histpos])
|
logging.debug("At end of history")
|
||||||
|
return
|
||||||
|
if item:
|
||||||
|
self.set_cmd_text(item)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _on_return_pressed(self):
|
def _on_return_pressed(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user