[Geany-Devel] How to programmatically de-select text

Lex Trotman elextr at xxxxx
Wed Aug 28 11:06:26 UTC 2019

On Wed, 28 Aug 2019 at 20:38, Austin Green <austin.green at orcon.net.nz> wrote:
> Hi Lex,
> > > Trying to programmatically cancel a text selection.  There are functions that will probably do it, e.g. sci_set_selection, but bearing in mind the restriction on changing the API, those functions are not callable from my code.
> > > Surely I'm missing something obvious here?  I do hope so!   :)
> >
> > Scintilla docs say "If the anchor and the current position are the
> > same, there is no selected text." so probably set selection start and
> > end both to current position.
> > https://www.geany.org/manual/reference/sciwrappers_8h.html#a6649bca185bcc34837642cb61b4e7791
> > Cheers
> > Lex
> Yes, that's what I tried first.  It only appears to have no selection -- as soon as I move the caret, it starts selecting again (even without the shift key!)  So appears to have gone into a strange extend-selection-just-by-moving mode.  I can make it return to normal by hitting ESC and then an arrow key, or by again setting the selection start and end points the to the same position.  Weird or what?

No, that makes sense now you say it, after all you have set the
anchor, so when you (or the user) move the cursor, Scintilla considers
between anchor and cursor to be the selection.

Scintilla docs say:

SCI_SETSEL(position anchor, position caret)
This message sets both the anchor and the current position. If caret
is negative, it means the end of the document. If anchor is negative,
it means remove any selection (i.e. set the anchor to the same
position as caret). The caret is scrolled into view after this

And you can send that using scintilla_send_message() which is in the API.


> Cheers, Austin.
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel

More information about the Devel mailing list