Class SelectionManager
- Namespace
- SharpConsoleUI.Core
- Assembly
- SharpConsoleUI.dll
Manages text selection within a single Window. This is the single source of truth for which ISelectableControl owns the active selection. Only one control may have a selection at a time: SetActiveSelection(ISelectableControl) clears the previously active control's selection before adopting the new one. Mirrors the per-window FocusManager.
public class SelectionManager
- Inheritance
-
SelectionManager
- Inherited Members
- Extension Methods
Remarks
Re-entrancy: a control's ClearSelection() must NOT call back into SetActiveSelection(ISelectableControl). It is only expected to reset the control's own state and invalidate.
Constructors
SelectionManager(Window)
Initializes a new SelectionManager for the given window.
public SelectionManager(Window window)
Parameters
windowWindow
Properties
ActiveSelection
Gets the control that currently owns the active selection, or null.
public ISelectableControl? ActiveSelection { get; }
Property Value
HasSelection
Gets whether any control in the window currently has a non-empty selection.
public bool HasSelection { get; }
Property Value
Methods
ClearSelection()
Clears the active selection, if any.
public void ClearSelection()
GetSelectedText()
Gets the active selection's plain text, or null if nothing is selected.
public string? GetSelectedText()
Returns
SetActiveSelection(ISelectableControl)
Makes control the owner of the active selection. If a different control
previously owned the selection, its selection is cleared first (single-selection invariant).
Controls call this when they begin or extend a selection.
public void SetActiveSelection(ISelectableControl control)
Parameters
controlISelectableControl
Events
SelectionChanged
Fired whenever the active selection changes (adopted, updated, or cleared).
public event EventHandler<SelectionChangedEventArgs>? SelectionChanged