Options
All
  • Public
  • Public/Protected
  • All
Menu

A caret manager maintains and modifies caret and selection positions. It also manages associated GUI elements like the input field. It is also responsible for converting positions in the GUI tree to positions in the data tree and vice-versa.

Given wed's notion of parallel data and GUI trees. A caret can either point into the GUI tree or into the data tree. In the following documentation, if the caret is not qualified, then it is a GUI caret.

Similarly, a selection can either span a range in the GUI tree or in the data tree. Again, "selection" without qualifier is a GUI selection.

Hierarchy

  • CaretManager

Implements

Index

Constructors

constructor

  • Parameters

    • guiRoot: DLocRoot

      The object representing the root of the gui tree.

    • dataRoot: DLocRoot

      The object representing the root of the data tree.

    • inputField: HTMLElement

      The HTML element that is the input field.

    • guiUpdater: GUIUpdater

      The GUI updater that is responsible for updating the tree whose root is guiRoot.

    • layer: Layer

      The layer that holds the caret.

    • scroller: Scroller

      The element that scrolls guiRoot.

    • modeTree: ModeTree

      The mode tree from which to get modes.

    Returns CaretManager

Properties

Private $inputField

$inputField: JQuery

Private _events

_events: Subject<CaretChange>

Private _sel

_sel: WedSelection | undefined

Private dataRoot

dataRoot: DLocRoot

The object representing the root of the data tree.

Private dataRootEl

dataRootEl: Document | Element

Private doc

doc: Document

events

events: Observable<CaretChange>

This is where you can listen to caret change events.

Private guiRoot

guiRoot: DLocRoot

The object representing the root of the gui tree.

Private guiRootEl

guiRootEl: Document | Element

Private guiUpdater

guiUpdater: GUIUpdater

The GUI updater that is responsible for updating the tree whose root is guiRoot.

Private inputField

inputField: HTMLElement

The HTML element that is the input field.

Private layer

layer: Layer

The layer that holds the caret.

mark

mark: CaretMark

The caret mark that represents the caret managed by this manager.

Private modeTree

modeTree: ModeTree

The mode tree from which to get modes.

Private prevCaret

prevCaret: DLoc | undefined

Private prevMode

prevMode: Mode | undefined

Private scroller

scroller: Scroller

The element that scrolls guiRoot.

Private selAtBlur

selAtBlur: WedSelection | undefined

Private selectionStack

selectionStack: (undefined | WedSelection)[] = []

Private win

win: Window

Accessors

anchor

  • get anchor(): DLoc | undefined

caret

  • get caret(): DLoc | undefined
  • The raw caret. Use getNormalizedCaret if you need it normalized.

    This is synonymous with the focus of the current selection. (foo.caret === foo.focus === foo.sel.focus).

    Returns DLoc | undefined

docDLocRange

focus

  • get focus(): DLoc | undefined

maxCaret

  • get maxCaret(): DLoc

minCaret

  • get minCaret(): DLoc

range

  • get range(): Range | undefined

rangeInfo

sel

Methods

Private _caretChange

Private _getDOMSelection

  • _getDOMSelection(): Selection

Private _getDOMSelectionRange

  • _getDOMSelectionRange(): Range | undefined

Private _normalizeCaret

  • _normalizeCaret(loc: DLoc | undefined | null): DLoc | undefined | null
  • Modify the passed position so that it if appears inside of a placeholder node, the resulting position is moved out of it.

    Parameters

    • loc: DLoc | undefined | null

      The location to normalize.

    Returns DLoc | undefined | null

    The normalized position. If undefined or null was passed, then the return value is the same as what was passed.

Private _restoreCaretAndSelection

  • _restoreCaretAndSelection(gainingFocus: boolean): void
  • Restores the caret and selection from the current selection. This is used to deal with situations in which the caret and range may have been "damaged" due to browser operations, changes of state, etc.

    Parameters

    • gainingFocus: boolean

      Whether the restoration of the caret and selection is due to regaining focus or not.

    Returns void

Private _setDOMSelectionRange

  • _setDOMSelectionRange(range: Range): void
  • This function is meant to be used internally to manipulate the DOM selection directly.

    Parameters

    • range: Range

    Returns void

Private _setGUICaret

clearSelection

  • clearSelection(): void

collapseSelection

  • collapseSelection(): void

dumpCaretInfo

  • dumpCaretInfo(): void

focusInputField

  • focusInputField(): void
  • Focus the field use for input events. It is used by wed on some occasions where it is needed. Mode authors should never need to call this. If they do find that calling this helps solve a problem they ran into, they probably should file an issue report.

    Returns void

fromDataLocation

  • fromDataLocation(loc: DLoc): DLoc | undefined
  • fromDataLocation(node: Node, offset: number): DLoc | undefined
  • Convert a caret location in the data tree into one in the GUI tree.

    Parameters

    • loc: DLoc

      A location in the data tree.

    Returns DLoc | undefined

    A location in the GUI tree, or undefined if no such location exists.

  • Parameters

    • node: Node
    • offset: number

    Returns DLoc | undefined

getDataCaret

  • getDataCaret(approximate?: undefined | true | false): DLoc | undefined
  • Get the current caret position in the data tree.

    Parameters

    • Optional approximate: undefined | true | false

      Some GUI locations do not correspond to data locations. Like if the location is in a gui element or phantom text. By default, this method will return undefined in such case. If this parameter is true, then this method will return the closest position.

    Returns DLoc | undefined

    A caret position in the data tree, or undefined if no such position exists.

getNormalizedCaret

  • getNormalizedCaret(): DLoc | undefined
  • Get a normalized caret.

    Returns DLoc | undefined

    A normalized caret, or undefined if there is no caret.

highlightRange

makeCaret

  • makeCaret(node: Node | null | undefined, offset?: undefined | number, normalize?: boolean): DLoc | undefined
  • Make a caret from a node and offset pair.

    Parameters

    • node: Node | null | undefined

      The node from which to make the caret. The node may be in the GUI tree or the data tree. If offset is omitted, the resulting location will point to this node (rather than point to some offset inside the node.)

    • Optional offset: undefined | number

      The offset into the node.

    • Default value normalize: boolean = false

      Whether to normalize the location. (Note that this is normalization in the DLoc sense of the term.)

    Returns DLoc | undefined

    A new caret. This will be undefined if the value passed for node was undefined or if the node is not in the GUI or data trees.

move

  • move(direction: caretMovement.Direction, extend?: boolean): void
  • Move the caret in a specific direction. The caret may not move if it is not possible to move in the specified direction.

    Parameters

    • direction: caretMovement.Direction

      The direction in which to move.

    • Default value extend: boolean = false

    Returns void

mustFromDataLocation

  • mustFromDataLocation(loc: DLoc): DLoc
  • mustFromDataLocation(node: Node, offset: number): DLoc

mustGetNormalizedCaret

  • mustGetNormalizedCaret(): DLoc

newCaretPosition

  • newCaretPosition(direction: caretMovement.Direction): DLoc | undefined
  • Compute the position of the current caret if it were moved according to some direction.

    Parameters

    • direction: caretMovement.Direction

      The direction in which the caret would be moved.

    Returns DLoc | undefined

    The position to the right of the caret position. Or undefined if there is no valid position to compute.

newPosition

  • newPosition(pos: DLoc | undefined, direction: caretMovement.Direction): DLoc | undefined
  • Compute a position derived from an arbitrary position. Note that this method is meant to be used for positions in the GUI tree. Computing positions in the data tree requires no special algorithm.

    This method does not allow movement outside of the GUI tree.

    Parameters

    • pos: DLoc | undefined

      The starting position in the GUI tree.

    • direction: caretMovement.Direction

      The direction in which to move.

    Returns DLoc | undefined

    The position to the right of the starting position. Or undefined if the starting position was undefined or if there is no valid position to compute.

normalizeToEditableRange

  • normalizeToEditableRange(loc: DLoc): DLoc

onBlur

  • onBlur(): void
  • This is called when the editing area is blurred. This is not something you should be calling in a mode's implementation. It is public because other parts of wed need to call it.

    Returns void

Private onFocus

  • onFocus(): void

popSelection

  • popSelection(): void
  • Pop the last selection that was pushed with pushSelection and restore the current caret and selection on the basis of the popped value.

    Returns void

popSelectionAndDiscard

  • popSelectionAndDiscard(): void
  • Pop the last selection that was pushed with pushSelection but do not restore the current caret and selection from the popped value.

    Returns void

pushSelection

  • pushSelection(): void
  • Save the current selection (and caret) on an internal selection stack.

    Returns void

setCaret

setCaretToLabelPosition

  • setCaretToLabelPosition(target: Node, label: Element, location: DLoc): void
  • Set the caret into a normalized label position. There are only some locations in which it is valid to put the caret inside a label:

    • The element name.

    • Inside attribute values.

    This method is used by DOM event handlers (usually mouse events handlers) to normalize the location of the caret to one of the valid locations listed above.

    Parameters

    • target: Node

      The target of the DOM event that requires moving the caret.

    • label: Element

      The label element that contains target.

    • location: DLoc

      The location of the event, which is what is normalized by this method.

    Returns void

setRange

  • setRange(anchorNode: Node, anchorOffset: number, focusNode: Node, focusOffset: number): void
  • setRange(anchor: DLoc, focus: DLoc): void
  • Set the range to a new value.

    Parameters

    • anchorNode: Node

      The anchor's node.

    • anchorOffset: number

      The anchor's offset.

    • focusNode: Node

      The focus' node.

    • focusOffset: number

      The focus's offset.

    Returns void

  • Parameters

    Returns void

toDataLocation

  • toDataLocation(loc: DLoc, approximate?: undefined | true | false): DLoc | undefined
  • toDataLocation(node: Node, offset: number, approximate?: undefined | true | false): DLoc | undefined
  • Converts a gui location to a data location.

    Parameters

    • loc: DLoc

      A location in the GUI tree.

    • Optional approximate: undefined | true | false

      Some GUI locations do not correspond to data locations. Like if the location is in a gui element or phantom text. By default, this method will return undefined in such case. If this parameter is true, then this method will return the closest position.

    Returns DLoc | undefined

    The data location that corresponds to the location passed. This could be undefined if the location does not correspond to a location in the data tree.

  • Parameters

    • node: Node
    • offset: number
    • Optional approximate: undefined | true | false

    Returns DLoc | undefined

Generated using TypeDoc