feat: scroll editor to cursor position when slash command palette opens#34
Merged
feat: scroll editor to cursor position when slash command palette opens#34
Conversation
- 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)
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.
Summary
/) opens, automatically scrolls the editor so the cursor is positioned near the top of the visible areaChanges
New files
src/features/editor/lib/commandPaletteScrollConfig.ts— mutable config with defaults and store keysrc/features/editor/hooks/useCommandPaletteScroll.ts— hook for reading/saving scroll configsrc/features/settings/ui/CommandPaletteScrollOption.tsx— settings UI (Switch + Slider)Modified files
src/App.tsx— addedscrollCursorToTopfunction, wired toonSuggestionMenuOpensrc/features/editor/ui/Editor.tsx— addedonSuggestionMenuOpenprop + SuggestionMenu store subscriptionsrc/features/editor/index.ts— exporteduseCommandPaletteScrollsrc/features/settings/ui/SettingsDialog.tsx— addedCommandPaletteScrollOptionsrc/shared/hooks/useScrollIsolation.ts— fixedhasExternalPortal()to only lock scroll on elements outside the editor containerImplementation Notes
suggestionMenustore extension (accessed viaeditor.getExtension("suggestionMenu")) to detect when the palette opens viashow: boolean(notstate !== undefined, which is always true)requestAnimationFrameto avoid racing with ProseMirror's built-inscrollIntoView