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(editor): fix the wrong position of validate messages on initialization when the sidebar is open (#2676)

白熱749dd74ba602
diff --git a/packages/debugger/src/commands/operations/sidebar.operation.ts b/packages/debugger/src/commands/operations/sidebar.operation.ts
index 1fde407d81..273d17a12c 100644
--- a/packages/debugger/src/commands/operations/sidebar.operation.ts
+++ b/packages/debugger/src/commands/operations/sidebar.operation.ts
@@ -37,8 +37,8 @@ export const SidebarOperation: ICommand = {
editorService.setOperationSheetUnitId(unit.getUnitId());
editorService.setOperationSheetSubUnitId(unit.getActiveSheet()?.getSheetId());
sidebarService.open({
- header: { title: 'debugger.sidebar.title' },
- children: { title: 'Sidebar Content', label: TEST_EDITOR_CONTAINER_COMPONENT },
+ header: { title: 'Sidebar title' },
+ children: { label: TEST_EDITOR_CONTAINER_COMPONENT },
footer: { title: 'Sidebar Footer' },
onClose: () => {
editorService.setOperationSheetUnitId(null);
diff --git a/packages/debugger/src/views/test-editor/TestTextEditor.tsx b/packages/debugger/src/views/test-editor/TestTextEditor.tsx
index da9c97e478..90f09bf448 100644
--- a/packages/debugger/src/views/test-editor/TestTextEditor.tsx
+++ b/packages/debugger/src/views/test-editor/TestTextEditor.tsx
@@ -22,14 +22,6 @@ import { createInternalEditorID, IUniverInstanceService, UniverInstanceType } fr
import { useDependency } from '@wendellhu/redi/react-bindings';
import { Input } from '@univerjs/design';
-const containerStyle: React.CSSProperties = {
- position: 'absolute',
- left: '10px',
- top: '300px',
- width: 'calc(100% - 20px)',
- height: 'calc(100% - 300px)',
-};
-
const editorStyle: React.CSSProperties = {
width: '100%',
};
@@ -52,9 +44,7 @@ export const TestEditorContainer = () => {
const [readonly, setReadonly] = useState(false);
return (
- <div
- style={containerStyle}
- >
+ <div>
<TextEditor id={createInternalEditorID('test-editor-1')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} style={editorStyle} canvasStyle={{ fontSize: 10 }} value="I found one cent on the roadside." />
<br></br>
<TextEditor id={createInternalEditorID('test-editor-2')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} onlyInputFormula={true} style={editorStyle} canvasStyle={{ fontSize: 10 }} />
diff --git a/packages/ui/src/components/editor/TextEditor.tsx b/packages/ui/src/components/editor/TextEditor.tsx
index 30fb92987c..759f9159b7 100644
--- a/packages/ui/src/components/editor/TextEditor.tsx
+++ b/packages/ui/src/components/editor/TextEditor.tsx
@@ -187,6 +187,8 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
activeChange(state);
});
+ // !IMPORTANT: Set a delay of 160ms to ensure that the position is corrected after the sidebar animation ends @jikkai
+ const ANIMATION_DELAY = 160;
const valueChange = debounce((editor: Readonly<Editor>) => {
const unitId = editor.editorUnitId;
const isLegality = editorService.checkValueLegality(unitId);
@@ -203,7 +205,7 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
} else {
setValidationContent(localeService.t('textEditor.rangeError'));
}
- }, 100);
+ }, ANIMATION_DELAY);
const currentValue = editorService.getValue(unitId);