reverts insert property logic

This commit is contained in:
sergeyteleshev
2025-06-16 16:40:22 +02:00
parent 1e16a01305
commit 8cd0e21ad7
2 changed files with 20 additions and 0 deletions
@@ -19,6 +19,7 @@ import { type IReactCodemirrorContext, ReactCodemirrorContext } from './ReactCod
import { useCodemirrorExtensions } from './useCodemirrorExtensions.js';
import { validateCursorBoundaries } from './validateCursorBoundaries.js';
import { ReactCodemirrorSearchPanel } from './ReactCodemirrorSearchPanel.js';
import { hasInsertProperty } from './hasInsertProperty.js';
const External = Annotation.define<boolean>();
@@ -213,6 +214,13 @@ export const ReactCodemirror = observer<IReactCodeMirrorProps, IEditorRef>(
}
}
if (hasInsertProperty(transaction.changes) && !transaction.selection) {
transaction.selection = {
anchor: transaction.changes.insert?.length ?? 0,
head: transaction.changes.insert?.length ?? 0,
};
}
if (transaction.changes) {
view.dispatch({ changes: transaction.changes });
}
@@ -0,0 +1,12 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2025 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { ChangeSpec, Text } from '@codemirror/state';
export function hasInsertProperty(spec: ChangeSpec | undefined): spec is { from: number; to?: number; insert?: string | Text } {
return typeof spec === 'object' && spec !== null && 'insert' in spec;
}