Add stricter focus checking for editor
This commit is contained in:
parent
fdc51cb628
commit
958b114d29
@ -714,7 +714,7 @@ class CommandDispatcher:
|
|||||||
elem = webelem.focus_elem(frame)
|
elem = webelem.focus_elem(frame)
|
||||||
if elem.isNull():
|
if elem.isNull():
|
||||||
raise CommandError("No element focused!")
|
raise CommandError("No element focused!")
|
||||||
if not webelem.is_editable(elem):
|
if not webelem.is_editable(elem, strict=True):
|
||||||
raise CommandError("Focused element is not editable!")
|
raise CommandError("Focused element is not editable!")
|
||||||
if webelem.is_content_editable(elem):
|
if webelem.is_content_editable(elem):
|
||||||
text = elem.toPlainText()
|
text = elem.toPlainText()
|
||||||
|
@ -234,13 +234,15 @@ def _is_editable_div(elem):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_editable(elem):
|
def is_editable(elem, strict=False):
|
||||||
"""Check whether we should switch to insert mode for this element.
|
"""Check whether we should switch to insert mode for this element.
|
||||||
|
|
||||||
FIXME: add tests
|
FIXME: add tests
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
elem: The QWebElement to check.
|
elem: The QWebElement to check.
|
||||||
|
strict: Whether to do stricter checking so only fields where we can get
|
||||||
|
the value match, for use with the :editor command.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if we should switch to insert mode, False otherwise.
|
True if we should switch to insert mode, False otherwise.
|
||||||
@ -260,11 +262,11 @@ def is_editable(elem):
|
|||||||
return is_writable(elem)
|
return is_writable(elem)
|
||||||
elif tag in ('embed', 'applet'):
|
elif tag in ('embed', 'applet'):
|
||||||
# Flash/Java/...
|
# Flash/Java/...
|
||||||
return config.get('input', 'insert-mode-on-plugins')
|
return config.get('input', 'insert-mode-on-plugins') and not strict
|
||||||
elif tag == 'object':
|
elif tag == 'object':
|
||||||
return _is_editable_object(elem)
|
return _is_editable_object(elem) and not strict
|
||||||
elif tag == 'div':
|
elif tag == 'div':
|
||||||
return _is_editable_div(elem)
|
return _is_editable_div(elem) and not strict
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user