Could you be more specific about what you are trying to do? Your statements leve me confused about whether the user is IN the field or not. If there is a selection, then the field is active. If there is a cursor in the field, the cursor's position is normally within the visible window, though it may not automatically scroll to a specific position realtive to the top, but based on making the cursor visible, until the user manually scrolls it.
Usually, providing the scroll bar allows the user to navigate at will. Activating a script while the cursor is active inside a field often changes the focus, depending on how the script is activated.
What is your starting scenario and what you are trying to accomplish from there with a script?
Assume a button to return to a saved position within the text. The user has scrolled down such that the saved position is out of view. The user clicks the button causing the text to scroll back to the saved position.
Another case is a script wants to position the viewed text to a specific position because the script found something of interest to show the user.
I tested a few things , and these script steps worked for me:
- Set Variable [ $select; Value: Get ( ActiveSelectionStart) ]
- Set Variable [ $select; Value: Get ( ActiveSelectionSize) ]
- Go to Field [Select/perform; yourTable:Fieldhere] (Select/Perform checked)
- Set Selection [yourTable:Fieldhere; Start Postion: $select ; End Position:
$select + $select - 1
I don't know quite why the "-1" was necessary to adjust the selection length to get it correct
This left the field scrolled to the selection in my tests, even when the selection had been scrolled out of view.
That worked. What I do not get is using the same Set Selection as a direct command from a button does not work, but in a script with the exact same syntax, it does work. However it is not highlighting the selection, but the cursor is at the correct position. I think it is because the Got To Field command does a selection whereas the command by itself does not default to using the entire text field.
Did you get both parameters of the Set Selection step set using the variables in the calcs I spelled out?
Be sure both Set Variables (including the  for repetition in the second variable with the same name) are set before the Go to Field step is performed.
If you are having trouble getting it to both start and extend the selection properly, try using the script debugger and data viewer to be sure your variables are correctly populated.
As for working with a button, that's problematic because a button is leaving the field, so the field and selection may not be active at the point the script executes following a button click.
The script as I posted it, is working for me every time, reselecting the exact selection which was scrolled out of view. However, I am executing it from the Script menu so as to not disrupt the field or it's selection. How to trigger it successfully may be an issue.
Found the problem. I was using the value from Get(ActiveSelectionSize) directly. Have to add that to the cursor position. So lets say I selected 10 characters at position 25. The cursor position was 25, the size was 10.
I was passing the start position of 25; end position at 10. Changed my calculation for end position to
(start + size) -1
I too encountered the need for the minus 1 to get the correct selection.
It looks like it is working now.
As far as capturing the position from a button, seems to work ok. I have a button (for test purposes) defined to execute a script. the script is simply
Set Field [table::start; Get(ActiveselectionStart)]
Set Field [table::end; ((table::start + Get(ActiveSelectionSize)) - 1)
Glat to hear the button isn't the problem and that it's working now.