Re: Restoring the vertical position
Jean Lalonde <[email protected]> Mon, 17 Mar 2025 14:02:38 -0700 (PDT)
| Newsgroups | gmane.comp.lib.scintilla.devel |
|---|---|
| Message-ID | <[email protected]> |
Thank you for your help Mitchell.
Here is a sample of my AutoHotkey code. The function SetEditorText() gets
the current vertical position, replace the editor with the new text and
tries to restore the vertical position.
;---------------------------------------------------------
SetEditorText(strNewText, intStart, intEnd)
;---------------------------------------------------------
{
; o_Sci is an AutoHotkey class wrapper for Scintilla commands messages
intFirstVisibleLine := o_Sci.GETFIRSTVISIBLELINE()
intDocLineFromVisible := o_Sci.DOCLINEFROMVISIBLE(intFirstVisibleLine)
o_Sci.SETTEXT("", strNewText, 1)
o_Sci.SETSEL(intStart, intEnd)
o_Sci.VISIBLEFROMDOCLINE(intDocLineFromVisible)
}
;---------------------------------------------------------
The current result with this code is that regardless of the original
position of the selected text in the visible portion (middle or bottom of
the window), the selection vertical position is always restored at the top
of the window (first visible line). See the example attached where the
selected text has been converted to uppercase.
Thanks,
Jean
Le lundi 17 mars 2025 à 12 h 14 min 50 s UTC-4, Mitchell a écrit :
> Hi,
>
> > On Mar 17, 2025, at 12:06 PM, Jean Lalonde <[email protected]> wrote:
> >
> > I forgot to mention that I also tried
> >
> > intFisrtVisibleLine := SCI_GETFIRSTVISIBLELINE()
> > ...
> > SCI_ SETFIRSTVISIBLELINE(intFisrtVisibleLine)
> >
> > But this does not restore the expected position. FYI, SCI_SETWRAPMODE()
> is enabled.
>
> Then I think you’ll have to save with
> SCI_DOCLINEFROMVISIBLE(SCI_GETFIRSTVISIBLELINE) and restore with
> SCI_VISIBLEFROMDOCLINE.
>
> You might need to trigger a Scintilla repaint in-between your SCI_SETTEXT
> and SCI_VISIBLEFROMDOCLINE. You could wait for an SCN_UPDATEUI
> notification, but that would require some extra work.
>
> Cheers,
> Mitchell
>
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/6e8ea8b1-b216-400d-940f-a4bac2c7884fn%40googlegroups.com.
1-selection-before.png
(image/png, 13.8 KB) - not displayed
2-selection-after.png
(image/png, 14 KB) - not displayed