From c154161a95f736a6f0031c235a9cab1fc7941b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E7=86=B1?= Date: Fri, 17 Jul 2026 18:35:52 +0800 Subject: [PATCH] fix(docs-ui): auto-focus newly created documents (#7283) --- .../docs/data-model/document-data-model.ts | 2 +- packages/docs-ui/src/plugin.ts | 24 +++++++------------ .../src/engine/analysis/lexer-node.ts | 6 ++--- .../src/functions/logical/groupby/index.ts | 10 ++++---- packages/engine-render/src/basics/path2.ts | 4 ++-- .../__tests__/merge-interceptor.spec.ts | 12 +++++----- .../src/views/panel/rule-edit/IconSet.tsx | 2 +- .../context-menu/ContextMenuPanel.tsx | 2 +- 8 files changed, 27 insertions(+), 35 deletions(-) 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 44853ced55..d5e0d9298a 100644 --- a/packages/core/src/docs/data-model/document-data-model.ts +++ b/packages/core/src/docs/data-model/document-data-model.ts @@ -18,9 +18,9 @@ import type { Nullable } from '../../shared'; 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 { mergeWith } from 'lodash-es'; import { BehaviorSubject } from 'rxjs'; import { isInternalEditorID } from '../../common/const'; +import { mergeWith } from '../../common/lodash'; import { UnitModel, UniverInstanceType } from '../../common/unit'; import { generateRandomId } from '../../shared/random-id'; import { Tools } from '../../shared/tools'; diff --git a/packages/docs-ui/src/plugin.ts b/packages/docs-ui/src/plugin.ts index 673b6eb2cb..784697793f 100644 --- a/packages/docs-ui/src/plugin.ts +++ b/packages/docs-ui/src/plugin.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import type { Dependency } from '@univerjs/core'; +import type { Dependency, DocumentDataModel } from '@univerjs/core'; import type { IUniverDocsUIConfig } from './config/config'; import { DependentOn, ICommandService, IConfigService, - ILogService, Inject, Injector, IUniverInstanceService, @@ -178,7 +177,6 @@ export class UniverDocsUIPlugin extends Plugin { @Inject(Injector) override _injector: Injector, @IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService, @ICommandService private _commandService: ICommandService, - @ILogService private _logService: ILogService, @IConfigService private readonly _configService: IConfigService ) { super(); @@ -201,7 +199,7 @@ export class UniverDocsUIPlugin extends Plugin { override onReady(): void { this._initRenderBasics(); - this._markDocAsFocused(); + this._initAutoFocus(); touchDependencies(this._injector, [ [DocsRenderService], @@ -392,25 +390,19 @@ export class UniverDocsUIPlugin extends Plugin { dependencies.forEach((d) => injector.add(d)); } - private _markDocAsFocused() { + private _initAutoFocus() { const currentService = this._injector.get(IUniverInstanceService); const editorService = this._injector.get(IEditorService); - try { - const doc = currentService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC); - if (!doc) return; - - const id = doc.getUnitId(); - const createOptions = currentService.getUnitCreateOptions(id); - if (createOptions?.makeCurrent === false) { + this.disposeWithMe(currentService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).subscribe((doc) => { + if (!doc) { return; } + const id = doc.getUnitId(); if (!editorService.isEditor(id)) { - currentService.focusUnit(doc.getUnitId()); + currentService.focusUnit(id); } - } catch (err) { - this._logService.warn(err); - } + })); } private _initRenderBasics(): void { diff --git a/packages/engine-formula/src/engine/analysis/lexer-node.ts b/packages/engine-formula/src/engine/analysis/lexer-node.ts index e7f219fd0c..48eebc69fa 100644 --- a/packages/engine-formula/src/engine/analysis/lexer-node.ts +++ b/packages/engine-formula/src/engine/analysis/lexer-node.ts @@ -19,9 +19,9 @@ import type { Nullable } from '@univerjs/core'; import type { LambdaPrivacyVarType } from '../ast-node/base-ast-node'; import { DEFAULT_TOKEN_TYPE_ROOT } from '../../basics/token-type'; -interface LexerNodeJson { +interface ILexerNodeJson { token: string; - children: Array; + children: Array; } export class LexerNode { @@ -173,7 +173,7 @@ export class LexerNode { const token = this.getToken(); const children = this.getChildren(); - const childrenSerialization: Array = []; + const childrenSerialization: Array = []; const childrenCount = children.length; for (let i = 0; i < childrenCount; i++) { const item = children[i]; diff --git a/packages/engine-formula/src/functions/logical/groupby/index.ts b/packages/engine-formula/src/functions/logical/groupby/index.ts index c59057b07e..1fa5272a49 100644 --- a/packages/engine-formula/src/functions/logical/groupby/index.ts +++ b/packages/engine-formula/src/functions/logical/groupby/index.ts @@ -26,13 +26,13 @@ import { FUNCTION_NAMES_LOGICAL } from '../function-names'; type GroupByAggregatorName = 'SUM' | 'COUNT' | 'COUNTA' | 'PERCENTOF' | 'MIN' | 'MAX' | 'ARRAYTOTEXT'; -interface ArrayInput { +interface IArrayInput { rowCount: number; columnCount: number; valueAt: (row: number, column: number) => BaseValueObject; } -interface GroupByGroup { +interface IGroupByGroup { key: BaseValueObject[]; values: BaseValueObject[][]; } @@ -80,7 +80,7 @@ export class Groupby extends BaseFunction { const groupColumnCount = rowFields.columnCount; const valueColumnCount = values.columnCount; const outputValueColumnCount = this._outputValueColumnCount(valueColumnCount, aggregators.length); - const groups: GroupByGroup[] = []; + const groups: IGroupByGroup[] = []; const allValues = Array.from({ length: valueColumnCount }, () => [] as BaseValueObject[]); for (let row = 0; row < rowFields.rowCount; row++) { @@ -161,7 +161,7 @@ export class Groupby extends BaseFunction { }); } - private _arrayInput(variant: FunctionVariantType | null): ArrayInput | ErrorValueObject { + private _arrayInput(variant: FunctionVariantType | null): IArrayInput | ErrorValueObject { if (variant == null) { return ErrorValueObject.create(ErrorType.VALUE); } @@ -332,7 +332,7 @@ export class Groupby extends BaseFunction { return `${typeof value.getValue()}:${String(value.getValue())}`; } - private _sortGroups(groups: GroupByGroup[], sortColumn?: number): void { + private _sortGroups(groups: IGroupByGroup[], sortColumn?: number): void { const descending = sortColumn != null && sortColumn < 0; const sortIndex = sortColumn == null ? undefined : Math.abs(sortColumn) - 1; groups.sort((left, right) => { diff --git a/packages/engine-render/src/basics/path2.ts b/packages/engine-render/src/basics/path2.ts index 0196f5580a..1b809b9451 100644 --- a/packages/engine-render/src/basics/path2.ts +++ b/packages/engine-render/src/basics/path2.ts @@ -19,7 +19,7 @@ import { Vector2 } from './vector2'; export const INITIAL_Path2: Vector2[] = [new Vector2(0, 0), new Vector2(1, 1)]; -interface Line { +interface ILine { from: Vector2; to: Vector2; } @@ -63,7 +63,7 @@ export class Path2 { return crossPoint; } - private _intersection(line1: Line, line2: Line): Vector2 | false { + private _intersection(line1: ILine, line2: ILine): Vector2 | false { const a = line1.from; const b = line1.to; const c = line2.from; diff --git a/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts b/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts index 9e36cc3cdf..faa7d8b183 100644 --- a/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts +++ b/packages/network/src/services/http/interceptors/__tests__/merge-interceptor.spec.ts @@ -57,12 +57,12 @@ describe('test "HTTPMergeInterceptor"', () => { it('two requests were created, but only one was a real request', async () => { const path = 'http://example.com'; - interface Request { ids: string[] }; - interface Response { list: number[] }; - const response: Response = { list: [1, 2] }; + interface IRequest { ids: string[] }; + interface IResponse { list: number[] }; + const response: IResponse = { list: [1, 2] }; httpService.registerHTTPInterceptor({ priority: 999, - interceptor: MergeInterceptorFactory({ + interceptor: MergeInterceptorFactory({ isMatch(config) { return config.url === path; }, @@ -86,8 +86,8 @@ describe('test "HTTPMergeInterceptor"', () => { }), }); - const request1 = httpService.post(path, { body: { ids: [1] } }); - const request2 = httpService.post(path, { body: { ids: [2] } }); + const request1 = httpService.post(path, { body: { ids: [1] } }); + const request2 = httpService.post(path, { body: { ids: [2] } }); request1.then((e) => { expect(e.body.list).toEqual(response.list); diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx index 634850d9a9..8bec7ff626 100644 --- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx +++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx @@ -357,7 +357,7 @@ const IconSetRuleEdit = (props: { > {icon ? - : } + : } diff --git a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx index 2e1493a7d8..55aa587443 100644 --- a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx +++ b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx @@ -1387,7 +1387,7 @@ function ContextMenuMenuItem(props: IContextMenuMenuItemProps) {