Only detect save for open-editor and config-edit.
Scope down the new trigger-on-save behavior to only open-editor and config-edit. Other uses of the editor such as edit-url and edit-command will behave as before.
This commit is contained in:
parent
ceab4a4c1f
commit
833df95485
@ -1621,7 +1621,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
caret_position = elem.caret_position()
|
caret_position = elem.caret_position()
|
||||||
|
|
||||||
ed = editor.ExternalEditor(self._tabbed_browser)
|
ed = editor.ExternalEditor(watch=True, parent=self._tabbed_browser)
|
||||||
ed.file_updated.connect(functools.partial(
|
ed.file_updated.connect(functools.partial(
|
||||||
self.on_file_updated, elem))
|
self.on_file_updated, elem))
|
||||||
ed.edit(text, caret_position)
|
ed.edit(text, caret_position)
|
||||||
|
@ -263,7 +263,7 @@ class ConfigCommands:
|
|||||||
except configexc.ConfigFileErrors as e:
|
except configexc.ConfigFileErrors as e:
|
||||||
message.error(str(e))
|
message.error(str(e))
|
||||||
|
|
||||||
ed = editor.ExternalEditor(self._config)
|
ed = editor.ExternalEditor(watch=True, parent=self._config)
|
||||||
if not no_source:
|
if not no_source:
|
||||||
ed.file_updated.connect(on_file_updated)
|
ed.file_updated.connect(on_file_updated)
|
||||||
|
|
||||||
|
@ -41,22 +41,27 @@ class ExternalEditor(QObject):
|
|||||||
closed.
|
closed.
|
||||||
_proc: The GUIProcess of the editor.
|
_proc: The GUIProcess of the editor.
|
||||||
_watcher: A QFileSystemWatcher to watch the edited file for changes.
|
_watcher: A QFileSystemWatcher to watch the edited file for changes.
|
||||||
|
Only set if watch=True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
file_updated = pyqtSignal(str)
|
file_updated = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None, watch=False):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._filename = None
|
self._filename = None
|
||||||
self._proc = None
|
self._proc = None
|
||||||
self._remove_file = None
|
self._remove_file = None
|
||||||
self._watcher = QFileSystemWatcher(parent=self)
|
if watch:
|
||||||
|
self._watcher = QFileSystemWatcher(parent=self)
|
||||||
|
else:
|
||||||
|
self._watcher = None
|
||||||
self._content = None
|
self._content = None
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
"""Clean up temporary files after the editor closed."""
|
"""Clean up temporary files after the editor closed."""
|
||||||
assert self._remove_file is not None
|
assert self._remove_file is not None
|
||||||
self._watcher.removePaths(self._watcher.files())
|
if self._watcher:
|
||||||
|
self._watcher.removePaths(self._watcher.files())
|
||||||
if self._filename is None or not self._remove_file:
|
if self._filename is None or not self._remove_file:
|
||||||
# Could not create initial file.
|
# Could not create initial file.
|
||||||
return
|
return
|
||||||
@ -154,8 +159,9 @@ class ExternalEditor(QObject):
|
|||||||
editor = config.val.editor.command
|
editor = config.val.editor.command
|
||||||
executable = editor[0]
|
executable = editor[0]
|
||||||
|
|
||||||
self._watcher.addPath(self._filename)
|
if self._watcher:
|
||||||
self._watcher.fileChanged.connect(self._on_file_changed)
|
self._watcher.addPath(self._filename)
|
||||||
|
self._watcher.fileChanged.connect(self._on_file_changed)
|
||||||
|
|
||||||
args = [self._sub_placeholder(arg, line, column) for arg in editor[1:]]
|
args = [self._sub_placeholder(arg, line, column) for arg in editor[1:]]
|
||||||
log.procs.debug("Calling \"{}\" with args {}".format(executable, args))
|
log.procs.debug("Calling \"{}\" with args {}".format(executable, args))
|
||||||
|
@ -170,18 +170,18 @@ def test_modify(qtbot, editor, initial_text, edited_text):
|
|||||||
with open(editor._filename, 'r', encoding='utf-8') as f:
|
with open(editor._filename, 'r', encoding='utf-8') as f:
|
||||||
assert f.read() == initial_text
|
assert f.read() == initial_text
|
||||||
|
|
||||||
with qtbot.wait_signal(editor.file_updated) as blocker:
|
with open(editor._filename, 'w', encoding='utf-8') as f:
|
||||||
with open(editor._filename, 'w', encoding='utf-8') as f:
|
f.write(edited_text)
|
||||||
f.write(edited_text)
|
|
||||||
|
|
||||||
with qtbot.assert_not_emitted(editor.file_updated):
|
with qtbot.wait_signal(editor.file_updated) as blocker:
|
||||||
editor._proc.finished.emit(0, QProcess.NormalExit)
|
editor._proc.finished.emit(0, QProcess.NormalExit)
|
||||||
|
|
||||||
assert blocker.args == [edited_text]
|
assert blocker.args == [edited_text]
|
||||||
|
|
||||||
|
|
||||||
def test_modify_multiple(qtbot, editor):
|
def test_modify_watch(qtbot):
|
||||||
"""Test that multiple saves all trigger file_updated."""
|
"""Test that saving triggers file_updated when watch=True."""
|
||||||
|
editor = editormod.ExternalEditor(watch=True)
|
||||||
editor.edit('foo')
|
editor.edit('foo')
|
||||||
|
|
||||||
with qtbot.wait_signal(editor.file_updated) as blocker:
|
with qtbot.wait_signal(editor.file_updated) as blocker:
|
||||||
|
Loading…
Reference in New Issue
Block a user