Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-hyper-link): sheet link popup should attach to cell editor (#4063)

zhangw7550f1cef8c7
diff --git a/packages/docs-ui/src/index.ts b/packages/docs-ui/src/index.ts
index fe6c5e1795..50aff6b1f6 100644
--- a/packages/docs-ui/src/index.ts
+++ b/packages/docs-ui/src/index.ts
@@ -36,7 +36,7 @@ export * from './services';
export { IDocClipboardService } from './services/clipboard/clipboard.service';
export { DocEventManagerService } from './services/doc-event-manager.service';
export { DocIMEInputManagerService } from './services/doc-ime-input-manager.service';
-export { DocCanvasPopManagerService } from './services/doc-popup-manager.service';
+export { calcDocRangePositions, DocCanvasPopManagerService } from './services/doc-popup-manager.service';
export { DocStateChangeManagerService } from './services/doc-state-change-manager.service';
export { DocsRenderService } from './services/docs-render.service';
export { Editor } from './services/editor/editor';
diff --git a/packages/sheets-hyper-link-ui/src/services/popup.service.ts b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
index 8c5a4aa80a..dccd6a51d7 100644
--- a/packages/sheets-hyper-link-ui/src/services/popup.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
@@ -15,12 +15,12 @@
*/
import type { DocumentDataModel, ICustomRange, IDisposable, INeedCheckDisposable, ITextRange, Nullable, Workbook } from '@univerjs/core';
-import type { IBoundRectNoAngle } from '@univerjs/engine-render';
import type { ISheetLocationBase } from '@univerjs/sheets';
import type { ICanvasPopup } from '@univerjs/sheets-ui';
-import { BuildTextUtils, CustomRangeType, Disposable, DOCS_ZEN_EDITOR_UNIT_ID_KEY, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { BuildTextUtils, CustomRangeType, Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
-import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
+import { calcDocRangePositions, DocCanvasPopManagerService } from '@univerjs/docs-ui';
+import { type IBoundRectNoAngle, IRenderManagerService } from '@univerjs/engine-render';
import { getCustomRangePosition, getEditingCustomRangePosition, IEditorBridgeService, SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
import { IZenZoneService } from '@univerjs/ui';
import { BehaviorSubject, Subject } from 'rxjs';
@@ -287,17 +287,26 @@ export class SheetsHyperLinkPopupService extends Disposable {
} else if (type === HyperLinkEditSourceType.EDITING) {
const range = this._getEditingRange();
- if (range) {
- this._textSelectionManagerService.replaceTextRanges([{ ...range }]);
+ if (!range) {
+ return;
}
- this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(
- link.row,
- link.col,
+ this._textSelectionManagerService.replaceDocRanges([{ ...range }], { unitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY, subUnitId: DOCS_NORMAL_EDITOR_UNIT_ID_KEY });
+ const currentRender = this._injector.get(IRenderManagerService).getRenderById(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
+ if (!currentRender) {
+ return;
+ }
+ const rects = calcDocRangePositions(range, currentRender);
+ if (!rects?.length) {
+ return;
+ }
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(
+ rects.pop()!,
this._editPopup,
unitId,
subUnitId
);
+
this._currentEditing$.next({
...link,
label: range?.label ?? '',