Add a blinking text caret#32
Open
andrewtheart wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a blinking text caret. Currently the caret is drawn solid on every cursor-canvas redraw and never blinks.
How
A small
CaretBlinkManagerdrives the blink while the control is focused:IsCaretVisibleflag on aDispatcherQueueTimerat 530 ms (the Windows default caret interval).CursorRenderer.Drawgates only theRenderCursor(...)call onIsCaretVisible. 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.CanvasUpdateManager.UpdateCursor()callsNotifyCaretActivity()(resets the phase). The blink timer redraws via a separateRedrawCursorForBlink()that does not reset the phase (otherwise the caret would never toggle).FocusManager.SetFocus()→Start(),RemoveFocus()→Stop(), andUnload()stops it too.Files
Core/CaretBlinkManager.cs.Core/CoreTextControlBox.xaml.cs— construct/init the manager, pass it toCursorRenderer.Init, stop it inUnload.Core/Renderer/CursorRenderer.cs— gate the caret paint onIsCaretVisible.Core/FocusManager.cs— start/stop on focus change.Core/CanvasUpdateManager.cs—NotifyCaretActivity()+RedrawCursorForBlink().Testing
TextControlBox.csproj, Release/x64).Contributing this back upstream after adding it for a downstream editor built on TextControlBox.