|
65 | 65 | import ui
|
66 | 66 | import winVersion
|
67 | 67 | import NVDAObjects
|
| 68 | +from documentNavigation import sentenceNavigation |
68 | 69 |
|
69 | 70 |
|
70 | 71 | paragraphIndentIDs = {
|
@@ -899,26 +900,66 @@ def _get_boundingRects(self):
|
899 | 900 | return self._getBoundingRectsFromUIARange(self._rangeObj)
|
900 | 901 |
|
901 | 902 | def expand(self, unit: str) -> None:
|
902 |
| - UIAUnit=UIAHandler.NVDAUnitsToUIAUnits[unit] |
903 |
| - self._rangeObj.ExpandToEnclosingUnit(UIAUnit) |
| 903 | + if unit == textInfos.UNIT_SENTENCE: |
| 904 | + context = sentenceNavigation.SentenceContext(self) |
| 905 | + sentence = context.moveSentence(0) |
| 906 | + self._rangeObj = sentence._rangeObj |
| 907 | + else: |
| 908 | + UIAUnit = UIAHandler.NVDAUnitsToUIAUnits[unit] |
| 909 | + self._rangeObj.ExpandToEnclosingUnit(UIAUnit) |
904 | 910 |
|
905 | 911 | def move(
|
906 | 912 | self,
|
907 | 913 | unit: str,
|
908 | 914 | direction: int,
|
909 | 915 | endPoint: Optional[str] = None,
|
910 | 916 | ):
|
911 |
| - UIAUnit=UIAHandler.NVDAUnitsToUIAUnits[unit] |
912 |
| - if endPoint=="start": |
913 |
| - res=self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_Start,UIAUnit,direction) |
914 |
| - elif endPoint=="end": |
915 |
| - res=self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_End,UIAUnit,direction) |
| 917 | + if unit == textInfos.UNIT_SENTENCE: |
| 918 | + if direction == 0: |
| 919 | + return 0 |
| 920 | + endPointInfo = self.copy() |
| 921 | + if endPoint == "start": |
| 922 | + endPointInfo.collapse() |
| 923 | + elif endPoint == "end": |
| 924 | + endPointInfo.collapse(end=True) |
| 925 | + if direction > 0: |
| 926 | + iteration = range(direction) |
| 927 | + direction = 1 |
| 928 | + else: |
| 929 | + iteration = range(-direction) |
| 930 | + direction = -1 |
| 931 | + result = 0 |
| 932 | + for i in iteration: |
| 933 | + context = sentenceNavigation.SentenceContext(endPointInfo) |
| 934 | + sentence = context.moveSentence(direction) |
| 935 | + if sentence is not None: |
| 936 | + result += direction |
| 937 | + endPointInfo = sentence |
| 938 | + else: |
| 939 | + break |
| 940 | + if result == 0: |
| 941 | + return 0 |
| 942 | + endPointInfo.collapse() |
| 943 | + if endPoint == "start": |
| 944 | + self.setEndPoint(endPointInfo, "startToStart") |
| 945 | + elif endPoint == "end": |
| 946 | + self.setEndPoint(endPointInfo, "endToEnd") |
| 947 | + else: |
| 948 | + self._rangeObj = endPointInfo._rangeObj |
| 949 | + return result |
916 | 950 | else:
|
917 |
| - res=self._rangeObj.Move(UIAUnit,direction) |
918 |
| - #Some Implementations of Move and moveEndpointByUnit return a positive number even if the direction is negative |
919 |
| - if direction<0 and res>0: |
920 |
| - res=0-res |
921 |
| - return res |
| 951 | + UIAUnit = UIAHandler.NVDAUnitsToUIAUnits[unit] |
| 952 | + if endPoint == "start": |
| 953 | + res = self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_Start, UIAUnit, direction) |
| 954 | + elif endPoint == "end": |
| 955 | + res = self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_End, UIAUnit, direction) |
| 956 | + else: |
| 957 | + res = self._rangeObj.Move(UIAUnit, direction) |
| 958 | + # Some Implementations of Move and moveEndpointByUnit return a positive number even if the direction is |
| 959 | + # negative |
| 960 | + if direction < 0 and res > 0: |
| 961 | + res = 0 - res |
| 962 | + return res |
922 | 963 |
|
923 | 964 | def copy(self):
|
924 | 965 | return self.__class__(self.obj,None,_rangeObj=self._rangeObj)
|
|
0 commit comments