Skip to content

XUICELineManager

Description

Every XUICodeEditor has a Line Manager that is represented by an instance of this class.

It is the responsibility of the line manager to handle the manipulation of lines of code within an editor.

Properties

Name Type Read-Only
Formatter XUICEFormatter
LastChanged Double
LineCount Integer
Lines() XUICELine
LongestLine XUICELine
mCaretPosCache Integer
mDidDeleteContiguousLines Boolean
mLastChanged Double
mLongestLine XUICELine
mNearestDelimiters XUICEDelimiter
mOwnerRef WeakRef
NearestDelimiters XUICEDelimiter
Owner XUICodeEditor

Methods

Name Parameters Returns
AdjustLineOffsets firstLineNumber As Integer, value As Integer, lineNumberDelta As Integer
CodeLineCount Integer
Constructor owner As XUICodeEditor
Contents String
ContentsFrom startLineNumber As Integer, endLineNum As Integer String
DeleteAllLines allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean
DeleteLineAt lineNumber As Integer, adjustBy As Integer
DeleteSelection allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean, undoMessage As String
InsertCharacter caretPos As Integer, char As String, allowUndo As Boolean, raiseContentsDidChange As Boolean
InsertLineAt lineNumber As Integer, contents As String, adjustBy As Integer XUICELine
InsertText caretPos As Integer, s As String, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean
IsEmpty Boolean
LastLine XUICELine
LineAt lineNumber As Integer XUICELine
LineForCaretPos caretPos As Integer XUICELine
LineNumberForCaretPos pos As Integer Integer
NextWordEnd caretPos As Integer Integer
PreviousWordStart caretPos As Integer Integer
ReplaceSelection s As String, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean
TokeniseAllLines
UpdateLongestLine
UpdateNearestDelimiters caretPos As Integer

Property Descriptions

Formatter As XUICEFormatter

The formatter used to format text in the editor.


LastChanged As Double

The time stamp (in microseconds) that the last change took place.


LineCount As Integer

The number of lines in the editor.


Lines() As XUICELine

The lines of text managed by the line manager.


LongestLine As XUICELine

The current longest line.


mCaretPosCache As Integer

Cached value of the caretPos argument passed to UpdateNearestDelimiters.


mDidDeleteContiguousLines As Boolean

True if the line manager just deleted contiguous lines.


mLastChanged As Double

Backing field for the LastChanged computed property.


mLongestLine As XUICELine

Backing field for the LongestLine property.


mNearestDelimiters As XUICEDelimiter

Stores the last computed matching delimiters. Used internally within UpdateNearestDelimiters(). May be Nil.


mOwnerRef As WeakRef

A weak reference to the XUICodeEditor that owns this line manager.


NearestDelimiters As XUICEDelimiter

Stores the last computed matching delimiters to the caret. May be Nil.


Owner As XUICodeEditor

The XUICodeEditor that owns this line manager.


Method Descriptions

AdjustLineOffsets(firstLineNumber As Integer, value As Integer, lineNumberDelta As Integer)

Adjusts the start and end positions of every line beginning at firstLineNumber by value.

lineNumberDelta is the number to adjust the line numbers by.


CodeLineCount() As Integer

Returns the number of lines of code (excludes empty lines and comment-only lines).


Constructor(owner As XUICodeEditor)

owner is the XUICodeEditor that owns this line manager.


Contents() As String

Returns the contents of every line.


ContentsFrom(startLineNumber As Integer, endLineNum As Integer) As String

Returns the contents of every line in the passed range (inclusive).

  • startLineNum is the 1-based number of the line to start at.
  • endLineNum is the 1-based number of the line to end at.

If endLineNum = -1 then we get all contents from startLineNum to the last line.


DeleteAllLines(allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean)

Deletes all lines and updates the caret position.

If allowUndo is True then this action will be undoable. If shouldInvalidate is False then the canvas will not be immediately invalidated.


DeleteLineAt(lineNumber As Integer, adjustBy As Integer)

Deletes the line at lineNumber and adjusts subsequent line offsets by adjustBy. Does not move the caret.

Raises an InvalidArgumentException if lineNumber is out of range.


DeleteSelection(allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean, undoMessage As String)

Deletes the current text selection and updates the caret position.

  • If allowUndo is True then this action should be pushed to the undo manager.
  • If shouldInvalidate is True then the canvas will be invalidated after the deletion.
  • If raiseContentsDidChange is True then we will raise the editor's ContentsDidChange event.
  • undoMessage is an optional override message for undoable actions.

There are 6 scenarios:

  1. A single whole line is selected.
  2. Only text on a single line is selected.
  3. Contiguous complete lines are selected.
  4. All of the start line but only part of the end line is selected.
  5. Part of the start line and all of the end line is selected.
  6. Part of the start line and part of the end line are selected.

InsertCharacter(caretPos As Integer, char As String, allowUndo As Boolean, raiseContentsDidChange As Boolean)

Inserts char at caretPos and updates the the owning editor's caret position.

If allowUndo is True then this action will be undoable. If raiseContentsDidChange is True then we raise the editor's ContentsDidChange event.

For performance, we make a number of assumptions:

  • Assumes that char is a single character.
  • Assumes 0 <= caretPos > (LastLine.EndPosition + 1).
  • Assumes char is not a newline character.

InsertLineAt(lineNumber As Integer, contents As String, adjustBy As Integer) As XUICELine

Creates and inserts a new line at lineNumber containing contents, returning the new line.

adjustBy is an (additional) value to adjust all subsequent line offsets by. Raises an InvalidArgumentException if lineNumber is out of range.


InsertText(caretPos As Integer, s As String, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean)

Inserts s into the editor at caretPos. s may contain newlines. Updates the caret position.

If allowUndo is True then push this action to the undo manager. If shouldInvalidate is False then the canvas will not immediately invalidate. If raiseContentsDidChange is True then we'll raise the editor's ContentsDidChange event.

Assumes that s is not empty. s may contain newlines. If present they must have been standardised to &u0A. Clears any selection present prior to the insertion.

There are three scenarios:

  1. A solitary newline character is being inserted.
  2. The text to insert does not contain newlines.
  3. The text to insert contains at least one newline.

IsEmpty() As Boolean

True if there is no text in the canvas.

There may be no text but there will always be at least on line.


LastLine() As XUICELine

The last (i.e. highest numbered) line.


LineAt(lineNumber As Integer) As XUICELine

Returns the line at lineNumber or Nil.


LineForCaretPos(caretPos As Integer) As XUICELine

Returns the line that would contain the 0-based caretPos.

Raises an InvalidArgumentException if caretPos is out of range.


LineNumberForCaretPos(pos As Integer) As Integer

Returns the line number for the specified caret position.

Raises an InvalidArgumentException if pos is out of range.


NextWordEnd(caretPos As Integer) As Integer

Returns the caret position of the end of the word after the caretPos.

Raises an InvalidArgumentException if caretPos is out of range for this line.


PreviousWordStart(caretPos As Integer) As Integer

Returns the caret pos of the start of the word before the caretPos.

Raises an InvalidArgumentException if caretPos is out of range for this line.


ReplaceSelection(s As String, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean)

Replaces the text selection in the owning canvas with s and updates the caret position.

If allowUndo is True then this replacement will be undoable. If shouldInvalidate is False then the canvas will not be immediately invalidated. If raiseContentsDidChange is True then we raise the editor's ContentsDidChange event.

Assumes that if s contains newlines that they have been standardised to UNIX (&u0A).


TokeniseAllLines()

Re-tokenises every line.


UpdateLongestLine()

Updates the cache of the longest line.


UpdateNearestDelimiters(caretPos As Integer)

Updates the nearest delimiters to the specified caretPos.