Skip to content

[desktop] Fix module-level state and silent failure in caret plugin#14

Merged
usamaasfar merged 2 commits intosmooth-caretfrom
copilot/sub-pr-13
Feb 21, 2026
Merged

[desktop] Fix module-level state and silent failure in caret plugin#14
usamaasfar merged 2 commits intosmooth-caretfrom
copilot/sub-pr-13

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

caret.ts used module-level activeView/activeEl variables, meaning each new editor instance silently overwrote the previous ones. Additionally, missing parentElement was swallowed via optional chaining, producing an invisible, never-appended caret element with no error surfaced.

Changes

  • Multi-instance tracking – replaced activeView/activeEl with Map<EditorView, HTMLElement>; setCaretStyle now iterates all active instances instead of clobbering on each mount
// before
let activeView: EditorView | null = null;
let activeEl: HTMLElement | null = null;

// after
const activeInstances = new Map<EditorView, HTMLElement>();
  • Explicit failure on missing parent – replaced view.dom.parentElement?.appendChild(el) with a guard that throws an actionable error, so a mis-mounted editor fails loudly at init rather than silently rendering nothing
  • Lifecycle cleanupdestroy() now calls activeInstances.delete(view) (keyed deletion), replacing the previous null-assignment that broke any remaining instances

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Greptile Summary

Fixed critical bugs in caret plugin by replacing module-level singleton state with a Map<EditorView, HTMLElement> to properly track multiple editor instances, and replaced silent optional chaining failure with explicit error when parent element is missing.

Key improvements:

  • Multi-instance support - setCaretStyle now updates all active editors instead of only the most recent one
  • Fail-fast validation - missing parent element now throws descriptive error at initialization instead of silently creating an orphaned DOM element
  • Proper cleanup - destroy() uses keyed deletion from Map instead of nulling shared state

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The changes are well-architected bug fixes that improve code correctness without introducing new complexity. The refactoring from singleton to Map properly handles multiple instances, and the explicit error handling replaces silent failures with actionable errors.
  • No files require special attention

Important Files Changed

Filename Overview
apps/desktop/src/editor/plugins/caret.ts Refactored from module-level singleton to Map-based multi-instance tracking; added explicit parent element validation

Last reviewed commit: ba5fb5b

Co-authored-by: usamaasfar <42825498+usamaasfar@users.noreply.github.com>
Copilot AI changed the title [WIP] Add smooth animated caret with line and underline styles [desktop] Fix module-level state and silent failure in caret plugin Feb 21, 2026
Copilot AI requested a review from usamaasfar February 21, 2026 18:11
@usamaasfar usamaasfar marked this pull request as ready for review February 21, 2026 18:13
@usamaasfar usamaasfar merged commit 7172585 into smooth-caret Feb 21, 2026
1 check passed
@usamaasfar usamaasfar deleted the copilot/sub-pr-13 branch February 21, 2026 18:17
usamaasfar added a commit that referenced this pull request Feb 21, 2026
* Add smooth animated caret with line and underline styles

- Custom ProseMirror plugin renders a virtual caret (hides native)
- Smooth 60ms CSS transition between positions while typing
- Blink pauses while typing, resumes 0.5s after last keystroke
- Line and underline styles switchable via Appearance > Cursor menu
- Style persisted to localStorage and restored on startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [desktop] Fix module-level state and silent failure in caret plugin (#14)

* Initial plan

* Fix module-level state and silent failure in caret plugin

Co-authored-by: usamaasfar <42825498+usamaasfar@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: usamaasfar <42825498+usamaasfar@users.noreply.github.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.

2 participants