fix(filter): restore cursor position when making changes

Related https://github.com/go-vikunja/vikunja/issues/1395
This commit is contained in:
kolaente 2025-11-16 15:38:24 +01:00
parent 2e3b2cb770
commit 675a550247
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 9 additions and 0 deletions

View File

@ -154,9 +154,18 @@ function setEditorContentFromModelValue(newValue: string | undefined) {
) : ''
if (editor.value.getText() !== content) {
// Preserve cursor position before updating content
const currentPosition = editor.value.state.selection.from
editor.value.commands.setContent(content, {
emitUpdate: false,
})
// Restore cursor position after content update
// Ensure position is within the new content bounds
const maxPosition = editor.value.state.doc.content.size
const safePosition = Math.min(currentPosition, maxPosition)
editor.value.commands.setTextSelection(safePosition)
}
}