fix: fix comment editor behavior (#6251)

This commit is contained in:
Shiyun Hua
2025-12-10 11:28:11 +08:00
committed by GitHub
parent fa5bb4a5ac
commit 098dbf6c7a
6 changed files with 20 additions and 5 deletions
+6
View File
@@ -22,6 +22,8 @@ export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = `${PREFIX}DOCS_FORMULA_BAR`;
export const DOCS_ZEN_EDITOR_UNIT_ID_KEY = `${PREFIX}ZEN_EDITOR`;
export const DOCS_COMMENT_EDITOR_UNIT_ID_KEY = `${PREFIX}COMMENT_EDITOR`;
export const DEFAULT_EMPTY_DOCUMENT_VALUE = '\r\n';
export const IS_ROW_STYLE_PRECEDE_COLUMN_STYLE = 'isRowStylePrecedeColumnStyle';
@@ -35,3 +37,7 @@ export function createInternalEditorID(id: string) {
export function isInternalEditorID(id: string) {
return id.startsWith(PREFIX);
}
export function isCommentEditorID(id: string) {
return id === DOCS_COMMENT_EDITOR_UNIT_ID_KEY;
}
@@ -42,6 +42,9 @@ export const FOCUSING_UNIVER_EDITOR = 'FOCUSING_UNIVER_EDITOR';
export const FOCUSING_EDITOR_STANDALONE = 'FOCUSING_EDITOR_INPUT_FORMULA';
/** The focusing state of the comment editor. */
export const FOCUSING_COMMENT_EDITOR = 'FOCUSING_COMMENT_EDITOR';
/** The focusing state of the editor in side panel, such as Chart Editor Panel. */
export const FOCUSING_PANEL_EDITOR = 'FOCUSING_PANEL_EDITOR';
@@ -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, Injector, isInternalEditorID, IUndoRedoService, IUniverInstanceService, toDisposable, UniverInstanceType, VerticalAlign } from '@univerjs/core';
import { createIdentifier, DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, EDITOR_ACTIVATED, FOCUSING_COMMENT_EDITOR, FOCUSING_EDITOR_STANDALONE, HorizontalAlign, ICommandService, IContextService, Inject, Injector, isCommentEditorID, 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';
@@ -145,6 +145,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this._contextService.setContextValue(EDITOR_ACTIVATED, false);
this._contextService.setContextValue(FOCUSING_EDITOR_STANDALONE, false);
this._contextService.setContextValue(FOCUSING_COMMENT_EDITOR, false);
this._setFocusId(null);
this._blur$.next(null);
}
@@ -173,6 +174,10 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this._contextService.setContextValue(FOCUSING_EDITOR_STANDALONE, true);
}
if (isCommentEditorID(editorUnitId)) {
this._contextService.setContextValue(FOCUSING_COMMENT_EDITOR, true);
}
editor.focus();
this._setFocusId(editorUnitId);
@@ -72,7 +72,7 @@ export function useEditor(opts: IUseEditorProps) {
setEditor(editor);
if (autoFocus) {
editor.focus();
editorService.focus(editorId);
const end = (snapshot.body?.dataStream.length ?? 2) - 2;
editor.setSelectionRanges([{ startOffset: end, endOffset: end }]);
}
@@ -22,7 +22,7 @@ import type { IMoveColsCommandParams, IMoveRangeCommandParams, IMoveRowsCommandP
import type { IAutoFillCommandParams } from '../../commands/commands/auto-fill.command';
import type { ISheetPasteParams } from '../../commands/commands/clipboard.command';
import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
import { Disposable, DisposableCollection, FOCUSING_EDITOR_STANDALONE, ICommandService, IContextService, Inject, IPermissionService, IUniverInstanceService, LocaleService, Rectangle, UniverInstanceType } from '@univerjs/core';
import { Disposable, DisposableCollection, FOCUSING_COMMENT_EDITOR, FOCUSING_EDITOR_STANDALONE, ICommandService, IContextService, Inject, IPermissionService, IUniverInstanceService, LocaleService, Rectangle, UniverInstanceType } from '@univerjs/core';
import { IMEInputCommand, InsertCommand } from '@univerjs/docs-ui';
import { UnitAction } from '@univerjs/protocol';
import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, RangeProtectionPermissionViewPoint, RangeProtectionRuleModel, SetBackgroundColorCommand, SheetPermissionCheckController, WorkbookCopyPermission, WorkbookEditablePermission, WorksheetCopyPermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, WorksheetSetColumnStylePermission } from '@univerjs/sheets';
@@ -99,7 +99,7 @@ export class SheetPermissionCheckUIController extends Disposable {
switch (id) {
case InsertCommand.id:
case IMEInputCommand.id:
if (this._contextService.getContextValue(FOCUSING_EDITOR_STANDALONE) === true) {
if (this._contextService.getContextValue(FOCUSING_EDITOR_STANDALONE) === true || this._contextService.getContextValue(FOCUSING_COMMENT_EDITOR) === true) {
break;
}
permission = this._sheetPermissionCheckController.permissionCheckWithoutRange({
@@ -17,7 +17,7 @@
import type { IDocumentBody, IDocumentData, IUser } from '@univerjs/core';
import type { Editor, IKeyboardEventConfig } from '@univerjs/docs-ui';
import type { IThreadComment } from '@univerjs/thread-comment';
import { BuildTextUtils, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
import { BuildTextUtils, DOCS_COMMENT_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, ICommandService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
import { Button, clsx } from '@univerjs/design';
import { BreakLineCommand, IEditorService, RichTextEditor } from '@univerjs/docs-ui';
import { KeyCode, useDependency } from '@univerjs/ui';
@@ -115,6 +115,7 @@ export const ThreadCommentEditor = forwardRef<IThreadCommentEditorInstance, IThr
<RichTextEditor
className="univer-w-full"
editorRef={editor}
editorId={DOCS_COMMENT_EDITOR_UNIT_ID_KEY}
autoFocus={autoFocus}
keyboardEventConfig={keyboardEventConfig}
placeholder={localeService.t('threadCommentUI.editor.placeholder')}