Header menu logo issie

Editor Module

Types and nested modules

Type/Module Description

Constants

constants used by code editor

HighlightT

the type of the code editor's text string asociated with a given highlight color

LineData

Type of data passed to the line render function from the main render function. This is a subset of CodeEditorModel data and derived from this.

MatchStream

The type of the input to the highlighter. This is a list of characters, since the input to the highlighter is a string. Matching operations have type: MatchStream -> (string * ElementType) * MatchStream. TODO: MatchStream could have state added to make the highlighting context-sensitive. E.g. to remember if the string being highlighted starts in a comment or not: MatchStream = bool * char list. More generally Matchstream = StateT * char list where StateT is a discriminated union.

Functions and values

Function or value Description

charsStartWith prefix str

Full Usage: charsStartWith prefix str

Parameters:
    prefix : string
    str : char list

Returns: bool

Return true if the characters in str, interpreted as a string, start with prefix.

prefix : string
str : char list
Returns: bool

highlight chars

Full Usage: highlight chars

Parameters:
Returns: (string * HighlightT) list

Return chars segmented as a list of strings each paired with a HighlightT. The string is the text to be highlighted and the HighlightT determines the color. HighlightT to color mapping is done in the render function.

chars : MatchStream
Returns: (string * HighlightT) list

initCodeEditorState

Full Usage: initCodeEditorState

Returns: CodeEditorModel

Initial state of the code editor.

Returns: CodeEditorModel

intersectionOpt other this

Full Usage: intersectionOpt other this

Parameters:
Returns: Interval option

Returns the intersection of two intervals each defining the end points of a raster scan (ascending order X first then Y), or None if there is no intersection.

other : Interval
this : Interval
Returns: Interval option

makeAPMatch startP inMatchP str

Full Usage: makeAPMatch startP inMatchP str

Parameters:
    startP : char -> bool
    inMatchP : char -> bool
    str : MatchStream

Returns: (string * MatchStream) option

Active pattern helper that matches if a list of chars starts with startP. If it matches the return value is a pair: the first character and the string of characters matching inMatchP the list of chars from the first character that does not match inMatchP. or None if the first character does not match startP. NB - this cannot itself be an active pattern since startP and inMatchP are not literals.

startP : char -> bool
inMatchP : char -> bool
str : MatchStream
Returns: (string * MatchStream) option

mouseEventHandler evType dispatch ev

Full Usage: mouseEventHandler evType dispatch ev

Parameters:

Handles editor mouse events. evtype is the type of event (e.g., click, mousemove). dispatch is the function to call to update the model. ev is the mouse event from the browser.

evType : string
dispatch : Msg -> unit
ev : MouseEvent

reactMemoize functionToMemoize name key props

Full Usage: reactMemoize functionToMemoize name key props

Parameters:
    functionToMemoize : 'Props -> ReactElement
    name : string
    key : ('Props -> string) option
    props : 'Props

Returns: ReactElement

Memoizes the function as a react component so that it is not called unless the props change. In addition, if the function is not called, the React DOM from the function result is not updated. This is important for performance when the react DOM is large.

functionToMemoize : 'Props -> ReactElement
name : string
key : ('Props -> string) option
props : 'Props
Returns: ReactElement

renderEditor model dispatch

Full Usage: renderEditor model dispatch

Parameters:
Returns: ReactElement

Renders the complete code editor with syntax highlighting and error indication. The editor is rendered in a div with a fixed size as specified in the CSS Height and Width props. The height of the editor is rounded to fit an integral number of lines. The editor is scrollable in both X and Y directions. CoceEditorModel is the model for the code editor, and includes info about the lines of code, the cursor position, and any errors.

model : CodeEditorModel
dispatch : Msg -> unit
Returns: ReactElement

renderLineNumbers xPosition model

Full Usage: renderLineNumbers xPosition model

Parameters:
Returns: ReactElement

Renders the line numbers in the left margin of the code editor. xPosition is the X position of the left margin within the scrolling editor div It changes to ensure the left margin stays fixed at the left of the editor. The number of lines is determined by the number of lines in the model.

xPosition : 'a
model : CodeEditorModel
Returns: ReactElement

renderOneEditorLine data

Full Usage: renderOneEditorLine data

Parameters:
Returns: ReactElement

Renders a single line of code in the editor, with optional cursor and error indication.

data : LineData
Returns: ReactElement

testEditorModel

Full Usage: testEditorModel

Returns: CodeEditorModel

Some ad hoc test data for the code editor used during development. Change as needed, this is not a unit test.

Returns: CodeEditorModel

update editorMsg model

Full Usage: update editorMsg model

Parameters:
Returns: Model * Cmd<'a>

Main editor model update function, called from Elmish main update when a CodeEditorMsg Message is received. This allows additional Code Editor messages to be added here in the future without changing the main update function. Note that the message type must still be changed in ModelType.fs since F# does not support forward type references even to an opaque type. NB - There is a way to get forward references - by parametrising the Model type - that is theoretically neat, and possible, but in practice it is too messy to implement because type parameters would then decorate the whole code base.

editorMsg : EditorMsg
model : Model
Returns: Model * Cmd<'a>

updateEditorCursor xMouse yMouse model

Full Usage: updateEditorCursor xMouse yMouse model

Parameters:
    xMouse : int
    yMouse : int
    model : Model

Returns: Model

Updates the Editor model with the new cursor position based on mouse coordinates. xMouse and yMouse are the mouse coordinates. xMouse specifies the column position in the line at which new chars are inserted xMouse - 1 is the column that is deleted on backspace. Model is the whole Issie Model - of which CodeEditorModel is one field.

xMouse : int
yMouse : int
model : Model
Returns: Model

updateEditorOnKeyPress keyPress model

Full Usage: updateEditorOnKeyPress keyPress model

Parameters:
Returns: Model * Cmd<'a>

Implements a model update for a key press event. The keyCode is the code of the key pressed. Normally, this is a character code, but it can also be a special key code (e.g., backspace). Character codes are inserted. Special codes are handled differently. Lines and CursorPos are updated accordingly.

keyPress : KeyPressInfo
model : Model
Returns: Model * Cmd<'a>

Active patterns

Active pattern Description

(|CharP|_|) charToMatch str

Full Usage: (|CharP|_|) charToMatch str

Parameters:
Returns: MatchStream option

Active Pattern that matches if str starts with a given character. Returns the remaining string if it does. NB - charToMatch must be a literal for this to work

charToMatch : char
str : MatchStream
Returns: MatchStream option

(|IdentifierP|_|) str

Full Usage: (|IdentifierP|_|) str

Parameters:
Returns: (string * MatchStream) option

Active Pattern that matches if str starts with an identifier. Returns the identifier and the remaining string if it does.

str : MatchStream
Returns: (string * MatchStream) option

(|NormalMatch|_|) str

Full Usage: (|NormalMatch|_|) str

Parameters:
Returns: (string * MatchStream) option

Returns as many characters not part of any other active pattern match as possible. This must be adjusted to match the otehr active patterns. Note that doing this without a this pattern, using a default for each character, would be inefficient since it would require a match for each character in the string. In addition it would require another pass to common up sequences of characters. However that would make the code more robust, and perhaps it would be better to do this.

str : MatchStream
Returns: (string * MatchStream) option

(|NumberP|_|) str

Full Usage: (|NumberP|_|) str

Parameters:
Returns: (string * MatchStream) option

Active Pattern that matches if str starts with a number. Returns the number and the remaining string if it does.

str : MatchStream
Returns: (string * MatchStream) option

(|StringLP|_|) prefixL str

Full Usage: (|StringLP|_|) prefixL str

Parameters:
Returns: (string * MatchStream) option

Active Pattern that matches if a char list starts with any of the prefixes in a list. Returns the prefix and the remaining characters if it does. NB - prefixL must be a literal for this to work

prefixL : string list
str : MatchStream
Returns: (string * MatchStream) option

(|StringLiteralStart|_|) str

Full Usage: (|StringLiteralStart|_|) str

Parameters:
Returns: (string * MatchStream) option

Active Pattern that matches if str starts with a string literal. A string literal is a string starting with a quote and ending with a quote. Returns the non quote part of the string literal and the remainder of str if it does. The closing quote is not removed from str.

str : MatchStream
Returns: (string * MatchStream) option

Type something to start searching.