dail8859:
> When exactly does it get updated? Is it related to the UI redraw? (this would explain why it works typing the commands in via the keyboard but not when doing it with a macro or direct with code).
It is updated after each command that is seen to be caused directly by the user which deliberately changes the X of the caret. Thus, left arrow, right arrow, and typing set the last X chosen but up and down arrow don’t. This means that a call is manually added to each situation identified as appropriate.
Actions that the application takes that are not directly caused by a user command should not set the last X chosen. For example, when saving, the application may fix up inconsistent line ends, strip trailing spaces, and tidy indentation. Making the next down arrow move 20 columns right because some off-screen whitespace was modified would not be nice.
SCI_REPLACESEL was available early so appeared a good choice for applications to use. Later, SCI_REPLACETARGET was added which is the better choice in most cases.
SCI_REPLACESEL takes an argument so can’t be assigned to a key for easy access. Thus, it was not seen as a command that should change the last X chosen. However, that overlooks its use in macros, as you discovered.
Neil