Class TextModeSelectionManager
Manages click-drag text selection for a text mode grid view. Place this component alongside a TextModeView or UITextModeView and assign the view as the grid provider. Handles mouse input, applies Selected to affected cells, and provides text extraction and clipboard support.
Inherited Members
Namespace: Scylla.TextMode
Assembly: ScyllaTextMode.dll
Syntax
[AddComponentMenu("Scylla/TextMode/TextMode Selection Manager")]
public class TextModeSelectionManager : MonoBehaviour
Properties
CopyShortcutEnabled
Gets or sets whether Ctrl+C (Cmd+C on macOS) copies the selection. On by default. Turn it off when the host maps copying to its own input and calls CopyToClipboard().
Declaration
public bool CopyShortcutEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
CurrentRange
Gets the current selection range.
Declaration
public CellRange CurrentRange { get; }
Property Value
| Type | Description |
|---|---|
| CellRange |
HasSelection
Gets whether there is an active non-empty selection.
Declaration
public bool HasSelection { get; }
Property Value
| Type | Description |
|---|---|
| bool |
InputEnabled
Gets or sets whether mouse input is enabled for selection. When set to false, mouse input is ignored and any in-progress selection is cleared. Used by TextModeMouseReporter to suppress selection while mouse reporting is active.
Side-effects when set to false: If a selection is active or in progress, the OnSelectionCleared delegate is invoked and a TextModeSelectionEndedEvent is published (if PublishEvents is true).
Declaration
public bool InputEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSelecting
Gets whether a drag selection is currently in progress.
Declaration
public bool IsSelecting { get; }
Property Value
| Type | Description |
|---|---|
| bool |
PinnedBottomRows
Gets or sets how many rows at the bottom of the grid stay in place while the rest scrolls, such as a status line. A selection made above them is never drawn into them, so a selection moved by ShiftSelection(int) does not spill onto the status line. A selection made on them stays put when the rest shifts.
Declaration
public int PinnedBottomRows { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
PublishEvents
Gets or sets whether to publish SEX events.
Declaration
public bool PublishEvents { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ViewProvider
Gets or sets the view provider MonoBehaviour. Must implement ITextModeGridProvider.
When set after OnEnable, the provider is re-resolved immediately.
Declaration
public MonoBehaviour ViewProvider { get; set; }
Property Value
| Type | Description |
|---|---|
| MonoBehaviour |
Methods
ClearSelection()
Clears the current selection.
Declaration
public void ClearSelection()
CopyToClipboard()
Copies the selected text to the system clipboard.
Declaration
public void CopyToClipboard()
GetSelectedText()
Extracts the text content of the current selection. Trailing spaces on each row are trimmed, rows are separated by newlines.
Declaration
public string GetSelectedText()
Returns
| Type | Description |
|---|---|
| string | The selected text, or an empty string if no selection. |
RefreshSelectionVisuals()
Re-applies the Selected attribute to all cells in the current selection range. Call this after any operation that overwrites grid cells (e.g. a full re-render) to restore the visual selection highlight.
Declaration
public void RefreshSelectionVisuals()
SelectAll()
Selects all cells in the grid.
Declaration
public void SelectAll()
SelectRow(int)
Selects all cells in the specified row.
Declaration
public void SelectRow(int row)
Parameters
| Type | Name | Description |
|---|---|---|
| int | row | Row index to select. |
SetInputEnabled(bool, bool)
Turns mouse input for selection on or off, and decides whether a finished selection survives turning it off.
Declaration
public void SetInputEnabled(bool enabled, bool clearSelection)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | enabled | Whether mouse input starts and extends selections. |
| bool | clearSelection | Whether turning input off clears a finished selection. |
Remarks
InputEnabled always clears the selection when input is turned off. This method can keep a finished selection instead, so it stays highlighted and can still be copied. TextModeMouseReporter uses this for a selection made with Shift held while an application has mouse reporting on. A drag that is still in progress is always cancelled, since it has no finished range to keep.
SetSelection(CellRange)
Sets the selection to the specified range programmatically.
Declaration
public void SetSelection(CellRange range)
Parameters
| Type | Name | Description |
|---|---|---|
| CellRange | range | The range to select. |
ShiftSelection(int)
Moves the selection by a number of rows, so it stays on the same text when the view scrolls its content.
Declaration
public void ShiftSelection(int rows)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rows | Rows to move. Positive moves the selection down. |
Remarks
Call this right after the view scrolled, including when scrolling swapped the grid it shows, as a terminal does when it switches between its live screen and a view of its history. The swap is then taken as the same content moved, and the selection is kept instead of cleared. Parts of the selection that move out of view are kept too and are drawn again when they scroll back in. Copying takes only the visible part.
Events
OnSelectionChanged
Invoked when the selection range changes during a drag. Parameter is the new range. May be null if no subscriber has registered.
Declaration
public event Action<CellRange> OnSelectionChanged
Event Type
| Type | Description |
|---|---|
| Action<CellRange> |
OnSelectionCleared
Invoked when the selection is cleared. May be null if no subscriber has registered.
Declaration
public event Action OnSelectionCleared
Event Type
| Type | Description |
|---|---|
| Action |
OnSelectionEnded
Invoked when a selection drag ends. Parameters are the final range and the selected text. May be null if no subscriber has registered.
Declaration
public event Action<CellRange, string> OnSelectionEnded
Event Type
| Type | Description |
|---|---|
| Action<CellRange, string> |
OnSelectionStarted
Invoked when a selection drag begins. Parameter is the initial range (anchor == active). May be null if no subscriber has registered.
Declaration
public event Action<CellRange> OnSelectionStarted
Event Type
| Type | Description |
|---|---|
| Action<CellRange> |