C# Class _3PA.Lib.DocumentLines

For every scintilla message that involves a position, the exepect position (expected by scintilla) is the BYTE position, not the CHAR position (as anyone would assume at first!) This class enables you to easily get the correspondance between a BYTE position and a CHAR position, it keeps tracks of inserted/deleted lines and register each line's start position, this information allows us to quickly convert BYTE to CHAR position and vice-versa
Show file Open project: jcaillon/3P

Private Properties

Property Type Description
FillTheHole void
GetCharCount int
GetCharCount int
OnDeletedText void
OnInsertedText void
PrivateCharPositionFromLine int
Reset void
SciGetLength int
SciGetLineCount int
SciLineFromPosition int
SciLineLength int
SciPositionFromLine int
SciPositionRelative int
SetHoleInLine void

Public Methods

Method Description
ByteToCharPosition ( int pos ) : int

Converts a BYTE position to a CHAR position.

CharPositionFromLine ( int index ) : int

Returns the CHAR position where the line begins, this is THE method of this class (since it is the only info we keep on the lines!)

CharToBytePosition ( int pos ) : int

Converts a CHAR position to a BYTE position

DocumentLines ( ) : System

Initializes a new instance

LineCharLength ( int index ) : int

Returns the number of CHAR in a line.

LineFromCharPosition ( int pos ) : int

Returns the line index containing the CHAR position.

OnScnModified ( SCNotification scn, bool isInsertion ) : void

When receiving a modification notification by scintilla

Private Methods

Method Description
FillTheHole ( ) : void

Fixes the hole we created in a line by correcting the start char position or all the following lines (by the amount of _holeLenght) and then rests the _holeLenght

GetCharCount ( IntPtr text, int length, Encoding encoding ) : int

Gets the number of CHAR in a BYTE range

GetCharCount ( int pos, int length ) : int

Gets the number of CHAR int a BYTE range

OnDeletedText ( SCNotification scn ) : void

updates the line info when deleting text

OnInsertedText ( SCNotification scn ) : void

Updates the line info when inserting text

PrivateCharPositionFromLine ( int index ) : int

Returns the CHAR position where the line begins, this is THE method of this class (since it is the only info we keep on the lines!)

Reset ( ) : void

Simulates the insertion of the whole text, use this to reset the lines info (when switching document for instance)

SciGetLength ( ) : int

Returns the document lenght in BYTES

SciGetLineCount ( ) : int

returns the number of lines in the document

SciLineFromPosition ( int pos ) : int

returns the line that contains the BYTE position pos in the document

SciLineLength ( int line ) : int

returns the length (nb of BYTE) of the line, including any line end CHARs

SciPositionFromLine ( int line ) : int

returns the document BYTE position that corresponds with the start of the line

SciPositionRelative ( int position, int nb ) : int

Count a number of whole characters before or after the argument position and return that position The minimum position returned is 0 and the maximum is the last position in the document

SetHoleInLine ( int line, int charLength ) : void

Creates a hole in a given line (charLength is added to the existing _holeLenght)

Method Details

ByteToCharPosition() public method

Converts a BYTE position to a CHAR position.
public ByteToCharPosition ( int pos ) : int
pos int
return int

CharPositionFromLine() public method

Returns the CHAR position where the line begins, this is THE method of this class (since it is the only info we keep on the lines!)
public CharPositionFromLine ( int index ) : int
index int
return int

CharToBytePosition() public method

Converts a CHAR position to a BYTE position
public CharToBytePosition ( int pos ) : int
pos int
return int

DocumentLines() public method

Initializes a new instance
public DocumentLines ( ) : System
return System

LineCharLength() public method

Returns the number of CHAR in a line.
public LineCharLength ( int index ) : int
index int
return int

LineFromCharPosition() public method

Returns the line index containing the CHAR position.
public LineFromCharPosition ( int pos ) : int
pos int
return int

OnScnModified() public method

When receiving a modification notification by scintilla
public OnScnModified ( SCNotification scn, bool isInsertion ) : void
scn _3PA.Interop.SCNotification
isInsertion bool
return void