Skip to content

Commit b10eebf

Browse files
committed
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)
1 parent 2e4b880 commit b10eebf

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/pyj/select.pyj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,15 @@ def move_end_of_selection(pos, start):
228228
else:
229229
# point is inside the selection
230230
start = False
231+
new_range = document.createRange()
231232
if start:
232-
if r.startContainer is not p.offsetNode or r.startOffset is not p.offset:
233-
r.setStart(p.offsetNode, p.offset)
234-
sel.removeAllRanges()
235-
sel.addRange(r)
233+
new_range.setStart(p.offsetNode, p.offset)
234+
new_range.setEnd(r.endContainer, r.endOffset)
235+
other_boundary_changed = r.endContainer is not new_range.endContainer or r.endOffset is not new_range.endOffset
236236
else:
237-
if r.endContainer is not p.offsetNode or r.endOffset is not p.offset:
238-
r.setEnd(p.offsetNode, p.offset)
239-
sel.removeAllRanges()
240-
sel.addRange(r)
237+
new_range.setStart(r.startContainer, r.startOffset)
238+
new_range.setEnd(p.offsetNode, p.offset)
239+
other_boundary_changed = r.startContainer is not new_range.startContainer or r.startOffset is not new_range.startOffset
240+
if not new_range.collapsed or not other_boundary_changed:
241+
sel.removeAllRanges()
242+
sel.addRange(new_range)

0 commit comments

Comments
 (0)