Scrolling to line in StyledTextCtrl

Hi. Iv been writing a small Python editor using the STC and its working very
well indeed, however, I have now added a list of the class and definition
names which is produced on the fly. The idea is to click on a name in the
list and scroll the STC to the correct line.

This works extremely well except when the the document has folded items (and
indeed when the item in question is inside a folded item). I have the
correct line number stored with the item name, but this is of course based
on the line numbers when the whole document is unfolded.

Here is some pseudo code that shows what I have tried to do in the list
click event (after Iv matched the correct item and have the line number),
but alas, with little success.

if self.STC.GetLineVisible(lineno) == 0:
    tFoldParent = self.STC.GetFoldParent(lineno)
    self.STC.SetFoldExpanded(tFoldParent,1)
    self.STC.ToggleFold(tFoldParent)
                    
self.STC.GotoLine(lineno)
self.STC.ScrollToLine(lineno)

Can anyone give me any idea about how to progress from here - It seems that
even when other items are folded, the number of lines is not correctly
matched (folded lines are not taken into account when positioning), so even
if the item I'm trying to reach is unfolded, if other items above it in the
document are folded, the lines count is incorrect.

cheers

Max

···

--
View this message in context: http://www.nabble.com/Scrolling-to-line-in-StyledTextCtrl-tp22881931p22881931.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Thanks Robin, thats what I thought as well!

Iv tried a number of approaches to this now, ranging from stored line
numbers to using a search and then LineFromPosition, but so far the only
method I have found that actually allows me to scroll to the correct place
is to toggle all of the folds open before trying to scroll to the selected
item (Iv yet to resort to trying to re-fold all of the other items after
reaching the correct line - overkill methinks!).

Its a valid workaround for now but Ill keep plugging away at it.

Thanks again

Max

Robin Dunn wrote:

···

MaxVK wrote:

Can anyone give me any idea about how to progress from here - It seems
that
even when other items are folded, the number of lines is not correctly
matched (folded lines are not taken into account when positioning), so
even
if the item I'm trying to reach is unfolded, if other items above it in
the
document are folded, the lines count is incorrect.

I haven't done much at all with line folding myself, but I think that
the EnsureVisible method should both scroll the line into view and
unfold any folded groups that may be hiding it.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
View this message in context: http://www.nabble.com/Scrolling-to-line-in-StyledTextCtrl-tp22881931p22924252.html
Sent from the wxPython-users mailing list archive at Nabble.com.