Move current tab to CompletionInfo
That way it can be used by other future completions easily as well.
This commit is contained in:
parent
5e2275502a
commit
e9cf19503d
|
|
@ -25,7 +25,7 @@ from PyQt5.QtCore import pyqtSlot, QObject, QTimer
|
|||
from qutebrowser.config import config
|
||||
from qutebrowser.commands import runners
|
||||
from qutebrowser.misc import objects
|
||||
from qutebrowser.utils import log, utils, debug
|
||||
from qutebrowser.utils import log, utils, debug, objreg
|
||||
from qutebrowser.completion.models import miscmodels
|
||||
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ class CompletionInfo:
|
|||
config = attr.ib()
|
||||
keyconf = attr.ib()
|
||||
win_id = attr.ib()
|
||||
cur_tab = attr.ib()
|
||||
|
||||
|
||||
class Completer(QObject):
|
||||
|
|
@ -254,12 +255,17 @@ class Completer(QObject):
|
|||
return
|
||||
|
||||
self._last_before_cursor = before_cursor
|
||||
|
||||
args = (x for x in before_cursor[1:] if not x.startswith('-'))
|
||||
cur_tab = objreg.get('tab', scope='tab', window=self._win_id,
|
||||
tab='current')
|
||||
|
||||
with debug.log_time(log.completion, 'Starting {} completion'
|
||||
.format(func.__name__)):
|
||||
info = CompletionInfo(config=config.instance,
|
||||
keyconf=config.key_instance,
|
||||
win_id=self._win_id)
|
||||
win_id=self._win_id,
|
||||
cur_tab=cur_tab)
|
||||
model = func(*args, info=info)
|
||||
with debug.log_time(log.completion, 'Set completion model'):
|
||||
completion.set_model(model)
|
||||
|
|
|
|||
|
|
@ -231,8 +231,7 @@ def _qdatetime_to_completion_format(qdate):
|
|||
|
||||
|
||||
def _back_forward(info, go_forward):
|
||||
tab = objreg.get('tab', scope='tab', window=info.win_id, tab='current')
|
||||
history = tab.history
|
||||
history = info.cur_tab.history
|
||||
current_idx = history.current_idx()
|
||||
model = completionmodel.CompletionModel(column_widths=(5, 36, 50, 9))
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,13 @@ from qutebrowser.commands import command
|
|||
from qutebrowser.api import cmdutils
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_cur_tab(tabbed_browser_stubs, fake_web_tab):
|
||||
# Make sure completions can access the current tab
|
||||
tabbed_browser_stubs[0].widget.tabs = [fake_web_tab()]
|
||||
tabbed_browser_stubs[0].widget.current_index = 0
|
||||
|
||||
|
||||
class FakeCompletionModel(QStandardItemModel):
|
||||
|
||||
"""Stub for a completion model."""
|
||||
|
|
|
|||
|
|
@ -217,7 +217,8 @@ def web_history_populated(web_history):
|
|||
def info(config_stub, key_config_stub):
|
||||
return completer.CompletionInfo(config=config_stub,
|
||||
keyconf=key_config_stub,
|
||||
win_id=0)
|
||||
win_id=0,
|
||||
cur_tab=None)
|
||||
|
||||
|
||||
def test_command_completion(qtmodeltester, cmdutils_stub, configdata_stub,
|
||||
|
|
@ -1233,6 +1234,8 @@ def tab_with_history(fake_web_tab, tabbed_browser_stubs, info, monkeypatch):
|
|||
|
||||
tabbed_browser_stubs[0].widget.tabs = [tab]
|
||||
tabbed_browser_stubs[0].widget.current_index = 0
|
||||
|
||||
info.cur_tab = tab
|
||||
return tab
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue