From 2e4b88059c7e2541cab4d0868556a26c8a2796d4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 29 Feb 2024 13:29:50 +0530 Subject: [PATCH] ... --- src/pyj/select.pyj | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/pyj/select.pyj b/src/pyj/select.pyj index f4dac0ec7b..6840e995fe 100644 --- a/src/pyj/select.pyj +++ b/src/pyj/select.pyj @@ -214,26 +214,27 @@ def move_end_of_selection(pos, start): if not sel.rangeCount: return p = caret_position_from_point(pos.x, pos.y) - if p: - r = sel.getRangeAt(0) - if start is None: - q = document.createRange() - q.setStart(p.offsetNode, p.offset) - q.setEnd(p.offsetNode, p.offset) - if r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0: - start = True - elif r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0: - start = False - else: - # 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) + if not p: + return + r = sel.getRangeAt(0) + if start is None: + q = document.createRange() + q.setStart(p.offsetNode, p.offset) + q.setEnd(p.offsetNode, p.offset) + if r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0: + start = True + elif r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0: + start = False 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) + # 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: + 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)