fix(sheets-drawing-ui): fix image zoom-in issue in merged cells (#7041)

Co-authored-by: Wpxp123456 <2677556700@qq.com>
This commit is contained in:
白熱
2026-06-09 12:01:03 +08:00
committed by GitHub
co-authored by Wpxp123456
parent c68c4129a9
commit cd9c7fba56
3 changed files with 61 additions and 10 deletions
@@ -48,16 +48,32 @@ export class SheetCellImageHoverRenderController extends Disposable implements I
if (richText !== null) {
currentSelections = this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections();
}
if (
currentSelections.length > 0 &&
richText?.unitId === this._context.unitId &&
richText?.drawing &&
currentSelections.length === 1 &&
currentSelections[0].primary?.actualRow === richText.row &&
currentSelections[0].primary?.actualColumn === richText.col
currentSelections[0].primary
) {
this._isSetCursor = true;
this._context.scene.setCursor(CURSOR_TYPE.ZOOM_IN);
const { row, col } = richText;
const { actualRow, actualColumn, startRow, startColumn, endRow, endColumn, isMerged, isMergedMainCell } = currentSelections[0].primary;
if (
(isMerged || isMergedMainCell) &&
row >= startRow &&
row <= endRow &&
col >= startColumn &&
col <= endColumn
) {
this._isSetCursor = true;
this._context.scene.setCursor(CURSOR_TYPE.ZOOM_IN);
} else if (row === actualRow && col === actualColumn) {
this._isSetCursor = true;
this._context.scene.setCursor(CURSOR_TYPE.ZOOM_IN);
} else if (this._isSetCursor) {
this._isSetCursor = false;
this._context.scene.resetCursor();
}
} else if (this._isSetCursor) {
this._isSetCursor = false;
this._context.scene.resetCursor();
@@ -14,11 +14,12 @@
* limitations under the License.
*/
import type { DocumentSkeleton } from '@univerjs/engine-render';
import { HorizontalAlign, IUniverInstanceService, VerticalAlign } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { describe, expect, it, vi } from 'vitest';
import { IEditorBridgeService } from '../../editor-bridge.service';
import { calcPadding, getCustomRangePosition, getEditingCustomRangePosition } from '../doc-skeleton-util';
import { calcPadding, calculateDocSkeletonRects, getCustomRangePosition, getEditingCustomRangePosition } from '../doc-skeleton-util';
vi.mock('@univerjs/docs-ui', async (importOriginal) => {
const actual = await importOriginal<typeof import('@univerjs/docs-ui')>();
@@ -96,6 +97,40 @@ describe('doc-skeleton-util', () => {
expect(calcPadding(cell, unspecifiedNumeric, true)).toEqual({ paddingTop: 20, paddingLeft: 30 });
});
it('does not add cell alignment padding to skeleton drawing positions', () => {
const docSkeleton = {
getSkeletonData: () => ({
pages: [{
skeDrawings: new Map([
['image-1', {
aLeft: 45,
aTop: 1,
width: 38,
height: 38,
}],
]),
}],
}),
getViewModel: () => ({
getDataModel: () => ({
getBody: () => ({
customRanges: [],
paragraphs: [],
}),
}),
}),
};
const rects = calculateDocSkeletonRects(docSkeleton as unknown as DocumentSkeleton, 48, 1);
expect(rects.drawings[0].rect).toEqual({
top: 1,
bottom: 39,
left: 45,
right: 83,
});
});
it('getCustomRangePosition returns transformed rects and label', () => {
const docSkeleton = createDocSkeleton();
const font = {
@@ -148,10 +148,10 @@ export const calculateDocSkeletonRects = (docSkeleton: DocumentSkeleton, padding
? Array.from(drawings.keys()).map((key) => ({
drawingId: key,
rect: {
top: drawings!.get(key)!.aTop + paddingTop,
bottom: drawings!.get(key)!.aTop + drawings!.get(key)!.height + paddingTop,
left: drawings!.get(key)!.aLeft + paddingLeft,
right: drawings!.get(key)!.aLeft + drawings!.get(key)!.width + paddingLeft,
top: drawings.get(key)!.aTop,
bottom: drawings.get(key)!.aTop + drawings.get(key)!.height,
left: drawings.get(key)!.aLeft,
right: drawings.get(key)!.aLeft + drawings.get(key)!.width,
},
drawing: drawings.get(key)!,
}))