Skip to content

Commit b219a8d

Browse files
committed
Fix bugs in DropdownControl, ButtonControl, and PromptControl
- DropdownControl: PageUp/PageDown now moves by _maxVisibleItems instead of 1 - ButtonControl: ProcessKey now checks IsEnabled before handling Enter/Space - PromptControl: Remove spurious InputChanged events on Enter and Escape - PromptControl: Fix Backspace/LeftArrow scroll condition to only trigger when cursor leaves visible area - Update EXAMPLES.md to reflect current DemoApp features
1 parent 292ae83 commit b219a8d

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

SharpConsoleUI/Controls/ButtonControl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ public Color? BorderColor
166166
/// <inheritdoc/>
167167
public bool ProcessKey(ConsoleKeyInfo key)
168168
{
169+
if (!_enabled) return false;
170+
169171
if (key.Key == ConsoleKey.Enter || key.Key == ConsoleKey.Spacebar)
170172
{
171173
// Trigger the click event

SharpConsoleUI/Controls/DropdownControl/DropdownControl.Keyboard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public bool ProcessKey(ConsoleKeyInfo key)
111111
case ConsoleKey.PageUp:
112112
if (_isDropdownOpen && currentHighlight > 0)
113113
{
114-
int newIndex = Math.Max(0, currentHighlight - ( 1));
114+
int newIndex = Math.Max(0, currentHighlight - _maxVisibleItems);
115115
_highlightedIndex = newIndex;
116116
EnsureHighlightedItemVisible();
117117
Container?.Invalidate(true);
@@ -122,7 +122,7 @@ public bool ProcessKey(ConsoleKeyInfo key)
122122
case ConsoleKey.PageDown:
123123
if (_isDropdownOpen && currentHighlight < _items.Count - 1)
124124
{
125-
int newIndex = Math.Min(_items.Count - 1, currentHighlight + ( 1));
125+
int newIndex = Math.Min(_items.Count - 1, currentHighlight + _maxVisibleItems);
126126
_highlightedIndex = newIndex;
127127
EnsureHighlightedItemVisible();
128128
Container?.Invalidate(true);

SharpConsoleUI/Controls/PromptControl.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,14 @@ public bool ProcessKey(ConsoleKeyInfo key)
249249
HasFocus = false;
250250
}
251251
Container?.Invalidate(true);
252-
InputChanged?.Invoke(this, _input);
253252
return true;
254253
}
255254
else if (key.Key == ConsoleKey.Backspace && cursorPos > 0)
256255
{
257256
_input = _input.Remove(cursorPos - 1, 1);
258257
int newCursorPos = cursorPos - 1;
259258
_cursorPosition = newCursorPos;
260-
if (newCursorPos < scrollOffset + (_inputWidth ?? _input.Length))
259+
if (newCursorPos < scrollOffset)
261260
{
262261
SetScrollOffset(scrollOffset - 1);
263262
}
@@ -290,7 +289,7 @@ public bool ProcessKey(ConsoleKeyInfo key)
290289
{
291290
int newCursorPos = cursorPos - 1;
292291
_cursorPosition = newCursorPos;
293-
if (newCursorPos < scrollOffset + (_inputWidth ?? _input.Length))
292+
if (newCursorPos < scrollOffset)
294293
{
295294
SetScrollOffset(scrollOffset - 1);
296295
}
@@ -312,7 +311,6 @@ public bool ProcessKey(ConsoleKeyInfo key)
312311
{
313312
HasFocus = false;
314313
Container?.Invalidate(true);
315-
InputChanged?.Invoke(this, _input);
316314
return true;
317315
}
318316
else if (!char.IsControl(key.KeyChar))

docs/EXAMPLES.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,16 @@ dotnet run --project Examples/DemoApp
336336
```
337337

338338
**Key Features:**
339-
- Fluent `WindowBuilder` pattern
340-
- Multiple window types (Log, System Info, Clock, File Explorer, Command, etc.)
341-
- `LogViewerControl` with real-time updates
342-
- `TreeControl` for file system navigation
343-
- `DropdownControl` with styled items
344-
- `ListControl` with selection handling
339+
- Six independent windows running simultaneously (Terminal, Canvas, DataGrid, System Info, Image Viewer, and the launcher)
340+
- `TerminalControl` with PTY-backed shell
341+
- `CanvasControl` with interactive starfield and plasma effects
342+
- `TableControl` (DataGrid) with 10,000 virtual rows, sorting, filtering, and cell editing
343+
- `ImageControl` rendering images directly in the terminal
344+
- Full markup syntax showcase with colors, decorations, and gradients
345345
- Async window threads with `CancellationToken`
346-
- Theme switching
346+
- Theme switching and window taskbar navigation
347347

348-
**Windows Available:** F1-F9 to open various demo windows
348+
**Windows Available:** Ctrl+O to open demo windows, Alt+1-6 to switch
349349

350350
---
351351

docs/images/examples/demoapp.png

323 KB
Loading

0 commit comments

Comments
 (0)