Workaround chromium causing selection start to also change when end is changed in some circumstances

Fixes #2054934 [Extra text copied when selecting across pages](https://bugs.launchpad.net/calibre/+bug/2054934)
This commit is contained in:
Kovid Goyal 2024-02-29 13:59:17 +05:30
parent 2e4b88059c
commit b10eebf7a0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -228,13 +228,15 @@ def move_end_of_selection(pos, start):
else: else:
# point is inside the selection # point is inside the selection
start = False start = False
new_range = document.createRange()
if start: if start:
if r.startContainer is not p.offsetNode or r.startOffset is not p.offset: new_range.setStart(p.offsetNode, p.offset)
r.setStart(p.offsetNode, p.offset) new_range.setEnd(r.endContainer, r.endOffset)
sel.removeAllRanges() other_boundary_changed = r.endContainer is not new_range.endContainer or r.endOffset is not new_range.endOffset
sel.addRange(r)
else: else:
if r.endContainer is not p.offsetNode or r.endOffset is not p.offset: new_range.setStart(r.startContainer, r.startOffset)
r.setEnd(p.offsetNode, p.offset) new_range.setEnd(p.offsetNode, p.offset)
other_boundary_changed = r.startContainer is not new_range.startContainer or r.startOffset is not new_range.startOffset
if not new_range.collapsed or not other_boundary_changed:
sel.removeAllRanges() sel.removeAllRanges()
sel.addRange(r) sel.addRange(new_range)