From 65fe84c4946deac7f43abbff5e65fa51efde968c Mon Sep 17 00:00:00 2001 From: DR-Univer Date: Sat, 16 Mar 2024 16:53:09 +0800 Subject: [PATCH 1/4] fix(editor): optimize editor focus --- .../controllers/text-selection.controller.ts | 23 +++++++++---------- .../text-selection-render-manager.ts | 22 ++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/docs-ui/src/controllers/text-selection.controller.ts b/packages/docs-ui/src/controllers/text-selection.controller.ts index b7dd47d3557..af2901177cb 100644 --- a/packages/docs-ui/src/controllers/text-selection.controller.ts +++ b/packages/docs-ui/src/controllers/text-selection.controller.ts @@ -121,22 +121,21 @@ export class TextSelectionController extends Disposable { this._currentUniverService.setCurrentUniverDocInstance(unitId); } + this._textSelectionRenderManager.eventTrigger(evt); + if (this._editorService.getEditor(unitId)) { - /** - * To accommodate focus switching between different editors. - * Since the editor for Univer is canvas-based, - * it primarily relies on focus and cannot use the focus event. - * Our editor's focus monitoring is based on PointerDown. - * The order of occurrence is such that PointerDown comes first. - * Translate the above text into English. - */ + /** + * To accommodate focus switching between different editors. + * Since the editor for Univer is canvas-based, + * it primarily relies on focus and cannot use the focus event. + * Our editor's focus monitoring is based on PointerDown. + * The order of occurrence is such that PointerDown comes first. + * Translate the above text into English. + */ setTimeout(() => { - this._textSelectionRenderManager.eventTrigger(evt); - this._setEditorFocus(unitId); + this._textSelectionRenderManager.setCursorManually(evt.offsetX, evt.offsetY); }, 0); - } else { - this._textSelectionRenderManager.eventTrigger(evt); } if (evt.button !== 2) { diff --git a/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts b/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts index 66266218df3..018cd9a41db 100644 --- a/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts +++ b/packages/engine-render/src/components/docs/text-selection/text-selection-render-manager.ts @@ -165,6 +165,8 @@ export interface ITextSelectionRenderManager { handleTripleClick(evt: IPointerEvent | IMouseEvent): void; eventTrigger(evt: IPointerEvent | IMouseEvent): void; + + setCursorManually(evtOffsetX: number, evtOffsetY: number): void; } export interface IEditorInputConfig { @@ -442,6 +444,26 @@ export class TextSelectionRenderManager extends RxDisposable implements ITextSel this.addTextRanges(textRanges, false); } + setCursorManually(evtOffsetX: number, evtOffsetY: number) { + const startNode = this._findNodeByCoord(evtOffsetX, evtOffsetY); + + const position = this._getNodePosition(startNode); + + if (position == null) { + this._removeAllTextRanges(); + + return; + } + + if (startNode?.node.streamType === DataStreamTreeTokenType.PARAGRAPH) { + position.isBack = true; + } + + this._updateTextRangeAnchorPosition(position); + + this._activeSelectionRefresh(); + } + // Handle pointer down. eventTrigger(evt: IPointerEvent | IMouseEvent) { if (!this._scene || !this._isSelectionEnabled) { From 60926b87ef1abb6b53e46f6126426c9f5be66f4e Mon Sep 17 00:00:00 2001 From: DR-Univer Date: Sat, 16 Mar 2024 17:48:26 +0800 Subject: [PATCH 2/4] fix(editor): firefox and regex --- packages/core/src/shared/common.ts | 6 +++--- .../docs-ui/src/controllers/text-selection.controller.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts index dcacd3ae6b4..35a1e32c27c 100644 --- a/packages/core/src/shared/common.ts +++ b/packages/core/src/shared/common.ts @@ -253,7 +253,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) if (style.ul?.s) { // If there are existing lines, add new lines if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' underline'); + str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' underline'); } else { str += 'text-decoration-line: underline; '; } @@ -271,7 +271,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) () => { if (style.st?.s) { if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' line-through'); + str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' line-through'); } else { str += 'text-decoration-line: line-through; '; } @@ -289,7 +289,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) () => { if (style.ol?.s) { if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' overline'); + str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' overline'); } else { str += 'text-decoration-line: overline; '; } diff --git a/packages/docs-ui/src/controllers/text-selection.controller.ts b/packages/docs-ui/src/controllers/text-selection.controller.ts index af2901177cb..50b9d26864a 100644 --- a/packages/docs-ui/src/controllers/text-selection.controller.ts +++ b/packages/docs-ui/src/controllers/text-selection.controller.ts @@ -123,6 +123,8 @@ export class TextSelectionController extends Disposable { this._textSelectionRenderManager.eventTrigger(evt); + const { offsetX, offsetY } = evt; + if (this._editorService.getEditor(unitId)) { /** * To accommodate focus switching between different editors. @@ -134,7 +136,7 @@ export class TextSelectionController extends Disposable { */ setTimeout(() => { this._setEditorFocus(unitId); - this._textSelectionRenderManager.setCursorManually(evt.offsetX, evt.offsetY); + this._textSelectionRenderManager.setCursorManually(offsetX, offsetY); }, 0); } From 5ef48efb65753ad9be1d93e28aec1c01bffebebc Mon Sep 17 00:00:00 2001 From: DR-Univer Date: Sat, 16 Mar 2024 19:11:37 +0800 Subject: [PATCH 3/4] fix(sheet): old version safari --- examples/esbuild.config.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/esbuild.config.mjs b/examples/esbuild.config.mjs index ed2da0fc4e1..31bb5a7c00c 100644 --- a/examples/esbuild.config.mjs +++ b/examples/esbuild.config.mjs @@ -25,6 +25,7 @@ function monacoBuildTask() { entryPoints: monacoEditorEntryPoints.map((entry) => `./node_modules/monaco-editor/esm/${entry}`), bundle: true, color: true, + target: 'chrome70', format: 'iife', outbase: './node_modules/monaco-editor/esm/', outdir: './local', @@ -42,6 +43,7 @@ const ctx = await esbuild[args.watch ? 'context' : 'build']({ loader: { '.svg': 'file', '.ttf': 'file' }, sourcemap: args.watch, minify: !args.watch, + target: 'chrome70', plugins: [ copyPlugin({ assets: { From 9269bed9713408b1e42e714ac6a4394f301a00be Mon Sep 17 00:00:00 2001 From: jocs Date: Sat, 16 Mar 2024 19:11:44 +0800 Subject: [PATCH 4/4] fix: regexp --- packages/core/src/shared/common.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts index 35a1e32c27c..d048ca910cc 100644 --- a/packages/core/src/shared/common.ts +++ b/packages/core/src/shared/common.ts @@ -253,7 +253,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) if (style.ul?.s) { // If there are existing lines, add new lines if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' underline'); + str = str.replace(/(text-decoration-line:\s*[^;]+)(?=;)/g, (_, p1) => `${p1} underline`); } else { str += 'text-decoration-line: underline; '; } @@ -271,7 +271,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) () => { if (style.st?.s) { if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' line-through'); + str = str.replace(/(text-decoration-line:\s*[^;]+)(?=;)/g, (_, p1) => `${p1} line-through`); } else { str += 'text-decoration-line: line-through; '; } @@ -289,7 +289,7 @@ export function handleStyleToString(style: IStyleData, isCell: boolean = false) () => { if (style.ol?.s) { if (str.indexOf('text-decoration-line') > -1) { - str = str.replace(/text-decoration-line:\s*([^;]+);/g, ' overline'); + str = str.replace(/(text-decoration-line:\s*[^;]+)(?=;)/g, (_, p1) => `${p1} overline`); } else { str += 'text-decoration-line: overline; '; }