Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-formula-ui): wrong curosr index caused by move-range (#4517)

zhangw6cd058396dc1
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
index 174c35780b..bb94d9e4a7 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
@@ -173,15 +173,6 @@ export function FormulaEditor(props: IFormulaEditorProps) {
}
}, [formulaText, isFocus, highlight]);
- // useEffect(() => {
- // const sub = docSelectionRenderService?.onChangeByEvent$.subscribe((e) => {
- // const formulaText = BuildTextUtils.transform.getPlainText(document?.getBody()?.dataStream ?? '');
- // highlight(formulaText, false, true);
- // });
-
- // return () => sub?.unsubscribe();
- // }, [docSelectionRenderService?.onChangeByEvent$, document, highlight]);
-
useVerify(isFocus, onVerify, formulaText);
const focus = useFocus(editor);
@@ -242,7 +233,9 @@ export function FormulaEditor(props: IFormulaEditorProps) {
if (!isFocusing) {
return;
}
- highlight(`=${refString}`, true, isEnd, [{ startOffset: offset + 1, endOffset: offset + 1, collapsed: true }]);
+
+ const newSelections = offset !== -1 ? [{ startOffset: offset + 1, endOffset: offset + 1, collapsed: true }] : undefined;
+ highlight(`=${refString}`, true, isEnd, newSelections);
if (isEnd) {
focus();
if (offset !== -1) {