Skip to content

feat: scroll editor to cursor position when slash command palette opens#34

Merged
j4rviscmd merged 2 commits intomainfrom
feat/command-palette-scroll
Mar 24, 2026
Merged

feat: scroll editor to cursor position when slash command palette opens#34
j4rviscmd merged 2 commits intomainfrom
feat/command-palette-scroll

Conversation

@j4rviscmd
Copy link
Copy Markdown
Owner

Summary

  • When the slash command palette (/) opens, automatically scrolls the editor so the cursor is positioned near the top of the visible area
  • Adds a configurable setting (enable/disable + position slider 0–90%) in the Settings dialog
  • Fixes scroll isolation to avoid locking scroll on elements inside the editor container

Changes

New files

  • src/features/editor/lib/commandPaletteScrollConfig.ts — mutable config with defaults and store key
  • src/features/editor/hooks/useCommandPaletteScroll.ts — hook for reading/saving scroll config
  • src/features/settings/ui/CommandPaletteScrollOption.tsx — settings UI (Switch + Slider)

Modified files

  • src/App.tsx — added scrollCursorToTop function, wired to onSuggestionMenuOpen
  • src/features/editor/ui/Editor.tsx — added onSuggestionMenuOpen prop + SuggestionMenu store subscription
  • src/features/editor/index.ts — exported useCommandPaletteScroll
  • src/features/settings/ui/SettingsDialog.tsx — added CommandPaletteScrollOption
  • src/shared/hooks/useScrollIsolation.ts — fixed hasExternalPortal() to only lock scroll on elements outside the editor container

Implementation Notes

  • Used BlockNote's suggestionMenu store extension (accessed via editor.getExtension("suggestionMenu")) to detect when the palette opens via show: boolean (not state !== undefined, which is always true)
  • Used requestAnimationFrame to avoid racing with ProseMirror's built-in scrollIntoView

- Subscribe to BlockNote SuggestionMenu extension store via editor.onMount()
  to detect when the slash command palette opens
- Use UiElementPosition.show boolean (not undefined-check) for correct
  open/close transition detection on repeated invocations
- Scroll the container so the cursor lands at a configurable fraction from
  the top (default 25%), giving the palette more vertical room
- Skip scroll if the cursor is already above the target position
- Fix useScrollIsolation createPortalScrollLock to ignore elements that are
  descendants of the scroll container (prevents false-positive overflowY lock)
- Add CommandPaletteScrollOption settings UI with enable toggle and position
  slider (0–90%), persisted via configStore (commandPaletteScrollEnabled /
  commandPaletteScrollFraction keys)
@j4rviscmd j4rviscmd added the enhancement New feature or request label Mar 24, 2026
@j4rviscmd j4rviscmd merged commit 8c2885e into main Mar 24, 2026
@j4rviscmd j4rviscmd deleted the feat/command-palette-scroll branch March 24, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant