Skip to content

Add a blinking text caret#32

Open
andrewtheart wants to merge 1 commit into
FrozenAssassine:masterfrom
andrewtheart:feat/blinking-caret
Open

Add a blinking text caret#32
andrewtheart wants to merge 1 commit into
FrozenAssassine:masterfrom
andrewtheart:feat/blinking-caret

Conversation

@andrewtheart

Copy link
Copy Markdown

What

Adds a blinking text caret. Currently the caret is drawn solid on every cursor-canvas redraw and never blinks.

How

A small CaretBlinkManager drives the blink while the control is focused:

  • Toggles an IsCaretVisible flag on a DispatcherQueueTimer at 530 ms (the Windows default caret interval).
  • CursorRenderer.Draw gates only the RenderCursor(...) call on IsCaretVisible. The current-line highlighter stays unconditional, so the highlighted line doesn't flicker while the caret blinks. Because Win2D clears the caret canvas each draw, skipping the paint yields a real blink.
  • Cursor activity keeps the caret solid so it never blinks mid-keystroke: CanvasUpdateManager.UpdateCursor() calls NotifyCaretActivity() (resets the phase). The blink timer redraws via a separate RedrawCursorForBlink() that does not reset the phase (otherwise the caret would never toggle).
  • The timer runs only while focused: FocusManager.SetFocus()Start(), RemoveFocus()Stop(), and Unload() stops it too.

Files

  • New Core/CaretBlinkManager.cs.
  • Core/CoreTextControlBox.xaml.cs — construct/init the manager, pass it to CursorRenderer.Init, stop it in Unload.
  • Core/Renderer/CursorRenderer.cs — gate the caret paint on IsCaretVisible.
  • Core/FocusManager.cs — start/stop on focus change.
  • Core/CanvasUpdateManager.csNotifyCaretActivity() + RedrawCursorForBlink().

Testing

  • Builds clean (TextControlBox.csproj, Release/x64).
  • Focused: caret blinks at ~530 ms; typing/moving keeps it solid for a full interval then resumes. Unfocused: caret is not painted (unchanged). No blink timer runs while unfocused.

Contributing this back upstream after adding it for a downstream editor built on TextControlBox.

The caret was drawn solid on every redraw and never blinked. Add a CaretBlinkManager that toggles caret visibility on a 530ms DispatcherQueueTimer (Windows default) while focused. CursorRenderer gates only the RenderCursor call on IsCaretVisible so the current-line highlighter stays solid. Cursor activity (UpdateCursor) resets the phase via NotifyCaretActivity so the caret stays solid while typing; the blink timer redraws via RedrawCursorForBlink which does not reset the phase. FocusManager starts/stops the timer on focus change and Unload stops it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant