Controlling the cursor position in a Text Entry object

In order to edit source code easily, I made a small editor with VisualNEO Win. The application has the Text Entry object MyBigCodeText. Its content is stored in the variable [MyBigCodeText].

Editing source code means in my case inserting some code tags. As an example: some source code sections have to be preceded by the separation directive ‘%%vskip 0.5cm’, other sections by a space directive as ‘%%stretchlast 1’ etc. Generally speaking, my application must be able to insert code tags like %%codetag-1, %%codetag-2, %%codetag-3, %%codetag-4 etc. in the source code.

There are two insertion methods to manage this.

Method 1

1. Place the cursor at some position in the source code.
2. Get the cursor position via

GetObjectInfo "MyBigCodeText" "CursorPosition" "[CurPos]"

3. Run the command

StrIns "%%codetag-1" "[MyBigCodeText]" "[CurPos]" "[MyBigCodeText]"

This works fine: %%codetag-1 is inserted at the right place. However, there is a problem. After calling the function StrIns, the cursor is automatically positioned at the end of the source code. Editing source code, that consists of many lines, becomes a tedious job in this way, jumping from the end to other positions in the source code.

The question is if control of the cursor position after insertion is possible. Of course, some plugins can handle that. But without them, VisualNeo Win is able to do that job

Method 2

1. Place the cursor at some position in the source code.
2. Run the commands

SetVar "[Clipboard]" "%%codetag-1"
SendKeys "" "{CtrlDn}V{CtrlUp}"

This works fine: %%codetag-1 is inserted at the right place. The advantage now is that the cursor is positioned after the inserted code tag.

In the case that the Clipboard should be kept for some reason, you could backup and restore the Clipboard:

SetVar "[ClipboardOld]" "[Clipboard]"
SetVar "[Clipboard]" "%%codetag-1"
SendKeys "" "{CtrlDn}V{CtrlUp}"
SetVar "[Clipboard]" "[ClipboardOld]"

The solution is straightforward. However, I’ve to admit that -after many years of using Neobook/VisualNeo Win- I was not aware of the SendKeys option to control the cursor position.

Let’s say: it’s never too late to learn…

Thanks for reading!

Reinier Maliepaard