diff --git a/qutebrowser/app.py b/qutebrowser/app.py index adf54c1b5..acd512ca2 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -52,7 +52,7 @@ from qutebrowser.browser.webkit.network import networkmanager from qutebrowser.keyinput import macros from qutebrowser.mainwindow import mainwindow, prompt from qutebrowser.misc import (readline, ipc, savemanager, sessions, - crashsignal, earlyinit, objects, sql) + crashsignal, earlyinit, objects, sql, cmdhistory) from qutebrowser.misc import utilcmds # pylint: disable=unused-import from qutebrowser.utils import (log, version, message, utils, qtutils, urlutils, objreg, usertypes, standarddir, error) @@ -419,6 +419,9 @@ def _init_modules(args, crash_handler): pre_text='Error initializing SQL') sys.exit(usertypes.Exit.err_init) + log.init.debug("Initializing command history...") + cmdhistory.init() + log.init.debug("Initializing web history...") history.init(qApp) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 15635347f..397a1d100 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -199,18 +199,6 @@ def init(config): state = StateConfig() objreg.register('state-config', state) - # We need to import this here because lineparser needs config. - # FIXME:conf add this to the Command widget or something? - from qutebrowser.misc import lineparser - save_manager = objreg.get('save-manager') - command_history = lineparser.LimitLineParser( - standarddir.data(), 'cmd-history', - limit='completion.cmd_history_max_items', - parent=config) - objreg.register('command-history', command_history) - save_manager.add_saveable('command-history', command_history.save, - command_history.changed) - # Set the QSettings path to something like # ~/.config/qutebrowser/qsettings/qutebrowser/qutebrowser.conf so it # doesn't overwrite our config. diff --git a/qutebrowser/misc/cmdhistory.py b/qutebrowser/misc/cmdhistory.py index baf210a68..a24f6b816 100644 --- a/qutebrowser/misc/cmdhistory.py +++ b/qutebrowser/misc/cmdhistory.py @@ -21,7 +21,8 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject -from qutebrowser.utils import usertypes, log +from qutebrowser.utils import usertypes, log, standarddir, objreg +from qutebrowser.misc import lineparser class HistoryEmptyError(Exception): @@ -129,3 +130,14 @@ class History(QObject): if not self.history or text != self.history[-1]: self.history.append(text) self.changed.emit() + + +def init(): + """Initialize the LimitLineParser storing the history.""" + save_manager = objreg.get('save-manager') + command_history = lineparser.LimitLineParser( + standarddir.data(), 'cmd-history', + limit='completion.cmd_history_max_items') + objreg.register('command-history', command_history) + save_manager.add_saveable('command-history', command_history.save, + command_history.changed) diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 6405cbcbf..adee2c9b3 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -869,7 +869,7 @@ def init_patch(qapp, fake_save_manager, monkeypatch, config_tmpdir, monkeypatch.setattr(config, 'key_instance', None) monkeypatch.setattr(config, '_change_filters', []) yield - for obj in ['config-commands', 'state-config', 'command-history']: + for obj in ['config-commands', 'state-config']: try: objreg.delete(obj) except KeyError: @@ -906,8 +906,6 @@ def test_init(qtbot, init_patch, fake_save_manager, config_tmpdir, objreg.get('config-commands') assert isinstance(config.instance, config.Config) assert isinstance(config.key_instance, config.KeyConfig) - fake_save_manager.add_saveable.assert_any_call( - 'command-history', unittest.mock.ANY, unittest.mock.ANY) fake_save_manager.add_saveable.assert_any_call( 'state-config', unittest.mock.ANY) fake_save_manager.add_saveable.assert_any_call( diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index 0cefe3d42..8fdc9a3ea 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -277,7 +277,6 @@ def init_patch(qapp, fake_save_manager, config_tmpdir, data_tmpdir, config_stub): yield objreg.delete('state-config') - objreg.delete('command-history') def test_init(init_patch, config_tmpdir): diff --git a/tests/unit/misc/test_cmdhistory.py b/tests/unit/misc/test_cmdhistory.py index 8d9a0e014..7858831b6 100644 --- a/tests/unit/misc/test_cmdhistory.py +++ b/tests/unit/misc/test_cmdhistory.py @@ -20,9 +20,12 @@ """Tests for misc.cmdhistory.History.""" +import unittest.mock + import pytest from qutebrowser.misc import cmdhistory +from qutebrowser.utils import objreg HISTORY = ['first', 'second', 'third', 'fourth', 'fifth'] @@ -167,3 +170,15 @@ def test_append_double(hist): hist.append('fifth') # assert that the new 'fifth' is not added assert hist.history[-2:] == ['fourth', 'fifth'] + + +@pytest.fixture +def init_patch(): + yield + objreg.delete('command-history') + + +def test_init(init_patch, fake_save_manager, data_tmpdir, config_stub): + cmdhistory.init() + fake_save_manager.add_saveable.assert_any_call( + 'command-history', unittest.mock.ANY, unittest.mock.ANY)