Add support for triggering change handlers when using :open-editor
This commit is contained in:
parent
93eb05598e
commit
e295e8054c
@ -1652,6 +1652,8 @@ class CommandDispatcher:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
elem.set_value(text)
|
elem.set_value(text)
|
||||||
|
# Kick off js handlers to trick them into thinking there was input.
|
||||||
|
elem.dispatch_event("input")
|
||||||
except webelem.OrphanedError:
|
except webelem.OrphanedError:
|
||||||
message.error('Edited element vanished')
|
message.error('Edited element vanished')
|
||||||
ed.backup()
|
ed.backup()
|
||||||
|
@ -139,6 +139,10 @@ class AbstractWebElement(collections.abc.MutableMapping):
|
|||||||
"""Set the element value."""
|
"""Set the element value."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def dispatch_event(self, event):
|
||||||
|
"""Set the element value."""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def insert_text(self, text):
|
def insert_text(self, text):
|
||||||
"""Insert the given text into the element."""
|
"""Insert the given text into the element."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -135,6 +135,9 @@ class WebEngineElement(webelem.AbstractWebElement):
|
|||||||
def set_value(self, value):
|
def set_value(self, value):
|
||||||
self._js_call('set_value', value)
|
self._js_call('set_value', value)
|
||||||
|
|
||||||
|
def dispatch_event(self, event):
|
||||||
|
self._js_call('dispatch_event', event)
|
||||||
|
|
||||||
def caret_position(self):
|
def caret_position(self):
|
||||||
"""Get the text caret position for the current element.
|
"""Get the text caret position for the current element.
|
||||||
|
|
||||||
|
@ -128,6 +128,14 @@ class WebKitElement(webelem.AbstractWebElement):
|
|||||||
value = javascript.string_escape(value)
|
value = javascript.string_escape(value)
|
||||||
self._elem.evaluateJavaScript("this.value='{}'".format(value))
|
self._elem.evaluateJavaScript("this.value='{}'".format(value))
|
||||||
|
|
||||||
|
def dispatch_event(self, event):
|
||||||
|
self._check_vanished()
|
||||||
|
if self._tab.is_deleted():
|
||||||
|
raise webelem.OrphanedError("Tab containing element vanished")
|
||||||
|
log.webelem.debug("Firing event on {!r} via javascript.".format(self))
|
||||||
|
self._elem.evaluateJavaScript("this.dispatchEvent(new Event('{}'))"
|
||||||
|
.format(event))
|
||||||
|
|
||||||
def caret_position(self):
|
def caret_position(self):
|
||||||
"""Get the text caret position for the current element."""
|
"""Get the text caret position for the current element."""
|
||||||
self._check_vanished()
|
self._check_vanished()
|
||||||
|
@ -362,6 +362,11 @@ window._qutebrowser.webelem = (function() {
|
|||||||
document.execCommand("insertText", false, text);
|
document.execCommand("insertText", false, text);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
funcs.dispatch_event = (id, event) => {
|
||||||
|
const elem = elements[id];
|
||||||
|
elem.dispatchEvent(new Event(event));
|
||||||
|
};
|
||||||
|
|
||||||
funcs.set_attribute = (id, name, value) => {
|
funcs.set_attribute = (id, name, value) => {
|
||||||
elements[id].setAttribute(name, value);
|
elements[id].setAttribute(name, value);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user