File tree 2 files changed +22
-4
lines changed
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 6
6
from typing import (
7
7
Dict ,
8
8
Optional ,
9
+ Self ,
9
10
Union ,
10
11
)
11
12
@@ -842,6 +843,20 @@ def updateSelection(self):
842
843
self .obj .ITextSelectionObject .start = self ._rangeObj .start
843
844
self .obj .ITextSelectionObject .end = self ._rangeObj .end
844
845
846
+ def getTextInfoForCodepointMovement (self ) -> Self :
847
+ # # In PoEdit ITextDocumentTextInfo sometimes cannot access the last character when that character is
848
+ # a newline. In this case collapse(True) takes us not to the end of textInfo, but right before
849
+ # trailing newline character, which causes adverse side effects in moveToCodepointOffset() function.
850
+ # Trimming trailing newline character here to work around.
851
+ info = self .copy ()
852
+ collapsedInfo = info .copy ()
853
+ collapsedInfo .collapse (end = True )
854
+ if collapsedInfo .compareEndPoints (info , "endToEnd" ) < 0 :
855
+ import tones
856
+ tones .beep (500 , 50 )
857
+ info .setEndPoint (collapsedInfo , "endToEnd" )
858
+ return info
859
+
845
860
846
861
class EditBase (Window ):
847
862
""""Base class for Edit and Rich Edit controls, shared by legacy and UIA implementations."""
Original file line number Diff line number Diff line change @@ -655,7 +655,10 @@ def getMathMl(self, field):
655
655
@raise LookupError: If MathML can't be retrieved for this field.
656
656
"""
657
657
raise NotImplementedError
658
-
658
+
659
+ def getTextInfoForCodepointMovement (self ) -> Self :
660
+ return self .copy ()
661
+
659
662
def moveToCodepointOffset (
660
663
self ,
661
664
codepointOffset : int ,
@@ -748,15 +751,15 @@ def moveToCodepointOffset(
748
751
we reduce the count of characters in order to make sure
749
752
the algorithm makes some progress on each iteration.
750
753
"""
751
- text = self .text
754
+ info = self .getTextInfoForCodepointMovement ()
755
+ text = info .text
752
756
if codepointOffset < 0 or codepointOffset > len (text ):
753
757
raise ValueError
754
758
if codepointOffset == 0 or codepointOffset == len (text ):
755
- result = self .copy ()
759
+ result = info .copy ()
756
760
result .collapse (end = codepointOffset > 0 )
757
761
return result
758
762
759
- info = self .copy ()
760
763
# Total codepoint Length represents length in python characters of Current TextInfo we're workoing with.
761
764
# We start with self, and then gradually divide and conquer in order to find desired offset.
762
765
totalCodepointOffset = len (text )
You can’t perform that action at this time.
0 commit comments