Setting selection and ensuring it is visible

71 vistas
Ir al primer mensaje no leído

dail8859

no leída,
11 sept 2017, 9:11:20 a.m.11/9/17
para scintilla-interest

I'm implementing a find feature and once a match is found I set the selection to that match then make sure it is visible. From this I need (a) a notification the selection has changed, and (b) honor the editor's visible policy (which I am using the default). However I've tried a couple different approaches and neither work exactly what I'm looking for.

My first attempt is to do:
  1. Locate a match (no big deal)
  2. Use SCI_SETSELECTION(targetStart, targetEnd)
  3. Use SCI_ENSUREVISIBLEENFORCEPOLICY(lineOfStart)
  4. This works as expected (if the match is not currently visible, it scrolls to put the match vertically centered; but if it is still visible, it doesn't scroll). However, using this method does not generate a SCN_UPDATEUI notification that has the SC_UPDATE_SELECTION flag set (only that it has been scrolled).


My next attempt was to do much the same:

  1. Locate the match
  2. Use SCI_SETSEL(targetStart, targetEnd)
  3. This does generate the correct SCN_UPDATEUI notification, however, if the selection is off of the screen it only scrolls the minimum amount to put the selection at the very bottom thus ignoring the visible policy.



So is one of the above situations not working correctly? If they are both working correctly is there another suggested method to achieve what I am needing?


Thanks,

Justin

Neil Hodgson

no leída,
11 sept 2017, 6:52:32 p.m.11/9/17
para scintilla...@googlegroups.com
dail8859:

> From this I need (a) a notification the selection has changed, and (b) honor the editor's visible policy (which I am using the default).

> • Use SCI_SETSELECTION(targetStart, targetEnd)
> • …However, using this method does not generate a SCN_UPDATEUI notification that has the SC_UPDATE_SELECTION flag set (only that it has been scrolled).

Your application changed the selection so Scintilla does not need to tell it. The point of the update selection notification is to tell the application about changes it would not otherwise know about.

Neil

dail8859

no leída,
12 sept 2017, 9:15:51 a.m.12/9/17
para scintilla-interest
Yes it does, however when writing modular code it is much easier to just handle notifications from Scintilla itself. Also, several of the other ways to set the selection does generate the notification. I did some more digging and found 4 different ways to set the selection. I had expected they all worked the same (other than SCI_SETSEL scrolling the caret into view), but did not realize there would be some of the small inconsistencies. My results:
  1. SCI_SETSEL
    • Does generates SCN_UPDATEUI with SC_UPDATE_SELECTION set
    • Scrolls selection into view (as the documentation states), but does not honor visible policy
  2. SCI_SETSELECTION
    • Does not generate SCN_UPDATEUI with SC_UPDATE_SELECTION set
  3. SCI_SETSELECTIONSTART and SCI_SETSELECTIONEND
    • Does generate SCN_UPDATEUI with SC_UPDATE_SELECTION set
  4. SCI_SETCURRENTPOS and SCI_SETANCHOR
    • Does generate SCN_UPDATEUI with SC_UPDATE_SELECTION set

Ultimately, I did find that option 3 and 4 worked for me since I can just call SCI_ENSUREVISIBLEENFORCEPOLICY afterwards and still receive the notification for the selection being updated. I had just found the first 2 options originally and neither worked exactly as I assumed.


Thanks,
Justin
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos