How to offset line numbers in Scintilla

715 views
Skip to first unread message

Tim Makins

unread,
Apr 4, 2016, 5:56:43 PM4/4/16
to scintilla-interest
I would like to add an offset to the displayed line number in Scintilla. I wish to load just a small section of my text file to the Scintilla box, so would like to be able to set what the first line-number in the box is.

Is this possible, and if so, how do I do it?

Thanks for your help.

Neil Hodgson

unread,
Apr 4, 2016, 6:36:20 PM4/4/16
to scintilla...@googlegroups.com
Tim Makins:

> I would like to add an offset to the displayed line number in Scintilla. I wish to load just a small section of my text file to the Scintilla box, so would like to be able to set what the first line-number in the box is.
>
> Is this possible, and if so, how do I do it?

Offset line numbers are not supported by Scintilla.

You could use a text margin
http://www.scintilla.org/ScintillaDoc.html#SCI_MARGINSETTEXT

Neil

Tim Makins

unread,
Apr 5, 2016, 4:01:33 AM4/5/16
to scintilla-interest, nyama...@me.com
Thanks for your help, Neil. I was eventually advised how to add a line-number offset by Jacob Slusser, using the ideas on this page:
https://github.com/jacobslusser/ScintillaNET/wiki/Displaying-Line-Numbers#custom-line-numbers

I then re-wrote the code to suit Visual Basic:


TextEditor.Margins(0).Type = MarginType.RightText
TextEditor.Margins(0).Width = 35

 

Private Sub UpdateLineNumbers(startingAtLine As Integer)
 Dim offset As Integer = 9500
 For i As Integer = startingAtLine To TextEditor.Lines.Count - 1
 TextEditor.Lines(i).MarginStyle = Style.LineNumber
 TextEditor.Lines(i).MarginText = CStr(offset + i)
 Next
 End Sub

Private Sub TextEditor_Insert(sender As Object, e As ModificationEventArgs) Handles TextEditor.Insert
 ' Only update line numbers if the number of lines changed
 If e.LinesAdded > 0 Then
 UpdateLineNumbers(TextEditor.LineFromPosition(e.Position))
 End If
 End Sub

Private Sub TextEditor_Delete(sender As Object, e As ModificationEventArgs) Handles TextEditor.Delete
 ' Only update line numbers if the number of lines changed
 If e.LinesAdded < 0 Then
 UpdateLineNumbers(TextEditor.LineFromPosition(e.Position))
 End If
 End Sub


Reply all
Reply to author
Forward
0 new messages