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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(docs-ui): align IME input with cursor (#7256)
wpxp123456d23c8df31169
diff --git a/packages/docs-ui/src/services/selection/__tests__/doc-selection-render.service.spec.ts b/packages/docs-ui/src/services/selection/__tests__/doc-selection-render.service.spec.tsindex 6ed2dc590d..351ea4db1c 100644--- a/packages/docs-ui/src/services/selection/__tests__/doc-selection-render.service.spec.ts+++ b/packages/docs-ui/src/services/selection/__tests__/doc-selection-render.service.spec.ts@@ -1300,6 +1300,7 @@ describe('DocSelectionRenderService', () => {};const { renderUnit, service, univer } = createRealSelectionRenderService({ scene });cleanup.push(() => renderUnit.dispose(), () => univer.dispose());+ vi.spyOn(TestLayoutService.root, 'getBoundingClientRect').mockReturnValue({ left: 100, top: 200 } as DOMRect);const activeRange = {isActive: () => true,getAnchor: () => ({ left: 12, top: 20, visible: true }),@@ -1315,6 +1316,19 @@ describe('DocSelectionRenderService', () => {expect(container.style.zIndex).toBe('1000');});+ it('converts the hidden editor position for a fixed containing block', () => {+ const { renderUnit, service, univer } = createRealSelectionRenderService();+ cleanup.push(() => renderUnit.dispose(), () => univer.dispose());+ const container = document.getElementById('univer-doc-selection-container-selection-render-doc')!;+ vi.spyOn(container, 'offsetParent', 'get').mockReturnValue(TestLayoutService.root);+ vi.spyOn(TestLayoutService.root, 'getBoundingClientRect').mockReturnValue({ left: 100, top: 200 } as DOMRect);++ service.activate(35, 47);++ expect(container.style.left).toBe('-65px');+ expect(container.style.top).toBe('-153px');+ });+it('parks the active selection while scrolling and restores the editor when the selection remains in view', () => {getCanvasOffsetByEngineMock.mockReturnValue({ left: 1, top: 2 });const scrollAfter$ = new TestRenderEvent<{ viewport: unknown }>();diff --git a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts b/packages/docs-ui/src/services/selection/doc-selection-render.service.tsindex cf267a0242..52d9e0d688 100644--- a/packages/docs-ui/src/services/selection/doc-selection-render.service.ts+++ b/packages/docs-ui/src/services/selection/doc-selection-render.service.ts@@ -372,16 +372,13 @@ export class DocSelectionRenderService extends RxDisposable implements IRenderMothis._updateInputPosition();}- /**- * @deprecated- */activate(x: number, y: number, force = false) {// Keep the hidden editor inside the Portal subtree when possible to avoid focus-trap loops,// then compensate coordinates if a transformed ancestor changes the fixed containing block.this._ensureHostContainer();let left = x;let top = y;- const fixedContainer = this._container.parentElement;+ const fixedContainer = this._container.offsetParent;if (fixedContainer) {const rect = fixedContainer.getBoundingClientRect();left -= rect.left;