mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-06-12 19:55:19 +02:00
move focus to new instance
This commit is contained in:
parent
52ac27ad2e
commit
a14ace8057
1 changed files with 17 additions and 1 deletions
|
|
@ -108,7 +108,23 @@ export function FindReplaceBar({ editor, onClose }: FindReplaceBarProps) {
|
|||
if (currentIndex >= 0 && currentIndex < matches.length) {
|
||||
const match = matches[currentIndex]
|
||||
editor.commands.setTextSelection(match)
|
||||
editor.commands.scrollIntoView()
|
||||
// Use coordsAtPos to get the screen position, then scroll the
|
||||
// .editor-content-wrapper container so the match is visible.
|
||||
try {
|
||||
const coords = editor.view.coordsAtPos(match.from)
|
||||
const wrapper = editor.view.dom.closest('.editor-content-wrapper')
|
||||
if (wrapper) {
|
||||
const rect = wrapper.getBoundingClientRect()
|
||||
const relativeTop = coords.top - rect.top
|
||||
// If the match is outside the visible area, scroll to center it
|
||||
if (relativeTop < 0 || relativeTop > rect.height - 40) {
|
||||
wrapper.scrollTop += relativeTop - rect.height / 3
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Fallback to ProseMirror's built-in scroll
|
||||
editor.commands.scrollIntoView()
|
||||
}
|
||||
}
|
||||
}, [currentIndex, matches, editor])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue