To find the startOffset and the endOffset in a treeInterceptor textInfo object with Microsoft Edge with the UIA feature enabled


Noelia Ruiz
 

Hi Abdel and all:

@Abdel: I tested your code and it works perfectly, as expected and I
knew that it happened. Now bookmarks based of Offsets can be saved for
UIA Chromium tree interceptor.
Anyway, since objects can be weakref and they cannot be piclked, we
can not use textInfo.bookmark to place the cursor at specific
positions, and using info.move to indicate the number of characters is
not efficient and can make NVDA to freeze. So, for now I won't update
placeMarkers to work with Edge. Anyway, if someone have ideas for
this, let me know. See this issue related to a bug that causes NVDA to
freeze while using textInfo.move:

https://github.com/nvaccess/nvda/issues/9093

Cheers

2022-07-05 10:41 GMT+02:00, Noelia Ruiz via groups.io
<nrm1977@...>:

Hi dear Abdel:

I'll test this and update placeMarkers accordingly.
Also, as you may know, I (with other members of the community),
maintain a website derived of a blog created by me in 2015, when the
previous NVDA's website created by other person didn't work. This is a
website about NVDA in Spanish, and there I've mentioned people like
Joseph, Alberto Buffolino, Cyrille, Mesar and Fatma Meanna. I'll
mention you too for this great code.
It's located at
https://nvdaes.github.io
Cheers

2022-07-05 8:40 GMT+02:00, Abdel <abdelkrim.bensaid@...>:
Hi dear Noelia and all,

You wrote :

I maintain placeMarkersadd-on, with Chris LM as an author too.
And I cannot use bookmarks in Microsoft Edge. Now I'm trying to use
the procedure explained by you in the treeInterceptor, but the result
is 1 or -1 regardles of the position. If you can help with this, we
may improve this add-on.

To find the startOffset and the endOffset in a treeInterceptor textInfo
object when the UIA feature is enabled in Microsoft Edge, the following
approach should work.

Unlike Paul's example, where we used the compareEndPoints method of
textInfos objects, we'll use the setEndPoint method, which uses the same
parameters, but will extend the endpoint toward the end of the location
where lies the selection.

Here is an implementation that should work in NVDA's Python console:

import NVDAObjects obj = focus.treeInterceptor if isinstance(obj,
NVDAObjects.UIA.chromium.ChromiumUIATreeInterceptor) and not
obj.passThrough: first = obj.makeTextInfo(textInfos.POSITION_FIRST) #
To point to where the browse mode caret is located, as there really
isn't a real caret, we can use the selection attribute as follows: cur
= obj.selection cur.expand(textInfos.UNIT_LINE) # Now, we can use the
setEndPoint method, as follows: first.setEndPoint (cur, "endToStart")
# The startOffset is now calculable, as follows: startOffset =
len(first.text) # We collapse our textInfo object towards the
beginning, to find the endOffset first.collapse() first.setEndPoint
(cur, "endToEnd") endOffset = len(first.text) # Now, if we want to see
what is between startOffset and endOffset, we can do the following:
allText = obj.makeTextInfo(textInfos.POSITION_ALL).text print
(allText[startOffset:endOffset])

It's true that it's a bit heavy, but it finds these *2 positions well
when cur.bookmark.startOffset and cur.bookmark.endOffseg are not
available, in particular, when using treeInterceptor objects in
Microsoft Edge with the UIA feature enabled.

Hope this helps.

Kind regards,
Abdel.










Noelia Ruiz
 

Hi dear Abdel:

I'll test this and update placeMarkers accordingly.
Also, as you may know, I (with other members of the community),
maintain a website derived of a blog created by me in 2015, when the
previous NVDA's website created by other person didn't work. This is a
website about NVDA in Spanish, and there I've mentioned people like
Joseph, Alberto Buffolino, Cyrille, Mesar and Fatma Meanna. I'll
mention you too for this great code.
It's located at
https://nvdaes.github.io
Cheers

2022-07-05 8:40 GMT+02:00, Abdel <abdelkrim.bensaid@...>:

Hi dear Noelia and all,

You wrote :

I maintain placeMarkersadd-on, with Chris LM as an author too.
And I cannot use bookmarks in Microsoft Edge. Now I'm trying to use
the procedure explained by you in the treeInterceptor, but the result
is 1 or -1 regardles of the position. If you can help with this, we
may improve this add-on.

To find the startOffset and the endOffset in a treeInterceptor textInfo
object when the UIA feature is enabled in Microsoft Edge, the following
approach should work.

Unlike Paul's example, where we used the compareEndPoints method of
textInfos objects, we'll use the setEndPoint method, which uses the same
parameters, but will extend the endpoint toward the end of the location
where lies the selection.

Here is an implementation that should work in NVDA's Python console:

import NVDAObjects obj = focus.treeInterceptor if isinstance(obj,
NVDAObjects.UIA.chromium.ChromiumUIATreeInterceptor) and not
obj.passThrough: first = obj.makeTextInfo(textInfos.POSITION_FIRST) #
To point to where the browse mode caret is located, as there really
isn't a real caret, we can use the selection attribute as follows: cur
= obj.selection cur.expand(textInfos.UNIT_LINE) # Now, we can use the
setEndPoint method, as follows: first.setEndPoint (cur, "endToStart")
# The startOffset is now calculable, as follows: startOffset =
len(first.text) # We collapse our textInfo object towards the
beginning, to find the endOffset first.collapse() first.setEndPoint
(cur, "endToEnd") endOffset = len(first.text) # Now, if we want to see
what is between startOffset and endOffset, we can do the following:
allText = obj.makeTextInfo(textInfos.POSITION_ALL).text print
(allText[startOffset:endOffset])

It's true that it's a bit heavy, but it finds these *2 positions well
when cur.bookmark.startOffset and cur.bookmark.endOffseg are not
available, in particular, when using treeInterceptor objects in
Microsoft Edge with the UIA feature enabled.

Hope this helps.

Kind regards,
Abdel.






Abdel
 

Hi dear Noelia and all,

You wrote :

I maintain placeMarkersadd-on, with Chris LM as an author too.
And I cannot use bookmarks in Microsoft Edge. Now I'm trying to use
the procedure explained by you in the treeInterceptor, but the result
is 1 or -1 regardles of the position. If you can help with this, we
may improve this add-on.


To find the startOffset and the endOffset in a treeInterceptor textInfo object when the UIA feature is enabled in Microsoft Edge, the following approach should work.

Unlike Paul's example, where we used the compareEndPoints method of textInfos objects, we'll use the setEndPoint method, which uses the same parameters, but will extend the endpoint toward the end of the location where lies the selection.

Here is an implementation that should work in NVDA's Python console:

import NVDAObjects obj = focus.treeInterceptor if isinstance(obj, NVDAObjects.UIA.chromium.ChromiumUIATreeInterceptor) and not obj.passThrough: first = obj.makeTextInfo(textInfos.POSITION_FIRST) # To point to where the browse mode caret is located, as there really isn't a real caret, we can use the selection attribute as follows: cur = obj.selection cur.expand(textInfos.UNIT_LINE) # Now, we can use the setEndPoint method, as follows: first.setEndPoint (cur, "endToStart") # The startOffset is now calculable, as follows: startOffset = len(first.text) # We collapse our textInfo object towards the beginning, to find the endOffset first.collapse() first.setEndPoint (cur, "endToEnd") endOffset = len(first.text) # Now, if we want to see what is between startOffset and endOffset, we can do the following: allText = obj.makeTextInfo(textInfos.POSITION_ALL).text print (allText[startOffset:endOffset])


It's true that it's a bit heavy, but it finds these *2 positions well when cur.bookmark.startOffset and cur.bookmark.endOffseg are not available, in particular, when using treeInterceptor objects in Microsoft Edge with the UIA feature enabled.

Hope this helps.

Kind regards,
Abdel.