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-ui): editing issues on formula-bar (#5027)

ZhangWei02d945dd9157
diff --git a/packages/core/src/docs/data-model/document-data-model.ts b/packages/core/src/docs/data-model/document-data-model.ts
index 59a7ca091b..f8d13cb4e3 100644
--- a/packages/core/src/docs/data-model/document-data-model.ts
+++ b/packages/core/src/docs/data-model/document-data-model.ts
@@ -15,19 +15,13 @@
*/
import type { Nullable } from '../../shared';
-import type {
- IDocumentBody,
- IDocumentData,
- IDocumentRenderConfig,
- IDocumentStyle,
- IDrawings,
- IListData,
-} from '../../types/interfaces/i-document-data';
+import type { IDocumentBody, IDocumentData, IDocumentRenderConfig, IDocumentStyle, IDrawings, IListData } from '../../types/interfaces/i-document-data';
import type { IPaddingData } from '../../types/interfaces/i-style-data';
import type { JSONXActions } from './json-x/json-x';
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../../common/unit';
import { Tools } from '../../shared/tools';
+
import { getEmptySnapshot } from './empty-snapshot';
import { JSONX } from './json-x/json-x';
import { PRESET_LIST_TYPE } from './preset-list-type';
diff --git a/packages/design/src/components/form-layout/index.module.less b/packages/design/src/components/form-layout/index.module.less
index e7f7f29a1e..ea071574c6 100644
--- a/packages/design/src/components/form-layout/index.module.less
+++ b/packages/design/src/components/form-layout/index.module.less
@@ -1,12 +1,7 @@
.form-layout {
display: flex;
flex-direction: column;
-
- .form-layout-inner {
- .form-layout-content {
- margin-bottom: 0;
- }
- }
+ margin-bottom: var(--margin-sm);
&-label {
font-size: var(--font-size-sm);
@@ -24,8 +19,6 @@
}
&-content {
- margin-bottom: var(--margin-sm);
-
.input-affix-wrapper {
width: 100%;
}
@@ -37,6 +30,10 @@
.range-selector {
width: 100% !important;
}
+
+ :last-child {
+ margin-bottom: 0;
+ }
}
&-content-error {
diff --git a/packages/design/src/components/input/Input.tsx b/packages/design/src/components/input/Input.tsx
index c0160cc055..38f598d8f7 100644
--- a/packages/design/src/components/input/Input.tsx
+++ b/packages/design/src/components/input/Input.tsx
@@ -56,6 +56,8 @@ export interface IInputProps extends Pick<InputProps, 'onFocus' | 'onBlur'>,
onClick?: (e: React.MouseEvent<HTMLInputElement>) => void;
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
onChange?: (value: string) => void;
+ inputClass?: string;
+ inputStyle?: React.CSSProperties;
}
export const Input = forwardRef<HTMLInputElement, IInputProps>(
@@ -74,6 +76,8 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
onChange,
onFocus,
onBlur,
+ inputClass,
+ inputStyle,
...props
}, ref) => {
const handleClear = (e: React.MouseEvent) => {
@@ -100,7 +104,8 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
className={clsx(
inputVariants({ size }),
disabled && 'univer-cursor-not-allowed univer-bg-gray-50',
- allowClear && 'univer-pr-8'
+ allowClear && 'univer-pr-8',
+ inputClass
)}
placeholder={placeholder}
value={value}
@@ -111,6 +116,7 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
onChange={handleChange}
onFocus={onFocus}
onBlur={onBlur}
+ style={inputStyle}
{...props}
/>
{allowClear && value && !disabled && (
diff --git a/packages/docs-ui/src/services/editor/editor-manager.service.ts b/packages/docs-ui/src/services/editor/editor-manager.service.ts
index e5a088a036..973388220a 100644
--- a/packages/docs-ui/src/services/editor/editor-manager.service.ts
+++ b/packages/docs-ui/src/services/editor/editor-manager.service.ts
@@ -18,7 +18,7 @@ import type { DocumentDataModel, IDisposable, IDocumentBody, IDocumentData, Null
import type { ISuccinctDocRangeParam, Scene } from '@univerjs/engine-render';
import type { Observable } from 'rxjs';
import type { IEditorConfigParams } from './editor';
-import { createIdentifier, DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_STANDALONE, HorizontalAlign, ICommandService, IContextService, Inject, isInternalEditorID, IUndoRedoService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';
+import { createIdentifier, DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, EDITOR_ACTIVATED, FOCUSING_EDITOR_STANDALONE, HorizontalAlign, ICommandService, IContextService, Inject, Injector, isInternalEditorID, IUndoRedoService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { IRenderManagerService } from '@univerjs/engine-render';
import { fromEvent, Subject } from 'rxjs';
@@ -83,7 +83,8 @@ export class EditorService extends Disposable implements IEditorService, IDispos
@Inject(DocSelectionManagerService) private readonly _docSelectionManagerService: DocSelectionManagerService,
@IContextService private readonly _contextService: IContextService,
@ICommandService private readonly _commandService: ICommandService,
- @IUndoRedoService private readonly _undoRedoService: IUndoRedoService
+ @IUndoRedoService private readonly _undoRedoService: IUndoRedoService,
+ @Inject(Injector) private readonly _injector: Injector
) {
super();
@@ -222,7 +223,8 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this._univerInstanceService,
this._docSelectionManagerService,
this._commandService,
- this._undoRedoService
+ this._undoRedoService,
+ this._injector
);
this._editors.set(editorUnitId, editor);
diff --git a/packages/docs-ui/src/services/editor/editor.ts b/packages/docs-ui/src/services/editor/editor.ts
index f0645ec374..5c71e91633 100644
--- a/packages/docs-ui/src/services/editor/editor.ts
+++ b/packages/docs-ui/src/services/editor/editor.ts
@@ -14,12 +14,14 @@
* limitations under the License.
*/
-import type { DocumentDataModel, ICommandService, IDocumentData, IDocumentStyle, IPosition, IUndoRedoService, IUniverInstanceService, Nullable } from '@univerjs/core';
+import type { DocumentDataModel, ICommandService, IDocumentData, IDocumentStyle, Injector, IPosition, IUndoRedoService, IUniverInstanceService, Nullable } from '@univerjs/core';
import type { DocSelectionManagerService } from '@univerjs/docs';
import type { IDocSelectionInnerParam, IRender, ISuccinctDocRangeParam, ITextRangeWithStyle } from '@univerjs/engine-render';
import type { Observable } from 'rxjs';
import type { IEditorInputConfig } from '../selection/doc-selection-render.service';
import { Disposable, isInternalEditorID, UniverInstanceType } from '@univerjs/core';
+import { DocSkeletonManagerService } from '@univerjs/docs';
+import { IRenderManagerService } from '@univerjs/engine-render';
import { KeyCode } from '@univerjs/ui';
import { merge, Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
@@ -138,7 +140,8 @@ export class Editor extends Disposable implements IEditor {
private _univerInstanceService: IUniverInstanceService,
private _docSelectionManagerService: DocSelectionManagerService,
private _commandService: ICommandService,
- private _undoRedoService: IUndoRedoService
+ private _undoRedoService: IUndoRedoService,
+ private _injector: Injector
) {
super();
@@ -243,19 +246,6 @@ export class Editor extends Disposable implements IEditor {
// Step 2: Focus this input element.
const docSelectionRenderService = this._param.render.with(DocSelectionRenderService);
docSelectionRenderService.focus();
-
- // Step 3: Sets the selection of the last selection, and if not, to the beginning of the document.
- // const lastSelectionInfo = this._docSelectionManagerService.getDocRanges({
- // unitId: editorUnitId,
- // subUnitId: editorUnitId,
- // });
-
- // if (lastSelectionInfo) {
- // this._docSelectionManagerService.replaceDocRanges(lastSelectionInfo, {
- // unitId: editorUnitId,
- // subUnitId: editorUnitId,
- // }, false);
- // }
}
/**
@@ -412,6 +402,11 @@ export class Editor extends Disposable implements IEditor {
return this._param.visible;
}
+ getSkeleton() {
+ const skeleton = this._injector.get(IRenderManagerService).getRenderById(this._getEditorId())?.with(DocSkeletonManagerService).getSkeleton();
+ return skeleton;
+ }
+
isSheetEditor() {
return isInternalEditorID(this._getEditorId());
}
diff --git a/packages/sheets-data-validation-ui/src/views/components/detail/index.tsx b/packages/sheets-data-validation-ui/src/views/components/detail/index.tsx
index 01f58c3644..9d7361bb87 100644
--- a/packages/sheets-data-validation-ui/src/views/components/detail/index.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/detail/index.tsx
@@ -45,6 +45,7 @@ function getSheetIdByName(univerInstanceService: IUniverInstanceService, unitId:
}
return univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetName(name)?.getSheetId() || '';
}
+
export function DataValidationDetail() {
const [key, setKey] = useState(0);
const dataValidationPanelService = useDependency(DataValidationPanelService);
@@ -246,7 +247,7 @@ export function DataValidationDetail() {
);
};
- const shouldHideFormula = !localRule.operator;
+ const shouldHideFormula = operators.length && !localRule.operator;
return (
<div className={styles.dataValidationDetail}>
diff --git a/packages/sheets-data-validation-ui/src/views/components/formula-input/list-formula-input.tsx b/packages/sheets-data-validation-ui/src/views/components/formula-input/list-formula-input.tsx
index 885f261b9d..5db613410d 100644
--- a/packages/sheets-data-validation-ui/src/views/components/formula-input/list-formula-input.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/formula-input/list-formula-input.tsx
@@ -137,6 +137,7 @@ const Template = (props: { item: IDropdownItem; commonProps: any; style?: CSSPro
onChange={(label) => {
onItemChange(item.id, label, item.color);
}}
+ inputStyle={{ height: 28 }}
/>
{item.isRef
? null
@@ -152,7 +153,6 @@ const Template = (props: { item: IDropdownItem; commonProps: any; style?: CSSPro
export function ListFormulaInput(props: IFormulaInputProps) {
const { value, onChange: _onChange = () => { /* empty */ }, unitId, subUnitId, validResult, showError, ruleId } = props;
const { formula1 = '', formula2 = '' } = value || {};
- const containerRef = useRef<HTMLDivElement>(null);
const [isFormulaStr, setIsFormulaStr] = useState(() => isFormulaString(formula1) ? '1' : '0');
const [formulaStr, setFormulaStr] = useState(isFormulaStr === '1' ? formula1 : '=');
const [formulaStrCopy, setFormulaStrCopy] = useState(isFormulaStr === '1' ? formula1 : '=');
@@ -355,20 +355,29 @@ export function ListFormulaInput(props: IFormulaInputProps) {
isSupportAcrossSheet
ref={formulaEditorRef}
/>
- <div ref={containerRef} style={{ marginTop: '12px' }}>
- {refFinalList.map((item) => {
- return <Template key={item.id} item={item} commonProps={{ onItemChange: handleRefItemChange }} style={{ marginBottom: 12 }} />;
- })}
- </div>
+ {refFinalList.length > 0 && (
+ <div style={{ marginTop: '12px' }}>
+ {refFinalList.map((item) => {
+ return (
+ <Template
+ key={item.id}
+ item={item}
+ commonProps={{ onItemChange: handleRefItemChange }}
+ style={{ marginBottom: 12 }}
+ />
+ );
+ })}
+ </div>
+ )}
</>
)
: (
<FormLayout error={formula1Res}>
- <div ref={containerRef} style={{ marginTop: '-12px' }}>
+ <div style={{ marginTop: '-12px' }}>
<DraggableList
list={strList}
onListChange={setStrList}
- rowHeight={32}
+ rowHeight={28}
margin={[0, 12]}
draggableHandle=".draggableHandle"
itemRender={(item) => (
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
index 520e738c2a..c4a14d62ca 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx
@@ -18,12 +18,14 @@ import type { Editor } from '@univerjs/docs-ui';
import type { IFunctionParam } from '@univerjs/engine-formula';
import { LocaleService } from '@univerjs/core';
import { CloseSingle, MoreSingle } from '@univerjs/icons';
-import { RectPopup, useDependency } from '@univerjs/ui';
+import { IEditorBridgeService } from '@univerjs/sheets-ui';
+import { RectPopup, useDependency, useEvent, useObservable } from '@univerjs/ui';
import React, { useMemo, useState } from 'react';
import { generateParam } from '../../../services/utils';
import { useEditorPosition } from '../hooks/use-editor-position';
import { useFormulaDescribe } from '../hooks/use-formula-describe';
+import { HelpHiddenTip } from './help-hidden-tip';
import styles from './index.module.less';
interface IParamsProps {
@@ -34,10 +36,11 @@ interface IParamsProps {
const Params = ({ className, title, value }: IParamsProps) => (
<div className={styles.formulaHelpFunctionContentParams}>
- <div className={`
- ${styles.formulaHelpFunctionContentParamsTitle}
- ${className}
- `}
+ <div
+ className={`
+ ${styles.formulaHelpFunctionContentParamsTitle}
+ ${className}
+ `}
>
{title}
</div>
@@ -90,6 +93,8 @@ export function HelpFunction(props: IHelpFunctionProps) {
const { onParamsSwitch = noop, onClose: propColose = noop, isFocus, editor, formulaText } = props;
const { functionInfo, paramIndex, reset } = useFormulaDescribe(isFocus, formulaText, editor);
const visible = useMemo(() => !!functionInfo && paramIndex >= 0, [functionInfo, paramIndex]);
+ const editorBridgeService = useDependency(IEditorBridgeService);
+ const hidden = !useObservable(editorBridgeService.helpFunctionVisible$);
const [contentVisible, setContentVisible] = useState(true);
const localeService = useDependency(LocaleService);
const required = localeService.t('formula.prompt.required');
@@ -100,57 +105,67 @@ export function HelpFunction(props: IHelpFunctionProps) {
onParamsSwitch && onParamsSwitch(paramIndex);
}
+ const setHidden = useEvent((v: boolean) => {
+ editorBridgeService.helpFunctionVisible$.next(!v);
+ });
+
const onClose = () => {
- reset();
+ setHidden(true);
propColose();
};
return visible && functionInfo
- ? (
- <RectPopup portal onClickOutside={() => reset()} anchorRect$={position$} direction="vertical">
- <div className={styles.formulaHelpFunction}>
- <div className={styles.formulaHelpFunctionTitle}>
- <Help
- prefix={functionInfo.functionName}
- value={functionInfo.functionParameter}
- active={paramIndex}
- onClick={handleSwitchActive}
- />
- <div className={styles.formulaHelpFunctionTitleIcons}>
- <div
- className={styles.formulaHelpFunctionTitleIcon}
- style={{ transform: contentVisible ? 'rotateZ(-90deg)' : 'rotateZ(90deg)' }}
- onClick={() => setContentVisible(!contentVisible)}
- >
- <MoreSingle />
- </div>
- <div
- className={styles.formulaHelpFunctionTitleIcon}
- onClick={onClose}
- >
- <CloseSingle />
+ ? hidden
+ ? (
+ <RectPopup key="hidden" portal anchorRect$={position$} direction="left-center">
+ <HelpHiddenTip onClick={() => setHidden(false)} />
+ </RectPopup>
+ )
+ : (
+ <RectPopup key="show" portal onClickOutside={() => reset()} anchorRect$={position$} direction="vertical">
+ <div className={styles.formulaHelpFunction}>
+ <div className={styles.formulaHelpFunctionTitle}>
+ <Help
+ prefix={functionInfo.functionName}
+ value={functionInfo.functionParameter}
+ active={paramIndex}
+ onClick={handleSwitchActive}
+ />
+ <div className={styles.formulaHelpFunctionTitleIcons}>
+ <div
+ className={styles.formulaHelpFunctionTitleIcon}
+ style={{ transform: contentVisible ? 'rotateZ(-90deg)' : 'rotateZ(90deg)' }}
+ onClick={() => setContentVisible(!contentVisible)}
+ >
+ <MoreSingle />
+ </div>
+ <div
+ className={styles.formulaHelpFunctionTitleIcon}
+ onClick={onClose}
+ >
+ <CloseSingle />
+ </div>
</div>
</div>
- </div>
- <div
- className={styles.formulaHelpFunctionContent}
- style={{
- height: contentVisible ? 'unset' : 0,
- padding: contentVisible ? 'revert-layer' : 0,
- }}
- >
- <div className={styles.formulaHelpFunctionContentInner}>
- <Params
- title={localeService.t('formula.prompt.helpExample')}
- value={`${functionInfo.functionName}(${functionInfo.functionParameter
- .map((item) => item.example)
- .join(',')})`}
- />
- <Params
- title={localeService.t('formula.prompt.helpAbstract')}
- value={functionInfo.description}
- />
- {functionInfo &&
+ <div
+ className={styles.formulaHelpFunctionContent}
+ style={{
+ height: contentVisible ? 'unset' : 0,
+ padding: contentVisible ? 'revert-layer' : 0,
+ }}
+ >
+ <div className={styles.formulaHelpFunctionContentInner}>
+ <Params
+ title={localeService.t('formula.prompt.helpExample')}
+ value={`${functionInfo.functionName}(${functionInfo.functionParameter
+ .map((item) => item.example)
+ .join(',')})`}
+ />
+ <Params
+ title={localeService.t('formula.prompt.helpAbstract')}
+ value={functionInfo.description}
+ />
+ {functionInfo &&
functionInfo.functionParameter &&
functionInfo.functionParameter.map((item: IFunctionParam, i: number) => (
<Params
@@ -160,10 +175,10 @@ export function HelpFunction(props: IHelpFunctionProps) {
value={`${item.require ? required : optional} ${item.detail}`}
/>
))}
+ </div>
</div>
</div>
- </div>
- </RectPopup>
- )
+ </RectPopup>
+ )
: null;
}
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/help-hidden-tip.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/help-hidden-tip.tsx
new file mode 100644
index 0000000000..8d1585aac5
--- /dev/null
+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/help-hidden-tip.tsx
@@ -0,0 +1,31 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export const HelpHiddenTip = ({ onClick }: { onClick: () => void }) => {
+ return (
+ <div
+ className={`
+ univer-z-[15] univer-box-border univer-h-[18px] univer-cursor-pointer univer-overflow-visible
+ univer-whitespace-nowrap univer-rounded-l univer-border univer-border-r-0 univer-border-[#5790f6]
+ univer-bg-[#1a73e8] univer-p-0.5 univer-text-[11px] univer-font-bold univer-leading-[13px]
+ univer-text-white
+ `}
+ onClick={onClick}
+ >
+ ?
+ </div>
+ );
+};
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-editor-position.ts b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-editor-position.ts
index a981269a4b..4067506c6e 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-editor-position.ts
+++ b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-editor-position.ts
@@ -32,7 +32,14 @@ export function useEditorPosition(editorId: string, ready: boolean, deps?: any[]
return;
}
const position = doc.getBoundingClientRect();
- const { left, top, right, bottom } = position;
+ const { marginTop = 0, marginBottom = 0 } = doc.getDocumentData().documentStyle;
+ const skeleton = doc.getSkeleton();
+ if (!skeleton) return;
+ const height = skeleton.getSkeletonData()?.pages[0].height;
+ let { left, top, right, bottom } = position;
+ top = top + marginTop;
+ bottom = height ? top + height : bottom - marginBottom;
+
const current = position$.getValue();
if (current.left === left && current.top === top && current.right === right && current.bottom === bottom) {
return;
@@ -46,7 +53,6 @@ export function useEditorPosition(editorId: string, ready: boolean, deps?: any[]
return;
}
updatePosition();
- // eslint-disable-next-line react-hooks/exhaustive-deps
}, [editorId, editorService, univerInstanceService.unitAdded$, updatePosition, ready, ...(deps ?? [])]);
useResizeScrollObserver(updatePosition);
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-focus.ts b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-focus.ts
index c828249c35..917cfc0a2a 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-focus.ts
+++ b/packages/sheets-formula-ui/src/views/formula-editor/hooks/use-focus.ts
@@ -31,6 +31,8 @@ export const useFocus = (editor?: Editor) => {
const body = editor.getDocumentData().body?.dataStream ?? '\r\n';
const offset = Math.max(body.length - 2, 0);
editor.setSelectionRanges([{ startOffset: offset, endOffset: offset }]);
+ } else {
+ editor.setSelectionRanges(selections);
}
};
});
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 464da3cf87..e672e3a33c 100644
--- a/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
+++ b/packages/sheets-formula-ui/src/views/formula-editor/index.tsx
@@ -58,7 +58,7 @@ export interface IFormulaEditorProps {
className?: string;
editorId?: string;
moveCursor?: boolean;
- onFormulaSelectingChange?: (isSelecting: FormulaSelectingType) => void;
+ onFormulaSelectingChange?: (isSelecting: FormulaSelectingType, isFocusing: boolean) => void;
keyboradEventConfig?: IKeyboardEventConfig;
onMoveInEditor?: (keyCode: KeyCode, metaKey?: MetaKeys) => void;
resetSelectionOnBlur?: boolean;
@@ -203,7 +203,7 @@ export const FormulaEditor = forwardRef((props: IFormulaEditorProps, ref: Ref<IF
const resetSelection = useResetSelection(isFocus, unitId, subUnitId);
useEffect(() => {
- onFormulaSelectingChange(isSelecting);
+ onFormulaSelectingChange(isSelecting, docSelectionRenderService?.isFocusing ?? true);
}, [onFormulaSelectingChange, isSelecting]);
useKeyboardEvent(isFocus, keyboradEventConfig, editor);
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index 9235370cad..a3fa969c2d 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -490,6 +490,18 @@ export class EditingRenderController extends Disposable {
this._renderManagerService.getRenderById(unitId)?.scene.resetCursor();
}
+ private _refreshCurrentSelections(sheetId: string) {
+ const selections = this._workbookSelections.getSelectionsOfWorksheet(sheetId);
+ if (selections) {
+ this._contextService.setContextValue(REF_SELECTIONS_ENABLED, false);
+ this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {
+ unitId: this._editingUnit,
+ subUnitId: sheetId,
+ selections,
+ });
+ }
+ }
+
private async _handleEditorInvisible(param: IEditorBridgeServiceVisibleParam) {
const editCellState = this._editorBridgeService.getEditCellState();
const documentDataModel = this._univerInstanceService.getUnit<DocumentDataModel>(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
@@ -529,7 +541,7 @@ export class EditingRenderController extends Disposable {
if (this._editorBridgeService.isForceKeepVisible()) {
this._editorBridgeService.disableForceKeepVisible();
}
- this._moveSelection(keycode, currentUnitId);
+ this._moveSelection(keycode, currentUnitId, worksheetId);
return;
}
@@ -538,17 +550,7 @@ export class EditingRenderController extends Disposable {
if (this._editorBridgeService.isForceKeepVisible()) {
this._editorBridgeService.disableForceKeepVisible();
}
-
- const selections = this._workbookSelections.getCurrentSelections();
- if (selections) {
- this._contextService.setContextValue(REF_SELECTIONS_ENABLED, false);
- this._commandService.syncExecuteCommand(SetSelectionsOperation.id, {
- unitId: workbookId,
- subUnitId: sheetId,
- selections,
- });
- }
-
+ this._refreshCurrentSelections(sheetId);
return;
}
@@ -563,7 +565,7 @@ export class EditingRenderController extends Disposable {
}
// moveSelection need to put behind of SetRangeValuesCommand, fix https://github.com/dream-num/univer/issues/1155
- this._moveSelection(keycode, currentUnitId);
+ this._moveSelection(keycode, currentUnitId, worksheetId);
}
private _getEditorObject() {
@@ -670,8 +672,9 @@ export class EditingRenderController extends Disposable {
this._undoRedoService.clearUndoRedo(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);
}
- private _moveSelection(keycode: KeyCode | undefined, currentUnitId: string) {
+ private _moveSelection(keycode: KeyCode | undefined, currentUnitId: string, worksheetId: string) {
if (keycode == null || !MOVE_SELECTION_KEYCODE_LIST.includes(keycode)) {
+ this._refreshCurrentSelections(worksheetId);
return;
}
diff --git a/packages/sheets-ui/src/services/editor-bridge.service.ts b/packages/sheets-ui/src/services/editor-bridge.service.ts
index 33ad2542f5..e62d12687f 100644
--- a/packages/sheets-ui/src/services/editor-bridge.service.ts
+++ b/packages/sheets-ui/src/services/editor-bridge.service.ts
@@ -106,13 +106,13 @@ export interface IEditorBridgeService {
disableForceKeepVisible(): void;
isForceKeepVisible(): boolean;
getCurrentEditorId(): Nullable<string>;
+ helpFunctionVisible$: BehaviorSubject<boolean>;
}
export class EditorBridgeService extends Disposable implements IEditorBridgeService, IDisposable {
private _editorUnitId: string = DOCS_NORMAL_EDITOR_UNIT_ID_KEY;
private _editorIsDirty: boolean = false;
- private _isDisabled: boolean = false;
private _visibleParams: IEditorBridgeServiceVisibleParam = {
visible: false,
eventType: DeviceInputEventType.Dblclick,
@@ -123,6 +123,8 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
private _currentEditCellState: Nullable<ICellEditorState> = null;
private _currentEditCellLayout: Nullable<ICellEditorLayout> = null;
+ helpFunctionVisible$ = new BehaviorSubject(true);
+
// TODO: @weird94 this should split into to subjects, documentDataModel & position
private readonly _currentEditCellState$ = new BehaviorSubject<Nullable<ICellEditorState>>(null);
readonly currentEditCellState$ = this._currentEditCellState$.asObservable();
diff --git a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
index 268c545e05..e5d3fa6845 100644
--- a/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
+++ b/packages/sheets-ui/src/views/editor-container/EditorContainer.tsx
@@ -161,8 +161,9 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {
resetSelectionOnBlur={false}
isSingle={false}
autoScrollbar={false}
- onFormulaSelectingChange={(isSelecting: 0 | 1 | 2) => {
+ onFormulaSelectingChange={(isSelecting: 0 | 1 | 2, isFocusing: boolean) => {
isRefSelecting.current = isSelecting;
+ if (!isFocusing) return;
if (isSelecting) {
editorBridgeService.enableForceKeepVisible();
} else {
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index 48a63510b5..10e1fc32c4 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -309,8 +309,9 @@ export function FormulaBar(props: IProps) {
resetSelectionOnBlur={false}
isSingle={false}
keyboradEventConfig={keyCodeConfig}
- onFormulaSelectingChange={(isSelecting: 0 | 1 | 2) => {
+ onFormulaSelectingChange={(isSelecting: 0 | 1 | 2, isFocusing: boolean) => {
isRefSelecting.current = isSelecting;
+ if (!isFocusing) return;
if (isSelecting) {
editorBridgeService.enableForceKeepVisible();
} else {
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index f8971fc1ba..f3148871a4 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -22,7 +22,7 @@ export { mergeMenuConfigs } from './common/menu-merge-configs';
export * from './components';
export { t } from './components/hooks/locale';
export * from './components/hooks';
-export { RectPopup } from './views/components/popup/RectPopup';
+export { RectPopup, type RectPopupDirection } from './views/components/popup/RectPopup';
export { Menu as UIMenu } from './components/menu/desktop/Menu';
export { type INotificationOptions, type NotificationType } from './components/notification/Notification';
export { ProgressBar } from './components/progress-bar/ProgressBar';
diff --git a/packages/ui/src/views/components/popup/RectPopup.tsx b/packages/ui/src/views/components/popup/RectPopup.tsx
index 766d4faed6..1fede87aaa 100644
--- a/packages/ui/src/views/components/popup/RectPopup.tsx
+++ b/packages/ui/src/views/components/popup/RectPopup.tsx
@@ -34,6 +34,32 @@ interface IAbsolutePosition {
const RectPopupContext = createContext<RefObject<IAbsolutePosition | undefined>>({ current: undefined });
+export type RectPopupDirection =
+ | 'left'
+ | 'left-center'
+ | 'left-bottom'
+ | 'left-top'
+ | 'right'
+ | 'right-center'
+ | 'right-bottom'
+ | 'right-top'
+ | 'top'
+ | 'top-center'
+ | 'top-left'
+ | 'top-right'
+ | 'bottom'
+ | 'bottom-center'
+ | 'bottom-left'
+ | 'bottom-right'
+ | 'vertical'
+ | 'vertical-left'
+ | 'vertical-right'
+ | 'vertical-center'
+ | 'horizontal'
+ | 'horizontal-top'
+ | 'horizontal-bottom'
+ | 'horizontal-center';
+
export interface IRectPopupProps {
children?: React.ReactNode;
@@ -42,8 +68,7 @@ export interface IRectPopupProps {
*/
anchorRect$: Observable<IAbsolutePosition>;
excludeRects?: RefObject<Nullable<IAbsolutePosition[]>>;
- direction?: 'vertical' | 'horizontal' | 'top' | 'right' | 'left' | 'right-center' | 'left-center' | 'bottom' | 'bottom-center' | 'top-center';
-
+ direction?: RectPopupDirection;
hidden?: boolean;
// #region closing behavior
onClickOutside?: (e: MouseEvent) => void;
@@ -77,7 +102,7 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe
const { position, width, height, containerHeight, containerWidth, direction = 'vertical' } = layout;
// In y-axis
- if (direction === 'vertical' || direction.includes('top') || direction.includes('bottom')) {
+ if (direction === 'vertical' || direction.indexOf('top') === 0 || direction.indexOf('bottom') === 0) {
const { left: startX, top: startY, right: endX, bottom: endY } = position;
const verticalStyle = (direction === 'vertical' && endY > containerHeight - height - PUSHING_MINIMUM_GAP) || direction.indexOf('top') > -1
// top
@@ -97,6 +122,10 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe
horizontalStyle = (Math.max(startX + offsetX, PUSHING_MINIMUM_GAP) + width) > containerWidth
? { left: Math.max(Math.min(maxLeft, endX - width - offsetX), minLeft) }
: { left: Math.max(minLeft, Math.min(startX + offsetX, maxLeft)) };
+ } else if (direction.includes('left')) {
+ horizontalStyle = { left: Math.max(endX - width, minLeft) };
+ } else if (direction.includes('right')) {
+ horizontalStyle = { left: Math.min(startX, maxLeft) };
} else {
// If the popup element exceed the visible area. We should "push" it back.
horizontalStyle = (startX + width) > containerWidth
@@ -113,6 +142,7 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe
const horizontalStyle = direction.includes('left')
? { left: Math.max(startX - width, PUSHING_MINIMUM_GAP) } // on left
: { left: Math.min(endX, containerWidth - width - PUSHING_MINIMUM_GAP) }; // on right
+
let verticalStyle;
const minTop = PUSHING_MINIMUM_GAP;
const maxTop = containerHeight - height - PUSHING_MINIMUM_GAP;
@@ -124,6 +154,14 @@ function calcPopupPosition(layout: IPopupLayoutInfo): { top: number; left: numbe
verticalStyle = (Math.max(startY + offsetY, PUSHING_MINIMUM_GAP) + height) > containerHeight
? { top: Math.max(Math.min(maxTop, endY - height - offsetY), minTop) }
: { top: Math.max(minTop, Math.min(startY + offsetY, maxTop)) };
+ } else if (direction.includes('top')) {
+ verticalStyle = {
+ top: Math.min(startY, containerHeight - height - PUSHING_MINIMUM_GAP),
+ };
+ } else if (direction.includes('bottom')) {
+ verticalStyle = {
+ top: Math.max(endY - height, PUSHING_MINIMUM_GAP),
+ };
} else {
// If the popup element exceed the visible area. We should "push" it back.
verticalStyle = ((startY + height) > containerHeight)