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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(editor): support shortcut (#1513)
Univerb362e733bfe0
diff --git a/packages/sheets-formula/src/commands/operations/editor-formula.operation.ts b/packages/sheets-formula/src/commands/operations/editor-formula.operation.tsindex ad3b4b566c..5775712fbc 100644--- a/packages/sheets-formula/src/commands/operations/editor-formula.operation.ts+++ b/packages/sheets-formula/src/commands/operations/editor-formula.operation.ts@@ -25,6 +25,7 @@ export interface ISelectEditorFormulaOperationParam {eventType: DeviceInputEventType;keycode?: KeyCode;metaKey?: MetaKeys | typeof META_KEY_CTRL_AND_SHIFT;+ isSingleEditor?: boolean;}export const SelectEditorFormulaOperation: IOperation<ISelectEditorFormulaOperationParam> = {diff --git a/packages/sheets-formula/src/controllers/formula-ui.controller.ts b/packages/sheets-formula/src/controllers/formula-ui.controller.tsindex 00a60796e1..f24acf6a76 100644--- a/packages/sheets-formula/src/controllers/formula-ui.controller.ts+++ b/packages/sheets-formula/src/controllers/formula-ui.controller.ts@@ -38,6 +38,7 @@ import {promptSelectionShortcutItemCtrl,promptSelectionShortcutItemCtrlAndShift,promptSelectionShortcutItemShift,+ singleEditorPromptSelectionShortcutItem,} from './shortcuts/prompt.shortcut';@OnLifecycle(LifecycleStages.Ready, FormulaUIController)@@ -89,6 +90,7 @@ export class FormulaUIController extends Disposable {...promptSelectionShortcutItemShift(),...promptSelectionShortcutItemCtrl(),...promptSelectionShortcutItemCtrlAndShift(),+ ...singleEditorPromptSelectionShortcutItem(),ChangeRefToAbsoluteShortcut,].forEach((item) => {this.disposeWithMe(this._shortcutService.registerShortcut(item));diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.tsindex 27748ff5c7..7078fabf16 100644--- a/packages/sheets-formula/src/controllers/prompt.controller.ts+++ b/packages/sheets-formula/src/controllers/prompt.controller.ts@@ -1649,13 +1649,18 @@ export class PromptController extends Disposable {this._changeRefString();} else if (updateCommandList.includes(command.id)) {const params = command.params as ISelectEditorFormulaOperationParam;- const { keycode, metaKey } = params;+ const { keycode, metaKey, isSingleEditor = false } = params;if (keycode === KeyCode.ENTER) {if (this._formulaPromptService.isSearching()) {this._formulaPromptService.accept(true);return;}++ if (isSingleEditor === true) {+ return;+ }+this._editorBridgeService.changeVisible({visible: false,eventType: DeviceInputEventType.Keyboard,@@ -1671,6 +1676,11 @@ export class PromptController extends Disposable {this._formulaPromptService.accept(true);return;}++ if (isSingleEditor === true) {+ return;+ }+this._editorBridgeService.changeVisible({visible: false,eventType: DeviceInputEventType.Keyboard,@@ -1693,6 +1703,10 @@ export class PromptController extends Disposable {}}+ if (isSingleEditor === true) {+ return;+ }+if (this._arrowMoveActionState === ArrowMoveAction.moveCursor) {this._moveInEditor(keycode);return;diff --git a/packages/sheets-formula/src/controllers/shortcuts/prompt.shortcut.ts b/packages/sheets-formula/src/controllers/shortcuts/prompt.shortcut.tsindex 607dd070e3..870c8b9a79 100644--- a/packages/sheets-formula/src/controllers/shortcuts/prompt.shortcut.ts+++ b/packages/sheets-formula/src/controllers/shortcuts/prompt.shortcut.ts@@ -22,6 +22,7 @@ import { KeyCode, MetaKeys } from '@univerjs/ui';import { SelectEditorFormulaOperation } from '../../commands/operations/editor-formula.operation';import { ReferenceAbsoluteOperation } from '../../commands/operations/reference-absolute.operation';import { META_KEY_CTRL_AND_SHIFT } from '../../common/prompt';+import { whenEditorStandalone } from '../utils/utils';export const PROMPT_SELECTION_KEYCODE_ARROW_LIST = [KeyCode.ARROW_DOWN,@@ -104,3 +105,20 @@ export const ChangeRefToAbsoluteShortcut: IShortcutItem = {binding: KeyCode.F4,preconditions: (contextService) => whenFormulaEditorActivated(contextService),};++export function singleEditorPromptSelectionShortcutItem() {+ const shortcutList: IShortcutItem[] = [];+ for (const keycode of [KeyCode.ENTER, KeyCode.TAB, KeyCode.ARROW_DOWN, KeyCode.ARROW_UP]) {+ shortcutList.push({+ id: SelectEditorFormulaOperation.id,+ binding: keycode,+ preconditions: (contextService) => whenEditorStandalone(contextService),+ staticParameters: {+ eventType: DeviceInputEventType.Keyboard,+ keycode,+ isSingleEditor: true,+ },+ });+ }+ return shortcutList;+}diff --git a/packages/sheets-formula/src/controllers/utils/utils.ts b/packages/sheets-formula/src/controllers/utils/utils.tsnew file mode 100644index 0000000000..f5191c6b4e--- /dev/null+++ b/packages/sheets-formula/src/controllers/utils/utils.ts@@ -0,0 +1,26 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * 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.+ */++import type { IContextService } from '@univerjs/core';+import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_UNIVER_EDITOR_SINGLE_MODE } from '@univerjs/core';++export function whenEditorStandalone(contextService: IContextService) {+ return (+ contextService.getContextValue(FOCUSING_DOC) &&+ contextService.getContextValue(FOCUSING_UNIVER_EDITOR) &&+ contextService.getContextValue(FOCUSING_UNIVER_EDITOR_SINGLE_MODE)+ );+}