[PR #17181] Fix multiple cursor invalidation issues #31147

Closed
opened 2026-01-31 09:45:24 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/17181

State: closed
Merged: Yes


There were multiple bugs:

  • GDI engine only paints whatever has been invalidated.
    This means we need to not just invalidate the old cursor rect
    but also the new one, or else movements may not be visible.
  • The composition should be drawn at the cursor position even if
    the cursor is invisible, but inside the renderer viewport.
  • Conceptually, scrolling the viewport moves the relative cursor
    position even if the cursor is invisible.
  • An invisible cursor is not the same as one that's outside the
    viewport. It's more like a cursor that's not turned on.

To resolve the first issue we simply need to call InvalidateCursor
again. To do so, it was abstracted into _invalidateCurrentCursor().

The next 2 issues are resolved by un-optional-izing CursorOptions.
After all, even an invisible or an out-of-bounds cursor still has a
coordinate and it may still be scrolled into view.
Instead, it has the new inViewport property as a replacement.
This allows for instance the IME composition code in the renderer
to use the cursor coordinate while the cursor is invisible.

The last issue is fixed by simply changing the .isOn logic.

Closes #17150

Validation Steps Performed

  • In conhost with the GDI renderer:
    printf "\e[2 q"; sleep 2; printf "\e[A"; sleep 2; printf "\e[B"
    Cursor moves up after 2s and then down again after 2s. ✅
  • Hide the cursor ("\e[?25l") and use a CJK IME.
    Words can still be written and deleted correctly. ✅
  • Turning the cursor back on ("\e[?25h") works ✅
  • Scrolling shows/hides the cursor ✅
**Original Pull Request:** https://github.com/microsoft/terminal/pull/17181 **State:** closed **Merged:** Yes --- There were multiple bugs: * GDI engine only paints whatever has been invalidated. This means we need to not just invalidate the old cursor rect but also the new one, or else movements may not be visible. * The composition should be drawn at the cursor position even if the cursor is invisible, but inside the renderer viewport. * Conceptually, scrolling the viewport moves the relative cursor position even if the cursor is invisible. * An invisible cursor is not the same as one that's outside the viewport. It's more like a cursor that's not turned on. To resolve the first issue we simply need to call `InvalidateCursor` again. To do so, it was abstracted into `_invalidateCurrentCursor()`. The next 2 issues are resolved by un-`optional`-izing `CursorOptions`. After all, even an invisible or an out-of-bounds cursor still has a coordinate and it may still be scrolled into view. Instead, it has the new `inViewport` property as a replacement. This allows for instance the IME composition code in the renderer to use the cursor coordinate while the cursor is invisible. The last issue is fixed by simply changing the `.isOn` logic. Closes #17150 ## Validation Steps Performed * In conhost with the GDI renderer: `printf "\e[2 q"; sleep 2; printf "\e[A"; sleep 2; printf "\e[B"` Cursor moves up after 2s and then down again after 2s. ✅ * Hide the cursor (`"\e[?25l"`) and use a CJK IME. Words can still be written and deleted correctly. ✅ * Turning the cursor back on (`"\e[?25h"`) works ✅ * Scrolling shows/hides the cursor ✅
claunia added the pull-request label 2026-01-31 09:45:24 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31147