Merge remote-tracking branch 'origin/pr/3357'
This commit is contained in:
commit
9dfff43d99
@ -518,7 +518,7 @@ class CommandDispatcher:
|
|||||||
return newtab
|
return newtab
|
||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
@cmdutils.argument('index', completion=miscmodels.buffer)
|
@cmdutils.argument('index', completion=miscmodels.other_buffer)
|
||||||
def tab_take(self, index):
|
def tab_take(self, index):
|
||||||
"""Take a tab from another window.
|
"""Take a tab from another window.
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class CompletionInfo:
|
|||||||
|
|
||||||
config = attr.ib()
|
config = attr.ib()
|
||||||
keyconf = attr.ib()
|
keyconf = attr.ib()
|
||||||
|
win_id = attr.ib()
|
||||||
|
|
||||||
|
|
||||||
class Completer(QObject):
|
class Completer(QObject):
|
||||||
@ -43,6 +44,7 @@ class Completer(QObject):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_cmd: The statusbar Command object this completer belongs to.
|
_cmd: The statusbar Command object this completer belongs to.
|
||||||
|
_win_id: The id of the window that owns this object.
|
||||||
_timer: The timer used to trigger the completion update.
|
_timer: The timer used to trigger the completion update.
|
||||||
_last_cursor_pos: The old cursor position so we avoid double completion
|
_last_cursor_pos: The old cursor position so we avoid double completion
|
||||||
updates.
|
updates.
|
||||||
@ -50,9 +52,10 @@ class Completer(QObject):
|
|||||||
_last_completion_func: The completion function used for the last text.
|
_last_completion_func: The completion function used for the last text.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, cmd, parent=None):
|
def __init__(self, cmd, win_id, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._cmd = cmd
|
self._cmd = cmd
|
||||||
|
self._win_id = win_id
|
||||||
self._timer = QTimer()
|
self._timer = QTimer()
|
||||||
self._timer.setSingleShot(True)
|
self._timer.setSingleShot(True)
|
||||||
self._timer.setInterval(0)
|
self._timer.setInterval(0)
|
||||||
@ -250,7 +253,8 @@ class Completer(QObject):
|
|||||||
with debug.log_time(log.completion,
|
with debug.log_time(log.completion,
|
||||||
'Starting {} completion'.format(func.__name__)):
|
'Starting {} completion'.format(func.__name__)):
|
||||||
info = CompletionInfo(config=config.instance,
|
info = CompletionInfo(config=config.instance,
|
||||||
keyconf=config.key_instance)
|
keyconf=config.key_instance,
|
||||||
|
win_id=self._win_id)
|
||||||
model = func(*args, info=info)
|
model = func(*args, info=info)
|
||||||
with debug.log_time(log.completion, 'Set completion model'):
|
with debug.log_time(log.completion, 'Set completion model'):
|
||||||
completion.set_model(model)
|
completion.set_model(model)
|
||||||
|
@ -94,10 +94,10 @@ def session(*, info=None): # pylint: disable=unused-argument
|
|||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
def buffer(*, info=None): # pylint: disable=unused-argument
|
def _buffer(skip_win_id=None):
|
||||||
"""A model to complete on open tabs across all windows.
|
"""Helper to get the completion model for buffer/other_buffer.
|
||||||
|
Args:
|
||||||
Used for switching the buffer command.
|
skip_win_id: The id of the window to skip, or None to include all.
|
||||||
"""
|
"""
|
||||||
def delete_buffer(data):
|
def delete_buffer(data):
|
||||||
"""Close the selected tab."""
|
"""Close the selected tab."""
|
||||||
@ -109,6 +109,8 @@ def buffer(*, info=None): # pylint: disable=unused-argument
|
|||||||
model = completionmodel.CompletionModel(column_widths=(6, 40, 54))
|
model = completionmodel.CompletionModel(column_widths=(6, 40, 54))
|
||||||
|
|
||||||
for win_id in objreg.window_registry:
|
for win_id in objreg.window_registry:
|
||||||
|
if skip_win_id and win_id == skip_win_id:
|
||||||
|
continue
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
if tabbed_browser.shutting_down:
|
if tabbed_browser.shutting_down:
|
||||||
@ -126,13 +128,31 @@ def buffer(*, info=None): # pylint: disable=unused-argument
|
|||||||
return model
|
return model
|
||||||
|
|
||||||
|
|
||||||
def window(*, info=None): # pylint: disable=unused-argument
|
def buffer(*, info=None): # pylint: disable=unused-argument
|
||||||
|
"""A model to complete on open tabs across all windows.
|
||||||
|
|
||||||
|
Used for switching the buffer command.
|
||||||
|
"""
|
||||||
|
return _buffer()
|
||||||
|
|
||||||
|
|
||||||
|
def other_buffer(*, info):
|
||||||
|
"""A model to complete on open tabs across all windows except the current.
|
||||||
|
|
||||||
|
Used for the tab-take command.
|
||||||
|
"""
|
||||||
|
return _buffer(skip_win_id=info.win_id)
|
||||||
|
|
||||||
|
|
||||||
|
def window(*, info):
|
||||||
"""A model to complete on all open windows."""
|
"""A model to complete on all open windows."""
|
||||||
model = completionmodel.CompletionModel(column_widths=(6, 30, 64))
|
model = completionmodel.CompletionModel(column_widths=(6, 30, 64))
|
||||||
|
|
||||||
windows = []
|
windows = []
|
||||||
|
|
||||||
for win_id in objreg.window_registry:
|
for win_id in objreg.window_registry:
|
||||||
|
if win_id == info.win_id:
|
||||||
|
continue
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
tab_titles = (tab.title() for tab in tabbed_browser.widgets())
|
tab_titles = (tab.title() for tab in tabbed_browser.widgets())
|
||||||
|
@ -320,7 +320,7 @@ class MainWindow(QWidget):
|
|||||||
def _init_completion(self):
|
def _init_completion(self):
|
||||||
self._completion = completionwidget.CompletionView(self.win_id, self)
|
self._completion = completionwidget.CompletionView(self.win_id, self)
|
||||||
cmd = objreg.get('status-command', scope='window', window=self.win_id)
|
cmd = objreg.get('status-command', scope='window', window=self.win_id)
|
||||||
completer_obj = completer.Completer(cmd, self._completion)
|
completer_obj = completer.Completer(cmd, self.win_id, self._completion)
|
||||||
self._completion.selection_changed.connect(
|
self._completion.selection_changed.connect(
|
||||||
completer_obj.on_selection_changed)
|
completer_obj.on_selection_changed)
|
||||||
objreg.register('completion', self._completion, scope='window',
|
objreg.register('completion', self._completion, scope='window',
|
||||||
|
@ -65,7 +65,7 @@ def completer_obj(qtbot, status_command_stub, config_stub, monkeypatch, stubs,
|
|||||||
"""Create the completer used for testing."""
|
"""Create the completer used for testing."""
|
||||||
monkeypatch.setattr(completer, 'QTimer', stubs.InstaTimer)
|
monkeypatch.setattr(completer, 'QTimer', stubs.InstaTimer)
|
||||||
config_stub.val.completion.show = 'auto'
|
config_stub.val.completion.show = 'auto'
|
||||||
return completer.Completer(status_command_stub, completion_widget_stub)
|
return completer.Completer(status_command_stub, 0, completion_widget_stub)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
|
@ -191,7 +191,8 @@ def web_history_populated(web_history):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def info(config_stub, key_config_stub):
|
def info(config_stub, key_config_stub):
|
||||||
return completer.CompletionInfo(config=config_stub,
|
return completer.CompletionInfo(config=config_stub,
|
||||||
keyconf=key_config_stub)
|
keyconf=key_config_stub,
|
||||||
|
win_id=0)
|
||||||
|
|
||||||
|
|
||||||
def test_command_completion(qtmodeltester, cmdutils_stub, configdata_stub,
|
def test_command_completion(qtmodeltester, cmdutils_stub, configdata_stub,
|
||||||
@ -581,7 +582,33 @@ def test_tab_completion_delete(qtmodeltester, fake_web_tab, app_stub,
|
|||||||
QUrl('https://duckduckgo.com')]
|
QUrl('https://duckduckgo.com')]
|
||||||
|
|
||||||
|
|
||||||
def test_window_completion(qtmodeltester, fake_web_tab, tabbed_browser_stubs):
|
def test_other_buffer_completion(qtmodeltester, fake_web_tab, app_stub,
|
||||||
|
win_registry, tabbed_browser_stubs, info):
|
||||||
|
tabbed_browser_stubs[0].tabs = [
|
||||||
|
fake_web_tab(QUrl('https://github.com'), 'GitHub', 0),
|
||||||
|
fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
|
||||||
|
fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2),
|
||||||
|
]
|
||||||
|
tabbed_browser_stubs[1].tabs = [
|
||||||
|
fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
|
||||||
|
]
|
||||||
|
info.win_id = 1
|
||||||
|
model = miscmodels.other_buffer(info=info)
|
||||||
|
model.set_pattern('')
|
||||||
|
qtmodeltester.data_display_may_return_none = True
|
||||||
|
qtmodeltester.check(model)
|
||||||
|
|
||||||
|
_check_completions(model, {
|
||||||
|
'0': [
|
||||||
|
('0/1', 'https://github.com', 'GitHub'),
|
||||||
|
('0/2', 'https://wikipedia.org', 'Wikipedia'),
|
||||||
|
('0/3', 'https://duckduckgo.com', 'DuckDuckGo')
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def test_window_completion(qtmodeltester, fake_web_tab, tabbed_browser_stubs,
|
||||||
|
info):
|
||||||
tabbed_browser_stubs[0].tabs = [
|
tabbed_browser_stubs[0].tabs = [
|
||||||
fake_web_tab(QUrl('https://github.com'), 'GitHub', 0),
|
fake_web_tab(QUrl('https://github.com'), 'GitHub', 0),
|
||||||
fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
|
fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
|
||||||
@ -591,7 +618,8 @@ def test_window_completion(qtmodeltester, fake_web_tab, tabbed_browser_stubs):
|
|||||||
fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0)
|
fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
model = miscmodels.window()
|
info.win_id = 1
|
||||||
|
model = miscmodels.window(info=info)
|
||||||
model.set_pattern('')
|
model.set_pattern('')
|
||||||
qtmodeltester.data_display_may_return_none = True
|
qtmodeltester.data_display_may_return_none = True
|
||||||
qtmodeltester.check(model)
|
qtmodeltester.check(model)
|
||||||
@ -600,7 +628,6 @@ def test_window_completion(qtmodeltester, fake_web_tab, tabbed_browser_stubs):
|
|||||||
'Windows': [
|
'Windows': [
|
||||||
('0', 'window title - qutebrowser',
|
('0', 'window title - qutebrowser',
|
||||||
'GitHub, Wikipedia, DuckDuckGo'),
|
'GitHub, Wikipedia, DuckDuckGo'),
|
||||||
('1', 'window title - qutebrowser', 'ArchWiki')
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user