This commit is contained in:
Kovid Goyal 2024-02-29 13:29:50 +05:30
parent 83a6ab947f
commit 2e4b88059c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -214,26 +214,27 @@ def move_end_of_selection(pos, start):
if not sel.rangeCount: if not sel.rangeCount:
return return
p = caret_position_from_point(pos.x, pos.y) p = caret_position_from_point(pos.x, pos.y)
if p: if not p:
r = sel.getRangeAt(0) return
if start is None: r = sel.getRangeAt(0)
q = document.createRange() if start is None:
q.setStart(p.offsetNode, p.offset) q = document.createRange()
q.setEnd(p.offsetNode, p.offset) q.setStart(p.offsetNode, p.offset)
if r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0: q.setEnd(p.offsetNode, p.offset)
start = True if r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0:
elif r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0: start = True
start = False elif r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0:
else: start = False
# point is inside the selection
start = False
if start:
if r.startContainer is not p.offsetNode or r.startOffset is not p.offset:
r.setStart(p.offsetNode, p.offset)
sel.removeAllRanges()
sel.addRange(r)
else: else:
if r.endContainer is not p.offsetNode or r.endOffset is not p.offset: # point is inside the selection
r.setEnd(p.offsetNode, p.offset) start = False
sel.removeAllRanges() if start:
sel.addRange(r) if r.startContainer is not p.offsetNode or r.startOffset is not p.offset:
r.setStart(p.offsetNode, p.offset)
sel.removeAllRanges()
sel.addRange(r)
else:
if r.endContainer is not p.offsetNode or r.endOffset is not p.offset:
r.setEnd(p.offsetNode, p.offset)
sel.removeAllRanges()
sel.addRange(r)