From 972b4b4d10db051c94d64a1cba80d2098a546e76 Mon Sep 17 00:00:00 2001 From: zhangw Date: Sat, 18 Jan 2025 18:37:39 +0800 Subject: [PATCH 1/2] fix: ime input move cursor --- .../services/selection/doc-selection-render.service.ts | 4 ++++ .../src/controllers/editor/editing.render-controller.ts | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts index ea42567989a7..3e67fc687aa4 100644 --- a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts +++ b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts @@ -109,6 +109,10 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMo // When the user switches editors, whether to clear the doc ranges. private _reserveRanges = false; + get isIMEInputing() { + return this._isIMEInputApply; + } + get isOnPointerEvent() { return this._onPointerEvent; } 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 a2ad9d4c93e4..14abfd9a1d29 100644 --- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts +++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts @@ -327,13 +327,19 @@ export class EditingRenderController extends Disposable implements IRenderModule const params = command.params as IEditorBridgeServiceVisibleParam & { isShift: boolean }; const { keycode, isShift } = params; + const docSelectionRenderManager = this._renderManagerService.getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY)?.with(DocSelectionRenderService); + /** * After the user enters the editor and actively moves the editor selection area with the mouse, * the up, down, left, and right keys can no longer switch editing cells, * but move the cursor within the editor instead. */ if (keycode != null && - (this._cursorChange === CursorChange.CursorChange || this._contextService.getContextValue(FOCUSING_FX_BAR_EDITOR)) + ( + this._cursorChange === CursorChange.CursorChange || + this._contextService.getContextValue(FOCUSING_FX_BAR_EDITOR) || + docSelectionRenderManager?.isIMEInputing + ) ) { this._moveInEditor(keycode, isShift); return; From a0969fe598aab902a8c463abfc2b8d5220e0326d Mon Sep 17 00:00:00 2001 From: zhangw Date: Mon, 20 Jan 2025 01:24:44 +0800 Subject: [PATCH 2/2] feat: support shift+delete --- .../src/controllers/sheet-ui.controller.ts | 4 +++- .../controllers/shortcuts/value.shortcut.ts | 21 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts index fa288ca6e92e..15dc847ecb46 100644 --- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts +++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts @@ -150,7 +150,7 @@ import { SetStrikeThroughShortcutItem, SetUnderlineShortcutItem, } from './shortcuts/style.shortcut'; -import { ClearSelectionValueShortcutItem } from './shortcuts/value.shortcut'; +import { AltClearSelectionValueShortcutItem, ClearSelectionValueShortcutItem, ShiftClearSelectionValueShortcutItem } from './shortcuts/value.shortcut'; import { PreventDefaultResetZoomShortcutItem, PreventDefaultZoomInShortcutItem, @@ -326,6 +326,8 @@ export class SheetUIController extends Disposable { // cell content editing shortcuts ClearSelectionValueShortcutItem, + ShiftClearSelectionValueShortcutItem, + AltClearSelectionValueShortcutItem, ...generateArrowSelectionShortCutItem(), EditorCursorEnterShortcut, StartEditWithF2Shortcut, diff --git a/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts b/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts index c874382109e6..66e2c740e70a 100644 --- a/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts +++ b/packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { ClearSelectionContentCommand } from '@univerjs/sheets'; import type { IShortcutItem } from '@univerjs/ui'; -import { KeyCode } from '@univerjs/ui'; +import { ClearSelectionContentCommand } from '@univerjs/sheets'; +import { KeyCode, MetaKeys } from '@univerjs/ui'; import { whenSheetEditorFocused } from './utils'; @@ -27,3 +27,20 @@ export const ClearSelectionValueShortcutItem: IShortcutItem = { binding: KeyCode.DELETE, mac: KeyCode.BACKSPACE, }; + +export const ShiftClearSelectionValueShortcutItem: IShortcutItem = { + id: ClearSelectionContentCommand.id, + // when focusing on any other input tag do not trigger this shortcut + preconditions: (contextService) => whenSheetEditorFocused(contextService), + binding: MetaKeys.SHIFT + KeyCode.DELETE, + mac: MetaKeys.SHIFT + KeyCode.BACKSPACE, +}; + +export const AltClearSelectionValueShortcutItem: IShortcutItem = { + id: ClearSelectionContentCommand.id, + // when focusing on any other input tag do not trigger this shortcut + preconditions: (contextService) => whenSheetEditorFocused(contextService), + binding: MetaKeys.ALT + KeyCode.DELETE, + mac: MetaKeys.ALT + KeyCode.BACKSPACE, +}; +