Fix editor/paste-primary
This commit is contained in:
parent
e051de4843
commit
5eca6e11a5
@ -1433,10 +1433,7 @@ class CommandDispatcher:
|
||||
raise cmdexc.CommandError("No element focused!")
|
||||
if not elem.is_editable(strict=True):
|
||||
raise cmdexc.CommandError("Focused element is not editable!")
|
||||
if elem.is_content_editable():
|
||||
text = str(elem)
|
||||
else:
|
||||
text = elem.evaluateJavaScript('this.value')
|
||||
text = elem.text(use_js=True)
|
||||
ed = editor.ExternalEditor(self._win_id, self._tabbed_browser)
|
||||
ed.editing_finished.connect(functools.partial(
|
||||
self.on_editing_finished, elem))
|
||||
@ -1478,7 +1475,7 @@ class CommandDispatcher:
|
||||
|
||||
log.misc.debug("Pasting primary selection into element {}".format(
|
||||
elem.debug_text()))
|
||||
elem.evaluateJavaScript("""
|
||||
elem.run_js_async("""
|
||||
var sel = '{}';
|
||||
var event = document.createEvent('TextEvent');
|
||||
event.initTextEvent('textInput', true, true, null, sel);
|
||||
|
@ -168,6 +168,18 @@ class WebElementWrapper(collections.abc.MutableMapping):
|
||||
self._check_vanished()
|
||||
return self._elem.styleProperty(name, strategy)
|
||||
|
||||
def text(self, *, use_js=False):
|
||||
"""Get the plain text content for this element.
|
||||
|
||||
Args:
|
||||
use_js: Whether to use javascript if the element isn't content-editable.
|
||||
"""
|
||||
self._check_vanished()
|
||||
if self._elem.is_content_editable() or not use_js:
|
||||
return self._elem.toPlainText()
|
||||
else:
|
||||
return self._elem.evaluateJavaScript('this.value')
|
||||
|
||||
def set_text(self, text, *, use_js=False):
|
||||
"""Set the given plain text.
|
||||
|
||||
@ -332,6 +344,13 @@ class WebElementWrapper(collections.abc.MutableMapping):
|
||||
self._check_vanished()
|
||||
return self._elem.tagName()
|
||||
|
||||
def run_js_async(self, code, callback=None):
|
||||
"""Run the given JS snippet async on the element."""
|
||||
self._check_vanished()
|
||||
result = self._elem.evaluateJavaScript(code)
|
||||
if callback is not None:
|
||||
callback(result)
|
||||
|
||||
def rect_on_view(self, *, elem_geometry=None, adjust_zoom=True, no_js=False):
|
||||
"""Get the geometry of the element relative to the webview.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user