select a certain number of characters


Stefan Moisei
 

Hello,
is it possible to select a certain number of characters starting from a certain offset without emulating shift+arrows? if it is, I guess it is something related to text infos, but no idea how...
Thanks.


Alberto Buffolino
 

Stefan Moisei via groups.io, il 22/1/2023, ha scritto:
is it possible to select a certain number of characters starting from a certain offset without emulating shift+arrows? if it is, I guess it is something related to text infos, but no idea how...
Alberto:
Hi Stefan,
it could depend from specific TextInfo implementation used, but try this:
1. open a document, i.e. with Notepad;
2. write something, i.e. "This is a test";
3. open NVDA Python console;
4. write these instructions, looking at each result:
***
# get TextInfo object at cursor position
info=focus.makeTextInfo(textInfos.POSITION_CARET)
# expand to include the first character
info.expand(textInfos.UNIT_CHARACTER)
# move the end to include other 3 characters
info.move(textInfos.UNIT_CHARACTER, 3, "end")
# see what info covers
info.text
# and select in editor window
info.updateSelection()
***
Note that POSITION_CARET could be not supported... and you can define info pointing it to a specific (start, end) position, instead of creating, expanding and moving; like this:
***
from textInfos.offsets import Offsets
info=focus.makeTextInfo(Offsets(0, 4))
info.updateSelection()
***
Even if it doesn't work with UIA, at least as far as I know.
Anyway, PlaceMarkers add-on is a good reference for this kind of stuff.
Alberto