Resolve crash when editor tab is closed.
If an editor is open on a form in a tab and that tab is closed, rewire the callback to print a warning. Previously, the callback would access a deleted C++ object and cause a crash. Resolves #2758.
This commit is contained in:
parent
03a9cbdfb4
commit
54fffc8264
@ -1621,6 +1621,9 @@ class CommandDispatcher:
|
||||
ed = editor.ExternalEditor(self._tabbed_browser)
|
||||
ed.editing_finished.connect(functools.partial(
|
||||
self.on_editing_finished, elem))
|
||||
tab = self._current_widget()
|
||||
tab.shutting_down.connect(functools.partial(
|
||||
self.on_editor_orphaned, ed))
|
||||
ed.edit(text, caret_position)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
@ -1647,6 +1650,11 @@ class CommandDispatcher:
|
||||
except webelem.Error as e:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
|
||||
def on_editor_orphaned(self, ed):
|
||||
ed.editing_finished.disconnect()
|
||||
ed.editing_finished.connect(
|
||||
lambda: message.warning('Edited element was closed'))
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', maxsplit=0,
|
||||
scope='window')
|
||||
def insert_text(self, text):
|
||||
|
@ -115,6 +115,16 @@ Feature: Opening external editors
|
||||
And I run :click-element id qute-button
|
||||
Then the javascript message "text: foobar" should be logged
|
||||
|
||||
Scenario: Spawning an editor and closing the tab
|
||||
When I set up a fake editor returning "foo" after 1s
|
||||
And I open data/editor.html
|
||||
And I run :click-element id qute-textarea
|
||||
And I wait for "Entering mode KeyMode.insert (reason: clicking input)" in the log
|
||||
And I run :open-editor
|
||||
And I set tabs.last_close to blank
|
||||
And I run :tab-close
|
||||
Then the warning "Edited element was closed" should be shown
|
||||
|
||||
@qtwebengine_todo: Caret mode is not implemented yet
|
||||
Scenario: Spawning an editor in caret mode
|
||||
When I set up a fake editor returning "foobar"
|
||||
|
@ -64,3 +64,21 @@ def set_up_editor(quteproc, server, tmpdir, text):
|
||||
def set_up_editor_empty(quteproc, server, tmpdir):
|
||||
"""Set up editor.command to a small python script inserting empty text."""
|
||||
set_up_editor(quteproc, server, tmpdir, "")
|
||||
|
||||
|
||||
@bdd.when(bdd.parsers.parse(
|
||||
'I set up a fake editor returning "{text}" after {t}s'))
|
||||
def set_up_editor_delay(quteproc, server, tmpdir, text, t):
|
||||
"""Set up editor.command to a small python script inserting a text."""
|
||||
script = tmpdir / 'script.py'
|
||||
script.write(textwrap.dedent("""
|
||||
import sys
|
||||
import time
|
||||
|
||||
time.sleep({t})
|
||||
|
||||
with open(sys.argv[1], 'w', encoding='utf-8') as f:
|
||||
f.write({text!r})
|
||||
""".format(text=text, t=t)))
|
||||
editor = json.dumps([sys.executable, str(script), '{}'])
|
||||
quteproc.set_setting('editor.command', editor)
|
||||
|
Loading…
Reference in New Issue
Block a user