Ignore reply header links for keyboard open binds

Don't open the multiple links contained in the "In reply to <user>"
text of fallback replies when using keyboard shortcuts to open
links/media.
This commit is contained in:
miruka 2020-07-21 22:45:26 -04:00
parent 7214180a66
commit 1c218c82ec
2 changed files with 12 additions and 2 deletions

View File

@ -4,7 +4,6 @@
- hflickable: support kinetic scrolling disabler
- compress png in a thread
- ctrl+o: ignore mx-reply links
- verify upload cancellation
- clipboard preview doesn't update when copied image changes until second time
- Avatar tooltip can get displayed in front of presence menu

View File

@ -305,10 +305,21 @@ class Event(ModelItem):
def parse_links(text: str) -> List[str]:
"""Return list of URLs (`<a href=...>` tags) present in the text."""
ignore = []
if "<mx-reply>" in text:
parser = lxml.html.etree.HTMLParser()
tree = lxml.etree.fromstring(text, parser) # nosec
xpath = "//mx-reply/blockquote/a[count(preceding-sibling::*)<=1]"
ignore = [lxml.etree.tostring(el) for el in tree.xpath(xpath)]
if not text.strip():
return []
return [link[2] for link in lxml.html.iterlinks(text)]
return [
url for el, attrib, url, pos in lxml.html.iterlinks(text)
if lxml.etree.tostring(el) not in ignore
]
def serialize_field(self, field: str) -> Any:
if field == "source":