Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheets-ui): ime input move cursor #4521

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/sheets-ui/src/controllers/sheet-ui.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -326,6 +326,8 @@ export class SheetUIController extends Disposable {

// cell content editing shortcuts
ClearSelectionValueShortcutItem,
ShiftClearSelectionValueShortcutItem,
AltClearSelectionValueShortcutItem,
...generateArrowSelectionShortCutItem(),
EditorCursorEnterShortcut,
StartEditWithF2Shortcut,
Expand Down
21 changes: 19 additions & 2 deletions packages/sheets-ui/src/controllers/shortcuts/value.shortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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),
Copy link
Member

@wzhudev wzhudev Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
preconditions: (contextService) => whenSheetEditorFocused(contextService),
preconditions: whenSheetEditorFocused,

There is no need to wrap in another anonymous arrow function.

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,
};

Loading