fix: prevent cursor reset when typing in filter input (#2287)

Fixes #2268
This commit is contained in:
kolaente 2026-02-24 12:50:45 +01:00 committed by GitHub
parent 9e633b3e82
commit f7a93e4ca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 5 deletions

View File

@ -119,7 +119,9 @@ const editor = useEditor({
content: '',
onUpdate: ({editor}) => {
const content = editor.getText()
emit('update:modelValue', processContent(content))
const processed = processContent(content)
lastEmittedValue = processed
emit('update:modelValue', processed)
},
})
@ -135,10 +137,21 @@ const processContent = (content: string) => {
)
}
// Watch for changes to the model value
let lastEmittedValue: string | undefined
// Watch for changes to the model value from external sources.
// Skip when the change originated from the editor itself (onUpdate emit)
// to avoid a destructive round-trip where whitespace normalization in
// transformFilterStringForApi changes the text and setContent resets the cursor.
watch(
() => props.modelValue,
value => setEditorContentFromModelValue(value),
() => props.modelValue,
value => {
if (value === lastEmittedValue) {
return
}
setEditorContentFromModelValue(value)
lastEmittedValue = undefined
},
{immediate: true},
)
@ -180,7 +193,9 @@ function updateDateInQuery(newDate: string | Date | null) {
editor.value.commands.setContent(newText, {
emitUpdate: false,
})
emit('update:modelValue', processContent(newText))
const processed = processContent(newText)
lastEmittedValue = processed
emit('update:modelValue', processed)
}

View File

@ -207,6 +207,36 @@ describe('Filter Transformation', () => {
expect(transformed).toBe('( labels = 456 || project = 123 )')
})
it('should normalize spacing around operators', () => {
const transformed = transformFilterStringForApi(
'labels=ipsum',
nullTitleToIdResolver,
nullTitleToIdResolver,
)
expect(transformed).toBe('labels = ipsum')
})
it('should normalize missing space after operator', () => {
const transformed = transformFilterStringForApi(
'labels =ipsum',
nullTitleToIdResolver,
nullTitleToIdResolver,
)
expect(transformed).toBe('labels = ipsum')
})
it('should normalize missing space before operator', () => {
const transformed = transformFilterStringForApi(
'labels= ipsum',
nullTitleToIdResolver,
nullTitleToIdResolver,
)
expect(transformed).toBe('labels = ipsum')
})
})
describe('Special Characters', () => {