Skip to content

XUICodeEditor

Inherits NSScrollViewCanvas

Implements XUINotificationListener

Description

A powerful and highly customisable code editor control based on the open source TextInputCanvas control. It supports themes, multiple languages, autocompletion and features a robust undo engine.

Properties

Name Type Read-Only
AllowAutocomplete Boolean
AllowAutoCompleteInComments Boolean
AllowInertialScrolling Boolean
AutocloseBrackets Boolean
AutocompleteCombo XUICodeEditor.AutocompleteCombos
AutocompleteData XUICEAutocompleteData
AutocompletePopupFontName String
AutocompletePopupFontSize Integer
BackgroundColor Color
BlinkCaret Boolean
BorderColor ColorGroup
CaretColour Color
CaretColumn Integer
CaretData XUICECaretData
CaretLineNumber Integer
CaretPosition Integer
CaretType CaretTypes
CaretXCoordinate Integer
ClosingBracketForOpener Dictionary
Contents String
ContentType XUICodeEditor.ContentTypes
CurrentLine XUICELine
CurrentLineHighlightColor Color
CurrentLineNumberColor Color
CurrentSelection XUITextSelection
CurrentUndoID Integer
DebuggingLine Integer
DebugLineColour Color
DisplayLineNumbers Boolean
DrawBlockLines Boolean
FirstVisibleLine Integer
FontName String
FontSize Integer
Formatter XUICEFormatter
HasBottomBorder Boolean
HasFocus Boolean
HasLeftBorder Boolean
HasRightBorder Boolean
HasTopBorder Boolean
HighlightCurrentLine Boolean
HighlightDelimitersAroundCaret Boolean
JustTokenised Boolean
LastFullyVisibleLineNumber Integer
LastParseMicroseconds Double
LineManager XUICELineManager
LineNumberColor Color
LineNumberFontSize Integer
LongestLineChanged Boolean
mAutocompletePopup XUICodeEditorAutocompletePopup
mBackBuffer Picture
mBorderColor ColorGroup
mCachedRequiredBufferWidth Double
mCaretBlinker Timer
mCaretPosition Integer
mCaretType CaretTypes
mCaretVisible Boolean
mCurrentLine XUICELine
mCurrentSelection XUITextSelection
mCurrentUndoID Integer
mDebuggingLine Integer
mDelimiterTimer Timer
mDisplayLineNumbers Boolean
mDragging Boolean
mDraggingHorizontalScrollbarThumb Boolean
mDraggingVerticalScrollbarThumb Boolean
mDrawBlockLines Boolean
mFirstVisibleLine Integer
mFontName String
mFontSize Integer
mFormatter XUICEFormatter
mGraphicsScaleX Double
mGraphicsScaleY Double
mGutterWidth Double
mHasBottomBorder Boolean
mHasFocus Boolean
mHasLeftBorder Boolean
mHasRightBorder Boolean
mHasTopBorder Boolean
mHighlightCurrentLine Boolean
mHighlightDelimitersAroundCaret Boolean
mHorizontalScrollbar Picture
mHorizontalScrollbarThumbBounds Rect
MinimumAutocompletionLength Integer
MinimumParseInterval Integer
mIsDoubleClick Boolean
mLastClickTicks Integer
mLastClickWasContextual Boolean
mLastKeyDownTicks Double
mLastMouseDownX Integer
mLastMouseDownY Integer
mLastMouseDragX Integer
mLastMouseDragY Integer
mLastMouseUpX Integer
mLastMouseUpY Integer
mLastTripleClickTicks Integer
mLineHeight Double
mLineNumberFontSize Integer
mLineNumWidth Double
mLocationUnderMouse XUICELocation
mMaxVisibleLines Integer
mMinimumAutocompletionLength Integer
mParseTimer Timer
mReadOnly Boolean
mScrollPosX Integer
mScrollPosY Integer
mSpacesPerTab Integer
mSuppressAutocompletePopup Boolean
mTheme XUICETheme
mVerticalLinePadding Integer
mVerticalScrollbar Picture
mVerticalScrollbarThumbBounds Rect
NeedsFullRedraw Boolean
ReadOnly Boolean
ScrollPosX Integer
SelectionColour Color
SpacesPerTab Integer
TextSelected Boolean
Theme XUICETheme
UndoIDThreshold Integer
UndoManager XUIUndoManager
VerticalLinePadding Integer

Methods

Name Parameters Returns
AcceptCurrentAutocompleteOption
AutocompleteOptionsAvailable Boolean
CaretAtCurrentLineEnd Boolean
CaretBlinkerAction caretBlinker As Timer
CaretIsInComment Boolean
Clear
ClearDebuggingLine
ComputeGutterWidth lineNumberWidth As Double Double
Constructor
ContentsDidChange
CurrentSelectionAsString String
DeleteBackward allowUndo As Boolean, raiseContentsDidChange As Boolean
DeleteForward allowUndo As Boolean, raiseContentsDidChange As Boolean
DeleteSelection allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean, undoMessage As String
DelimiterTimerAction delimiterTimer As Timer
DocumentSize Rect
DrawBorders g As Graphics
FetchAutocompleteData
ForceRedraw
HandleAutocompleteKeyPress
HandleCtrlSpace
HandleDoubleClick x As Integer, y As Integer
HandleEscKey shouldInvalidate As Boolean
HandleHorizontalScrollbarTrackClick x As Integer, y As Integer
HandleReturnKey allowUndo As Boolean, raiseContentsDidChange As Boolean
HandleTripleClick x As Integer, y As Integer
HandleVerticalScrollbarTrackClick x As Integer, y As Integer
HideAutocompletePopup shouldSetFocus As Boolean
Insert s As String, pos As Integer, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean
InsertCharacter char As String, raiseContentsDidChange As Boolean, range As TextRange
IsDoubleClick x As Integer, y As Integer Boolean
IsOverHorizontalScrollbar x As Integer, y As Integer Boolean
IsOverVerticalScrollbar x As Integer, y As Integer Boolean
IsTripleClick x As Integer, y As Integer Boolean
IsWithinHorizontalScrollbarTrack x As Integer, y As Integer Boolean
IsWithinVerticalScrollbarTrack x As Integer, y As Integer Boolean
LastVisibleLineNumber Integer
LineFullyVisible line As XUICELine Boolean
LineHeight Double
LocationAtXY x As Integer, y As Integer XUICELocation
LocationToCaretPos location As XUICELocation Integer
MaxVisibleLines lineHeight As Double Integer
MoveCaretDown
MoveCaretLeft
MoveCaretRight
MoveCaretToColumn lineNumber As Integer, column As Integer, shouldInvalidate As Boolean
MoveCaretToNextWordEnd
MoveCaretToPos newPos As Integer, shouldInvalidate As Boolean
MoveCaretToPreviousWordStart
MoveCaretUp
MoveDownAndModifySelection
MoveLeftAndModifySelection
MoveRightAndModifySelection
MoveToBeginningOfDocument
MoveToBeginningOfLine
MoveToDocumentBeginningAndModifySelection
MoveToDocumentEndAndModifySelection
MoveToEndOfDocument
MoveToEndOfLine
MoveToLeftEndOfLineAndModifySelection
MoveToRightEndOfLineAndModifySelection
MoveUpAndModifySelection
MoveWordLeftAndModifySelection
MoveWordRightAndModifySelection
NotificationReceived n As XUINotification
PageDownAndModifySelection
PageUpAndModifySelection
PaintBlockCaret g As Graphics, x As Double, y As Double
PaintCaret g As Graphics, pos As Integer
ParseTimerAction parseTimer As Timer
RebuildBackBuffer
RebuildHorizontalScrollbar
RebuildScrollbars
RebuildVerticalScrollbar
RedrawDirtyLines
RegisterForNotifications
ReplaceCurrentSelection s As String
RequiredBufferWidth Double
RequiresHorizontalScrollbar Boolean
RequiresVerticalScrollbar Boolean
ScrollDown linesToScroll As Integer, moveCaret As Boolean, shouldInvalidate As Boolean
ScrollPageDown moveCaret As Boolean, shouldInvalidate As Boolean
ScrollPageUp moveCaret As Boolean, shouldInvalidate As Boolean
ScrollToCaretPos shouldInvalidate As Boolean
ScrollUp linesToScroll As Integer, moveCaret As Boolean, shouldInvalidate As Boolean
SelectAll shouldInvalidate As Boolean
SelectWhitespaceAroundCaret shouldInvalidate As Boolean
SelectWordAtCaret shouldInvalidate As Boolean
SetGraphicsStyle g As Graphics, style As XUICETokenStyle
ShowAutocompletePopup
TabToSpaces String
Typing Boolean
XYAtCaretPos caretPos As Integer, x As Double, y As Double

Events

Name Parameters Returns
AutocompleteDataForPrefix prefix As String, caretLine As Integer, caretColumn As Integer XUICEAutocompleteData
ContentsDidChange
DidContextualClick x As Integer, y As Integer
Opening

Constants

Name Type
BLOCK_GUTTER_MIN_WIDTH Double
CARET_BLINK_PERIOD Double
DEFAULT_AUTOCOMPLETE_POPUP_FONT_SIZE Double
DEFAULT_FONT_SIZE Double
DEFAULT_LINE_NUMBER_FONT_SIZE Double
DELIMITER_TIMER_PERIOD Double
HORIZONTAL_SCROLLBAR_HEIGHT Double
HORIZONTAL_SCROLLBAR_THUMB_HEIGHT Double
LEFT_SCROLL_PADDING Double
LINE_CONTENTS_LEFT_PADDING Double
MIN_LINE_NUMBER_WIDTH Double
PARSE_TIMER_PERIOD Double
POPUP_PADDING Double
RIGHT_SCROLL_PADDING Double
SCROLLBAR_THUMB_PADDING Double
TYPING_SPEED_TICKS Double
UNDO_EVENT_BLOCK_SECONDS Double
VERTICAL_SCROLLBAR_THUMB_WIDTH Double
VERTICAL_SCROLLBAR_WIDTH Double
VSCROLL_SENSITIVITY Double

BLOCK_GUTTER_MIN_WIDTH As Double The minimal width of the gutter containing the block indicators.


CARET_BLINK_PERIOD As Double The interval (in ms) between caret blinks.


DEFAULT_AUTOCOMPLETE_POPUP_FONT_SIZE As Double The default font size for the options in the autocomplete popup to use if not overridden.


DEFAULT_FONT_SIZE As Double The default font size to use if not overridden.


DEFAULT_LINE_NUMBER_FONT_SIZE As Double The default font size to use for line numbers if not overridden.


DELIMITER_TIMER_PERIOD As Double The number of milliseconds between updating the nearest delimiters to the caret.


HORIZONTAL_SCROLLBAR_HEIGHT As Double The width of the vertical scrollbar.


HORIZONTAL_SCROLLBAR_THUMB_HEIGHT As Double The width of the vertical scrollbar thumb.


LEFT_SCROLL_PADDING As Double The number of pixels to pad left when scrolling leftwards.


LINE_CONTENTS_LEFT_PADDING As Double The padding between the right gutter edge and the line contents.


MIN_LINE_NUMBER_WIDTH As Double If line numbers are not drawn, this is the minimum width of the line number section of the gutter.


PARSE_TIMER_PERIOD As Double The number of milliseconds between checks to see if we should invoke the formatter's Parse() method.


POPUP_PADDING As Double The number of pixels between the autocomplete popup and the edge of the canvas.


RIGHT_SCROLL_PADDING As Double Fudge factor for padding the right of lines when horizontal scrolling.


SCROLLBAR_THUMB_PADDING As Double The number of pixels to pad either side of the scrollbar thumb.


TYPING_SPEED_TICKS As Double The number of ticks between keystrokes to still be considered as actively typing.


UNDO_EVENT_BLOCK_SECONDS As Double The number of seconds within which undoable action will be grouped together as a single undoable action.


VERTICAL_SCROLLBAR_THUMB_WIDTH As Double The width of the vertical scrollbar thumb.


VERTICAL_SCROLLBAR_WIDTH As Double The width of the vertical scrollbar.


VSCROLL_SENSITIVITY As Double Higher number = more lines scrolled when quickly scrolling vertically. Values between 1 - 3 work well.


Enumerations

AutocompleteCombos

The acceptable key combinations for triggering autocompletion.

Name
CtrlSpace
Tab

CaretTypes

The different types of caret the canvas supports.

Name
Block
Underscore
VerticalBar

ContentTypes

The type of content the editor is processing.

Name
Markdown
SourceCode

Property Descriptions

AllowAutocomplete As Boolean

True if the editor supports autocompletion.


AllowAutoCompleteInComments As Boolean

If True then the autocomplete engine will also function inside comments.


AllowInertialScrolling As Boolean

If True then the canvas will vertically scroll faster if the mouse wheel is moved faster.


AutocloseBrackets As Boolean

If True then the editor will automatically close parentheses, square brackets and curly brackets when an opening bracket is entered and the caret is not in a comment.


AutocompleteCombo As XUICodeEditor.AutocompleteCombos

The keyboard shortcut used to trigger autocompletion.


AutocompleteData As XUICEAutocompleteData

The autocomplete options for prefix in front of the caret. May be Nil.


AutocompletePopupFontName As String

The name of the font family to use for options in the autocomplete popup.


AutocompletePopupFontSize As Integer

The autocomplete popup option font size.


BackgroundColor As Color

The editor's background colour.


BlinkCaret As Boolean

True if the caret should periodically blink.


BorderColor As ColorGroup

The colour of the editor's border (if enabled).


CaretColour As Color

The caret colour.


CaretColumn As Integer

The current 0-based column the caret is in.


CaretData As XUICECaretData

Data required for drawing the block type caret.


CaretLineNumber As Integer

The number of the line the caret is currently on.


CaretPosition As Integer

The current position of the caret in the editor (0-based).


CaretType As CaretTypes

The type of caret the canvas should use.


CaretXCoordinate As Integer

The absolute X coordinate of the caret at its current position (computed and expensive).


ClosingBracketForOpener As Dictionary

Maps opening brackets (e.g. "[") to their closer (e.g. "]"). Key = opening bracket (string), Value = matching closing bracket (string).


Contents As String

The text contents of the editor.


ContentType As XUICodeEditor.ContentTypes

The type of contents in the editor (Markdown or source code).


CurrentLine As XUICELine

The line that the caret is currently on.


CurrentLineHighlightColor As Color

The colour to use to highlight the current line (if enabled).


CurrentLineNumberColor As Color

The colour of the line number if it is the current line.


CurrentSelection As XUITextSelection

The currently selected text range (or Nil if nothing selected).


CurrentUndoID As Integer

The ID of the group of undo actions that are considered one "event" for the purposes of undo.


DebuggingLine As Integer

The line number to highlights as being currently debugged. Set to 0 if no line should be highlighted in this way.


DebugLineColour As Color

The colour to use when highlighting a line for debugging.


DisplayLineNumbers As Boolean

True if line numbers should be displayed.


DrawBlockLines As Boolean

If True then the editor will draw block lines for source code.


FirstVisibleLine As Integer

The number of the line visible at the top of the canvas. Altered by vertical scrolling.


FontName As String

The font family used in the canvas.


FontSize As Integer

The font size to use for text in the editor.


Formatter As XUICEFormatter

The formatter used to format text.


HasBottomBorder As Boolean

If True then a border will be drawn at the bottom of the editor.


HasFocus As Boolean

True if the editor currently has the focus.


HasLeftBorder As Boolean

If True then a border will be drawn at the left edge of the editor.


HasRightBorder As Boolean

If True then a border will be drawn at the right edge of the editor.


HasTopBorder As Boolean

If True then a border will be drawn at the top of the editor.


HighlightCurrentLine As Boolean

If True then the line the caret is currently on will be highlighted.


HighlightDelimitersAroundCaret As Boolean

If True then delimiters (such as { and }) will be highlighted around the caret. Only supported by some formatters.


JustTokenised As Boolean

Internally set to True whenever the tokenisation has occurred.


LastFullyVisibleLineNumber As Integer

The line number of the last fully visible line.


LastParseMicroseconds As Double

The time (from System.Microseconds) that the last Formatter.Parse() invocation occurred.


LineManager As XUICELineManager

A reference to this code editor's line manager.


LineNumberColor As Color

The line number colour for lines that are not the current line.


LineNumberFontSize As Integer

The line number font size. Must be less than FontSize.


LongestLineChanged As Boolean

If True then the there has been a change in the length of the longest line.


mAutocompletePopup As XUICodeEditorAutocompletePopup

This code editor's autocomplete popup control.


mBackBuffer As Picture

The buffer we draw the editor contents to and then blit to the screen each frame.


mBorderColor As ColorGroup

The colour of the editor's border (if enabled).


mCachedRequiredBufferWidth As Double

A cache of the required buffer width computed in the last Paint event.


mCaretBlinker As Timer

The timer responsible for blinking the caret.


mCaretPosition As Integer

Backing field for the CaretPosition computed property.


mCaretType As CaretTypes

Backing field for the CaretType computed property.


mCaretVisible As Boolean

True if the caret has blinked visible, False if not.


mCurrentLine As XUICELine

Backing field for the CurrentLine computed property.


mCurrentSelection As XUITextSelection

Backing field for the CurrentSelection computed property.


mCurrentUndoID As Integer

Backing field for the CurrentUndoID computed property.


mDebuggingLine As Integer

The line number to highlights as being currently debugged. Set to 0 if no line should be highlighted in this way.


mDelimiterTimer As Timer

Runs periodically to update the nearest delimiters to the caret position.


mDisplayLineNumbers As Boolean

Backing field for the DisplayLineNumbers computed property.


mDragging As Boolean

True if the mouse is currently dragging.


mDraggingHorizontalScrollbarThumb As Boolean

Set to True in MouseDown if the user has clicked the horizontal scrollbar thumb on Windows & Linux.


mDraggingVerticalScrollbarThumb As Boolean

Set to True in MouseDown if the user has clicked the vertical scrollbar thumb on Windows & Linux.


mDrawBlockLines As Boolean

If True then the editor will draw block lines for source code. Backs the DrawBlockLines computed property.


mFirstVisibleLine As Integer

Backing field for the FirstVisibleLine computed property.


mFontName As String

Backing field for the FontName computed property.


mFontSize As Integer

Backing field for the FontSize computed property.


mFormatter As XUICEFormatter

The formatter used to format text. Backs the Formatter computed property.


mGraphicsScaleX As Double

The cached canvas Graphics.ScaleX value.


mGraphicsScaleY As Double

The cached canvas Graphics.ScaleY value.


mGutterWidth As Double

An internal cache of the gutter width in pixels.


mHasBottomBorder As Boolean

If True then a border will be drawn at the bottom of the editor.


mHasFocus As Boolean

Backing field for the HasFocus computed property.


mHasLeftBorder As Boolean

If True then a border will be drawn at the left edge of the editor.


mHasRightBorder As Boolean

If True then a border will be drawn at the right edge of the editor.


mHasTopBorder As Boolean

If True then a border will be drawn at the top of the editor.


mHighlightCurrentLine As Boolean

Backing field for the HighlightCurrentLine computed property.


mHighlightDelimitersAroundCaret As Boolean

If True then delimiters (such as { and }) will be highlighted around the caret. Only supported by some formatters.


mHorizontalScrollbar As Picture

The horizontal scrollbar image to draw. May be Nil if not required.


mHorizontalScrollbarThumbBounds As Rect

The current bounds of the horizontal scrollbar thumb. Will be Nil if the vertical scrollbar is not visible. Always Nil on macOS.


MinimumAutocompletionLength As Integer

The minimum number of characters required before autocompletion is offered. Must be >= 2.


MinimumParseInterval As Integer

The minimum time (in milliseconds) between calls to the editor's formatter's Parse() method.


mIsDoubleClick As Boolean

True if the last click that occurred was a double click.


mLastClickTicks As Integer

The ticks that the last mouse click occurred at.


mLastClickWasContextual As Boolean

True if the mouse click that just occurred in the MouseDown event was a contextual click.


mLastKeyDownTicks As Double

The time of the last KeyDown event. Used to determine if the user is still typing.


mLastMouseDownX As Integer

The X coordinate of the last MouseDown event.


mLastMouseDownY As Integer

The Y coordinate of the last MouseDown event.


mLastMouseDragX As Integer

The X coordinate during the last MouseDrag event or -1 if the mouse has been released since the last drag event.


mLastMouseDragY As Integer

The Y coordinate during the last MouseDrag event or -1 if the mouse has been released since the last drag event.


mLastMouseUpX As Integer

The X mouse coordinate from the previous MouseUp event.


mLastMouseUpY As Integer

The Y mouse coordinate from the previous MouseUp event.


mLastTripleClickTicks As Integer

The ticks that the last triple click occurred at.


mLineHeight As Double

Internal cache of the current line height.


mLineNumberFontSize As Integer

Backing field for the computed LineNumberFontSize.


mLineNumWidth As Double

Internal cache of the line number width in the gutter.


mLocationUnderMouse As XUICELocation

The line location underneath the mouse cursor.


mMaxVisibleLines As Integer

A cache of the last value returned by the MaxVisibleLines method. It's the maximum number of lines visible in the canvas. Will never be more than the number of lines in existence.


mMinimumAutocompletionLength As Integer

The minimum number of characters required before autocompletion is offered. Backs the MinimumAutocompletionLength computed property.


mParseTimer As Timer

Periodically checks to see if the formatter can parse the contents.


mReadOnly As Boolean

Backing store for the ReadOnly computed property.


mScrollPosX As Integer

Backing field for the ScrollPosX computed property.


mScrollPosY As Integer

The Y coordinate the canvas last scrolled to.


mSpacesPerTab As Integer

The number of spaces to insert in place of the tab character.


mSuppressAutocompletePopup As Boolean

If True then the autocomplete popup is suppressed even if there is autocomplete data available. Set after the user has cancelled or accepted autocomplete.


mTheme As XUICETheme

The editor's current theme (backs the Theme computed property).


mVerticalLinePadding As Integer

Backing field for the VerticalLinePadding computed property.


mVerticalScrollbar As Picture

The vertical scrollbar image to draw. May be Nil if not required.


mVerticalScrollbarThumbBounds As Rect

The current bounds of the vertical scrollbar thumb. Will be Nil if the vertical scrollbar is not visible. Always Nil on macOS.


NeedsFullRedraw As Boolean

True if the canvas needs a full redraw.


ReadOnly As Boolean

If True then the canvas is read-only (i.e. not editable).


ScrollPosX As Integer

The horizontal scroll offset. 0 is baseline. Positive indicates scrolling to the right.


SelectionColour As Color

The selection colour.


SpacesPerTab As Integer

The number of spaces to insert in place of the tab character.


TextSelected As Boolean

True if there is any text currently selected.


Theme As XUICETheme

The editor's current theme.


UndoIDThreshold As Integer

The number of ticks that represents the start of a new undo event block.


UndoManager As XUIUndoManager

A reference to this editor's undo manager.


VerticalLinePadding As Integer

The number of pixels to pad a line on its top and bottom edges.


Method Descriptions

AcceptCurrentAutocompleteOption()

Accepts the currently selected option in the autocomplete popup.


AutocompleteOptionsAvailable() As Boolean

True if there are autocompletion options available at the current caret position.


CaretAtCurrentLineEnd() As Boolean

True if the caret is at the end of the current line.


CaretBlinkerAction(caretBlinker As Timer)

Toggles the visibility of the caret. Called by mCaretBlinker.Action.


CaretIsInComment() As Boolean

Returns True if the token at the current caret position is a comment.


Clear()

Clears the contents of the editor.


ClearDebuggingLine()

If a line is currently being highlighted for debugging it will no longer be highlighted this way.


ComputeGutterWidth(lineNumberWidth As Double) As Double

Computes the width in pixels of the gutter using the passed lineNumberWidth.


Constructor()

Default constructor.


ContentsDidChange()

Raises this editor's ContentsDidChange event.


CurrentSelectionAsString() As String

Returns the contents of the current selection. May return an empty string.


DeleteBackward(allowUndo As Boolean, raiseContentsDidChange As Boolean)

Deletes the character before the caret and invalidates the canvas.

If allowUndo is True then this action will be undoable. If raiseContentsDidChange is True then we will also raise the ContentsDidChange event. By default, ContentsDidChange is raised but sometimes (e.g. when this method is called internally by other methods) we don't.


DeleteForward(allowUndo As Boolean, raiseContentsDidChange As Boolean)

Deletes the character immediately in front of the caret and invalidates the canvas.

If allowUndo is True then this action will be undoable. If raiseContentsDidChange is True then we will also raise the ContentsDidChange event. By default, ContentsDidChange is raised but sometimes (e.g. when this method is called internally by other methods) we don't.


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

Deletes the current selection.

If allowUndo is True then this action will be pushed to the undo manager. If shouldInvalidate is True then the canvas will immediately invalidate. If raiseContentsDidChange is True then we will raise the ContentsDidChange event. undoMessage is an optional override message for undoable actions.


DelimiterTimerAction(delimiterTimer As Timer)

Updates the nearest delimiters to the caret periodically. Called by mDelimiterTimer.Action.


DocumentSize() As Rect

Returns the size of the entire contents area in pixels.


DrawBorders(g As Graphics)

Draws any enabled borders.


FetchAutocompleteData()

Requests autocomplete data for the word immediately in front of the caret.


ForceRedraw()

Immediately redraws the canvas.


HandleAutocompleteKeyPress()

Handles the pressing of the autocomplete key.


HandleCtrlSpace()

Handles the pressing of the Ctrl+Space key combination.


HandleDoubleClick(x As Integer, y As Integer)

Handles a double click occurring at the passed x, y mouse coordinates.

  1. Double-clicking when not over a line highlights the last word of the last line.
  2. Double-clicking at the end of a line highlights the last word of that line.
  3. Double-clicking on whitespace highlights the run of whitespace.
  4. Double-clicking on a non-alphanumeric character highlights the character.
  5. Double-clicking within an alphanumeric word selects the word.

HandleEscKey(shouldInvalidate As Boolean)

Handles an Esc key press at the current caret position.


HandleHorizontalScrollbarTrackClick(x As Integer, y As Integer)

Handles a click in the horizontal scrollbar track.

Assumes the click location has been verified prior to this with a call to IsWithinHorizontalScrollbarTrack(). We mimic Window's behaviour so if we left of the thumb we move the thumb up so its left edge is positioned at the mouse click. If we click to the right of the thumb we move the thumb rightwards so its right edge is positioned at the mouse click. Only valid on Windows and Linux.


HandleReturnKey(allowUndo As Boolean, raiseContentsDidChange As Boolean)

Handles a Return key press at the current caret position.

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

Three Scenarios:

  1. The caret is at the end of the line (blank line inserted below with caret at its start).
  2. The caret is at the beginning of the line (blank line inserted above with caret at start of this line).
  3. The caret is in the middle of the line (line is broken and caret is placed at start of new line below).

We then need to scroll to the current caret position.


HandleTripleClick(x As Integer, y As Integer)

Handles a triple click occurring at the passed x, y mouse coordinates. Selects the line under the click.

This will always occur after a double click so HandleDoubleClick will have been called prior to this method.


HandleVerticalScrollbarTrackClick(x As Integer, y As Integer)

Handles a click in the vertical scrollbar track.

Assumes the click location has been verified prior to this with a call to IsWithinVerticalScrollbarTrack(). We mimic Window's behaviour so if we click above the thumb we move the thumb up so its top is positioned at the mouse click. If we click below the thumb we move the thumb down so its bottom is positioned at the mouse click. Only valid on Windows and Linux.


HideAutocompletePopup(shouldSetFocus As Boolean)

Hides the autocomplete popup.


Insert(s As String, pos As Integer, allowUndo As Boolean, shouldInvalidate As Boolean, raiseContentsDidChange As Boolean)

Inserts s at the specified caret position.

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


InsertCharacter(char As String, raiseContentsDidChange As Boolean, range As TextRange)

Inserts a single character at the current caret position.

Assumes char is only one character. For longer strings, use Insert().


IsDoubleClick(x As Integer, y As Integer) As Boolean

If a double click occurred, this method handles it and returns True. Otherwise it returns False.


IsOverHorizontalScrollbar(x As Integer, y As Integer) As Boolean

Returns True if x, y is over any part of the horizontal scrollbar (Windows & Linux only).


IsOverVerticalScrollbar(x As Integer, y As Integer) As Boolean

Returns True if x, y is over any part of the vertical scrollbar (Windows & Linux only).


IsTripleClick(x As Integer, y As Integer) As Boolean

If a triple click just happened, this method handles it and returns True. Otherwise it returns False.

If a triple click occurs, calls the HandleTripleClick() method.


IsWithinHorizontalScrollbarTrack(x As Integer, y As Integer) As Boolean

Returns True if x, y is within a visible horizontal scrollbar track (not the thumb).


IsWithinVerticalScrollbarTrack(x As Integer, y As Integer) As Boolean

Returns True if x, y is within a visible vertical scrollbar track (not the thumb).


LastVisibleLineNumber() As Integer

The 1-based line number of the last visible line.

The line may be only partially visible.


LineFullyVisible(line As XUICELine) As Boolean

Returns True if line is fully visible on the canvas.


LineHeight() As Double

The height (in pixels) of a line.


LocationAtXY(x As Integer, y As Integer) As XUICELocation

Returns the line location at coordinates x, y or Nil if there is no line at those coordinates.

If x is beyond the end of a line then the last column for that line is specified in the returned line location.


LocationToCaretPos(location As XUICELocation) As Integer

Returns the caret position specified by the passed location.


MaxVisibleLines(lineHeight As Double) As Integer

The maximum number of lines that are visible in the canvas.

Will never be more than the maximum number of lines in existence.


MoveCaretDown()

Moves the caret down a line.


MoveCaretLeft()

Moves the caret to the left one position.


MoveCaretRight()

Moves the caret one position to the right.


MoveCaretToColumn(lineNumber As Integer, column As Integer, shouldInvalidate As Boolean)

Moves the caret to the column on the specified line.

If shouldInvalidate is False then the canvas will not be immediately invalidated.

Raises an InvalidArgumentException if lineNumber is out of range. If column is greater than the number of columns in the target line then it moves the caret to the end of the target line.


MoveCaretToNextWordEnd()

Moves the caret to the end of the next word.


MoveCaretToPos(newPos As Integer, shouldInvalidate As Boolean)

Moves the caret to the 0-based newPos, clamped between the start and end of the text.

If shouldInvalidate is False then the canvas will not be immediately invalidated. If newPos < 0 then the caret is moved to the start of the text. If newPos > last valid caret position then the caret is moved to the end of the text.


MoveCaretToPreviousWordStart()

Moves the caret to the start of the previous word.


MoveCaretUp()

Moves the caret up a line.


MoveDownAndModifySelection()

Moves down and modifies the selection.


MoveLeftAndModifySelection()

Moves the caret one position to the left and modifies the current selection.

The user has pressed Shift+Left arrow.


MoveRightAndModifySelection()

Moves the caret one position to the right and modifies the current selection.

The user has pressed Shift+Right arrow.


MoveToBeginningOfDocument()

Moves the caret to the beginning of the document.


MoveToBeginningOfLine()

Moves the caret to the beginning of the line.


MoveToDocumentBeginningAndModifySelection()

Moves to the top of the beginning of the document and modifies the selection.


MoveToDocumentEndAndModifySelection()

Moves to the end of the document and modifies the selection.


MoveToEndOfDocument()

Moves the caret to the end of the document.


MoveToEndOfLine()

Moves the caret to the end of the line.


MoveToLeftEndOfLineAndModifySelection()

Moves the selection to the left end of the line.


MoveToRightEndOfLineAndModifySelection()

Moves the selection to the right end of the line.


MoveUpAndModifySelection()

Moves up and modifies the selection.


MoveWordLeftAndModifySelection()

Selects the text from the beginning of the word to the left of the caret to the current caret position.


MoveWordRightAndModifySelection()

Handles modifying the selection to the end of the word.

On macOS this is Shift+Opt+Right Arrow


NotificationReceived(n As XUINotification)

A notification has been received from the Notification Center.

Part of the XUINotificationListener interface.


PageDownAndModifySelection()

Pages down and modifies the selection.


PageUpAndModifySelection()

Scrolls the page up and modifies the selection.


PaintBlockCaret(g As Graphics, x As Double, y As Double)

Paints the block caret on g at x, y.

Assumes the drawing colour of g has been set to the correct colour for the caret. Assumes that the font properties of g object have been set to the correct style.


PaintCaret(g As Graphics, pos As Integer)

Paints the caret to g at the 0-based pos.


ParseTimerAction(parseTimer As Timer)

Checks to see if enough time has elapsed that we should invoke the formatter's Parse() method.


RebuildBackBuffer()

Rebuilds the entire back buffer by drawing all visible content to it.


RebuildHorizontalScrollbar()

Rebuilds the horizontal scroll bar or sets it to Nil if it's not needed.


RebuildScrollbars()

Rebuilds both the vertical and horizontal scrollbars or sets them to Nil if they aren't needed.


RebuildVerticalScrollbar()

Rebuilds the vertical scroll bar or sets it to Nil if it's not needed.


RedrawDirtyLines()

Redraws all dirty lines to the back buffer.

Assumes that the back buffer exists and is the correct size.


RegisterForNotifications()

Registers the editor for desired notifications.


ReplaceCurrentSelection(s As String)

Replaces the current selection with s.


RequiredBufferWidth() As Double

Returns the width (in pixels) that the back buffer should be to accomodate the longest line, padding and gutter.

Will always be at least as wide as the canvas' current width.


RequiresHorizontalScrollbar() As Boolean

Returns True if a horizontal scrollbar is required (inexpensive computation).


RequiresVerticalScrollbar() As Boolean

Returns True if a vertical scrollbar is required. Inexpensive computation.


ScrollDown(linesToScroll As Integer, moveCaret As Boolean, shouldInvalidate As Boolean)

Scrolls the canvas down linesToScroll lines.

If moveCaret is True then the caret will be moved down by the number of lines we scroll down. If shouldInvalidate is False then the canvas will not be immediately invalidated.


ScrollPageDown(moveCaret As Boolean, shouldInvalidate As Boolean)

Scrolls the canvas down a page and optionally moves the caret down as well.

If moveCaret is True then the caret will be moved down by the number of lines we scroll down. If shouldInvalidate is False then the canvas will not be immediately invalidated.


ScrollPageUp(moveCaret As Boolean, shouldInvalidate As Boolean)

Scrolls the canvas up a page and optionally moves the caret up as well.

If moveCaret is True then the caret will be moved up by the number of lines we scroll up. If shouldInvalidate is False then the canvas will not be immediately invalidated.


ScrollToCaretPos(shouldInvalidate As Boolean)

Scrolls the canvas (if necessary) to the current caret position.

If shouldInvalidate is True then the canvas will immediately redraw.


ScrollUp(linesToScroll As Integer, moveCaret As Boolean, shouldInvalidate As Boolean)

Scrolls the canvas up linesToScroll lines.

If moveCaret is True then the caret will be moved up by the number of lines we scroll up. If shouldInvalidate is False then the canvas will not be immediately invalidated.


SelectAll(shouldInvalidate As Boolean)

Selects everything in the editor.

If shouldInvalidate is True then the editor will immediately refresh.


SelectWhitespaceAroundCaret(shouldInvalidate As Boolean)

Selects all whitespace around the current caret position on the caret's current line.

If shouldInvalidate is True then the canvas will be invalidated. If False then it's merely marked for a full redraw.


SelectWordAtCaret(shouldInvalidate As Boolean)

Selects the word the caret is within and marks the canvas for redrawing.

If shouldInvalidate is True then the canvas will be invalidated. If False then it is merely marked for a full redraw.


SetGraphicsStyle(g As Graphics, style As XUICETokenStyle)

Sets the font properties of g to the specified token style.


ShowAutocompletePopup()

Shows the autocomplete popup at the caret position.


TabToSpaces() As String

Returns a tab characters as a fixed width of space characters. Determined by SpacesPerTab.


Typing() As Boolean

True if the user is still thought to be typing.

We make this decision based on the time the last key was depressed and released as well as an acceptable interval between depressions.


XYAtCaretPos(caretPos As Integer, x As Double, y As Double)

Computes (ByRef) the canvas x, y coordinates at the 0-based caretPos.


Event Descriptions

AutocompleteDataForPrefix(prefix As String, caretLine As Integer, caretColumn As Integer) As XUICEAutocompleteData The code editor is asking for autocompletion options for the specified prefix at caretColumn on line number caretLine. You should return Nil if there are none.


ContentsDidChange() The text contents of the editor has changed.


DidContextualClick(x As Integer, y As Integer) The user contexutal clicked (right clicked) inside the editor at the passed local coordinates.


Opening() The editor is about to be displayed.