Table of Contents

Class SelectionStateHelper

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Helper class for managing selection state updates across controls. Eliminates code duplication and prevents double event firing bugs.

public static class SelectionStateHelper
Inheritance
SelectionStateHelper
Inherited Members

Methods

UpdateSelection(ref int, int, int, Action<int>?)

Updates selection index with proper guard clause to prevent duplicate events.

public static bool UpdateSelection(ref int currentIndex, int newIndex, int maxIndex, Action<int>? onChanged = null)

Parameters

currentIndex int

Reference to the current selected index field

newIndex int

The new index to select

maxIndex int

Maximum valid index (exclusive upper bound)

onChanged Action<int>

Optional callback invoked once if selection changed

Returns

bool

True if selection changed, false otherwise

UpdateSelectionByOffset(ref int, int, int, Action<int>?)

Updates selection by relative offset (e.g., +1 for down, -1 for up).

public static bool UpdateSelectionByOffset(ref int currentIndex, int offset, int maxIndex, Action<int>? onChanged = null)

Parameters

currentIndex int

Reference to the current selected index field

offset int

Offset to apply (positive for down, negative for up)

maxIndex int

Maximum valid index (exclusive upper bound)

onChanged Action<int>

Optional callback invoked once if selection changed

Returns

bool

True if selection changed, false otherwise

UpdateSelectionByPage(ref int, int, int, int, Action<int>?)

Updates selection by page offset (PageUp/PageDown).

public static bool UpdateSelectionByPage(ref int currentIndex, int pageSize, int direction, int maxIndex, Action<int>? onChanged = null)

Parameters

currentIndex int

Reference to the current selected index field

pageSize int

Number of items per page

direction int

Direction: 1 for PageDown, -1 for PageUp

maxIndex int

Maximum valid index (exclusive upper bound)

onChanged Action<int>

Optional callback invoked once if selection changed

Returns

bool

True if selection changed, false otherwise

UpdateSelectionWithScroll(ref int, int, int, ref int, int, Action<int>?)

Updates selection and adjusts scroll offset to ensure item is visible. Combines selection update with viewport scrolling logic.

public static bool UpdateSelectionWithScroll(ref int currentIndex, int newIndex, int maxIndex, ref int scrollOffset, int visibleItems, Action<int>? onChanged = null)

Parameters

currentIndex int

Reference to the current selected index field

newIndex int

The new index to select

maxIndex int

Maximum valid index (exclusive upper bound)

scrollOffset int

Reference to the scroll offset field

visibleItems int

Number of items visible in viewport

onChanged Action<int>

Optional callback invoked once if selection changed

Returns

bool

True if selection changed, false otherwise