From 514a4a05fffdc4a1e7f4a060af30ac4a16429024 Mon Sep 17 00:00:00 2001 From: inwit Date: Mon, 7 Feb 2022 22:23:01 +0100 Subject: External editor: add an option to never remove the file upon closing --- qutebrowser/config/configdata.yml | 6 +++++- qutebrowser/misc/editor.py | 2 +- tests/unit/misc/test_editor.py | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index cf5e4665a..30f1e2d11 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1396,12 +1396,16 @@ editor.command: * `{line0}`: Same as `{line}`, but starting from index 0. * `{column0}`: Same as `{column}`, but starting from index 0. - editor.encoding: type: Encoding default: utf-8 desc: Encoding to use for the editor. +editor.remove_file: + default: true + type: Bool + desc: Whether to delete the temporary file upon closing the editor. + ## fileselect fileselect.handler: diff --git a/qutebrowser/misc/editor.py b/qutebrowser/misc/editor.py index d561a7b96..3ef84284d 100644 --- a/qutebrowser/misc/editor.py +++ b/qutebrowser/misc/editor.py @@ -135,7 +135,7 @@ class ExternalEditor(QObject): message.error("Failed to create initial file: {}".format(e)) return - self._remove_file = True + self._remove_file = config.val.editor.remove_file line, column = self._calc_line_and_column(text, caret_position) self._start_editor(line=line, column=column) diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 8e5597a0e..5ed8b834f 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -72,14 +72,17 @@ class TestFileHandling: """Test creation/deletion of tempfile.""" - def test_ok(self, editor): + @pytest.mark.parametrize('remove_file', [True, False]) + def test_ok(self, editor, remove_file, config_stub): """Test file handling when closing with an exit status == 0.""" + config_stub.val.editor.remove_file = remove_file editor.edit("") filename = pathlib.Path(editor._filename) assert filename.exists() assert filename.name.startswith('qutebrowser-editor-') editor._proc._proc.finished.emit(0, QProcess.NormalExit) - assert not filename.exists() + if config_stub.val.editor.remove_file: + assert filename.exists() != config_stub.val.editor.remove_file @pytest.mark.parametrize('touch', [True, False]) def test_with_filename(self, editor, tmp_path, touch): -- cgit v1.2.3-54-g00ecf From 3cbb7194b0cd26819e1452df0f773bc21c4b4737 Mon Sep 17 00:00:00 2001 From: inwit Date: Thu, 10 Feb 2022 18:09:52 +0100 Subject: Apply the requested changes --- qutebrowser/config/configdata.yml | 2 +- tests/unit/misc/test_editor.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 30f1e2d11..fb38f5a96 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1404,7 +1404,7 @@ editor.encoding: editor.remove_file: default: true type: Bool - desc: Whether to delete the temporary file upon closing the editor. + desc: Delete the temporary file upon closing the editor. ## fileselect diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index 5ed8b834f..1dce96de6 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -81,8 +81,7 @@ class TestFileHandling: assert filename.exists() assert filename.name.startswith('qutebrowser-editor-') editor._proc._proc.finished.emit(0, QProcess.NormalExit) - if config_stub.val.editor.remove_file: - assert filename.exists() != config_stub.val.editor.remove_file + assert filename.exists() != config_stub.val.editor.remove_file @pytest.mark.parametrize('touch', [True, False]) def test_with_filename(self, editor, tmp_path, touch): -- cgit v1.2.3-54-g00ecf