SelectionModel (JavaFX 28)
Description: declaration: module: jfx.incubator.richtext, package: jfx.incubator.scene.control.richtext, interface: SelectionModel

# Interface SelectionModel

All Known Implementing Classes:
  `SingleSelectionModel`

public interface SelectionModel
A Selection model that maintains a single `SelectionSegment`.

Since:
  24

- ## Property Summary

  Properties
  Type
  Property
  Description
  `ReadOnlyProperty<TextPos>`
  `anchorPosition`
  Anchor position property.
  `ReadOnlyProperty<TextPos>`
  `caretPosition`
  Caret position property.
  `ReadOnlyProperty<SelectionSegment>`
  `selection`
  Selection property.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ReadOnlyProperty<TextPos>`
  `anchorPositionProperty()`
  Anchor position property.
  `ReadOnlyProperty<TextPos>`
  `caretPositionProperty()`
  Caret position property.
  `void`
  `clear()`
  Clears the selection.
  `void`
  `extendSelection(StyledTextModel model, TextPos pos)`
  Extends selection to the specified position.
  `SelectionSegment`
  `getSelection()`
  Returns the current selection.
  `ReadOnlyProperty<SelectionSegment>`
  `selectionProperty()`
  Selection property.
  `void`
  `setSelection(StyledTextModel model, TextPos anchor, TextPos caret)`
  Replaced existing selection, if any, with the new one.

- ## Property Details

  - ### caretPosition

    ReadOnlyProperty<TextPos> caretPositionProperty
    Caret position property. The value can be null, indicating no selection. When the caret position is `null`, the `selectionProperty` and the `anchorPositionProperty` are also `null`.

    Note: `selectionProperty()`, `anchorPositionProperty()`, and `caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Default value:
      null
    See Also:
      - `caretPositionProperty()`

  - ### anchorPosition

    ReadOnlyProperty<TextPos> anchorPositionProperty
    Anchor position property. The value can be null, indicating no selection. When the anchor position is `null`, the `selectionProperty` and the `caretPositionProperty` are also `null`.

    Note: `selectionProperty()`, `anchorPositionProperty()`, and `caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Default value:
      null
    See Also:
      - `anchorPositionProperty()`

  - ### selection

    ReadOnlyProperty<SelectionSegment> selectionProperty
    Selection property. The value can be null, indicating no selection. When the selection segment is `null`, the `anchorPositionProperty` and the `caretPositionProperty` are also `null`.
    Default value:
      null
    See Also:
      - `getSelection()`
      - `selectionProperty()`

- ## Method Details

  - ### clear

    void clear()
    Clears the selection. This sets `selectionProperty`, `anchorPositionProperty`, and `caretPositionProperty` to null.

  - ### setSelection

    void setSelection(StyledTextModel model, TextPos anchor, TextPos caret)
    Replaced existing selection, if any, with the new one. While this method will accept the text positions outside of the document range, the actual values of `anchorPositionProperty`, and `caretPositionProperty` must always remain within the valid range for the document.
    Parameters:
      `model` - the model, must be non-null
      `anchor` - the anchor position, must be non-null
      `caret` - the caret position, must be non-null

  - ### extendSelection

    void extendSelection(StyledTextModel model, TextPos pos)
    Extends selection to the specified position. Internally, the position will be normalized to be within the document boundaries. This method will issue a `setSelection(model, pos, pos)` call if the model instance is different from that passed before.

    While this method will accept the text position outside of the document range, the actual values of `anchorPositionProperty`, and `caretPositionProperty` must always remain within the valid range for the document.

    Parameters:
      `model` - the model, must be non-null
      `pos` - the new caret position, must be non-null

  - ### caretPositionProperty

    ReadOnlyProperty<TextPos> caretPositionProperty()
    Caret position property. The value can be null, indicating no selection. When the caret position is `null`, the `selectionProperty` and the `anchorPositionProperty` are also `null`.

    Note: `selectionProperty()`, `anchorPositionProperty()`, and `caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Default value:
      null
    Returns:
      the caret position property

  - ### anchorPositionProperty

    ReadOnlyProperty<TextPos> anchorPositionProperty()
    Anchor position property. The value can be null, indicating no selection. When the anchor position is `null`, the `selectionProperty` and the `caretPositionProperty` are also `null`.

    Note: `selectionProperty()`, `anchorPositionProperty()`, and `caretPositionProperty()` are logically connected. When a change occurs, the anchor position is updated first, followed by the caret position, followed by the selection segment.

    Default value:
      null
    Returns:
      the anchor position property

  - ### selectionProperty

    ReadOnlyProperty<SelectionSegment> selectionProperty()
    Selection property. The value can be null, indicating no selection. When the selection segment is `null`, the `anchorPositionProperty` and the `caretPositionProperty` are also `null`.
    Default value:
      null
    Returns:
      the selection property
    See Also:
      - `getSelection()`

  - ### getSelection

    SelectionSegment getSelection()
    Returns the current selection. The value can be null, indicating no selection. When the selection segment is `null`, the `anchorPositionProperty` and the `caretPositionProperty` are also `null`.
    Returns:
      current selection, or null