Skip to content

Commit

Permalink
fix(sheet): editor and selection position (#1830)
Browse files Browse the repository at this point in the history
* fix(sheet): editor and selection position

* fix(sheet): type error
  • Loading branch information
DR-Univer authored Apr 8, 2024
1 parent 6544ffc commit e23992f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
8 changes: 3 additions & 5 deletions packages/engine-render/src/shape/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ export abstract class Shape<T> extends BaseObject {
private static _renderStroke(ctx: UniverRenderingContext, props: IShapeProps) {
const { stroke, strokeWidth, shadowEnabled, shadowForStrokeEnabled, strokeScaleEnabled, parent } = props;

let { scaleX, scaleY } = props;
// let { scaleX, scaleY } = props;
let { scaleX, scaleY } = ctx.getScale();
if (!stroke || strokeWidth === 0) {
return;
}
Expand All @@ -281,10 +282,7 @@ export abstract class Shape<T> extends BaseObject {
}

ctx.save();
if (strokeScaleEnabled && parent) {
const scaling = this._getObjectScaling();
ctx.scale(1 / scaling.scaleX, 1 / scaling.scaleY);
} else if (strokeScaleEnabled) {
if (strokeScaleEnabled === false) {
scaleX = scaleX ?? 1;
scaleY = scaleY ?? 1;
ctx.scale(1 / scaleX, 1 / scaleY);
Expand Down
10 changes: 5 additions & 5 deletions packages/sheets-ui/src/services/editor-bridge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
toDisposable,
} from '@univerjs/core';
import type { Engine, IDocumentLayoutObject, Scene } from '@univerjs/engine-render';
import { convertTextRotation, DeviceInputEventType, fixLineWidthByScale, getCanvasOffsetByEngine } from '@univerjs/engine-render';
import { convertTextRotation, DeviceInputEventType, getCanvasOffsetByEngine } from '@univerjs/engine-render';
import type { ISheetLocation } from '@univerjs/sheets';
import { IEditorService } from '@univerjs/ui';
import type { KeyCode } from '@univerjs/ui';
Expand Down Expand Up @@ -222,10 +222,10 @@ export class EditorBridgeService extends Disposable implements IEditorBridgeServ
const { scaleX: precisionScaleX, scaleY: precisionScaleY } = scene.getPrecisionScale();

const scrollXY = scene.getScrollXY(this._selectionRenderService.getViewPort());
startX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(startX, scaleX, scrollXY), precisionScaleX);
startY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(startY, scaleY, scrollXY), precisionScaleY);
endX = fixLineWidthByScale(skeleton.convertTransformToOffsetX(endX, scaleX, scrollXY), precisionScaleX);
endY = fixLineWidthByScale(skeleton.convertTransformToOffsetY(endY, scaleY, scrollXY), precisionScaleY);
startX = skeleton.convertTransformToOffsetX(startX, scaleX, scrollXY);
startY = skeleton.convertTransformToOffsetY(startY, scaleY, scrollXY);
endX = skeleton.convertTransformToOffsetX(endX, scaleX, scrollXY);
endY = skeleton.convertTransformToOffsetY(endY, scaleY, scrollXY);

const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
Expand Down
4 changes: 2 additions & 2 deletions packages/sheets-ui/src/services/selection/selection-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ export class SelectionShape extends Disposable {
this.fillControl.transformByState({
width: AutofillSize - AutofillStrokeWidth,
height: AutofillSize - AutofillStrokeWidth,
left: endX - startX - AutofillSize / 2 + AutofillStrokeWidth / 2,
top: endY - startY - AutofillSize / 2 + AutofillStrokeWidth / 2,
left: endX - startX - AutofillSize / 2 + AutofillStrokeWidth / 2 - fixOnePixelBlurOffset,
top: endY - startY - AutofillSize / 2 + AutofillStrokeWidth / 2 - fixOnePixelBlurOffset,
strokeWidth: AutofillStrokeWidth,
});
this.fillControl.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export const EditorContainer: React.FC<ICellIEditorProps> = () => {
});
} else {
setState({
width: endX - startX - FIX_ONE_PIXEL_BLUR_OFFSET * 2,
height: endY - startY - FIX_ONE_PIXEL_BLUR_OFFSET * 2,
width: endX - startX - FIX_ONE_PIXEL_BLUR_OFFSET,
height: endY - startY - FIX_ONE_PIXEL_BLUR_OFFSET,
left: startX + FIX_ONE_PIXEL_BLUR_OFFSET,
top: startY + FIX_ONE_PIXEL_BLUR_OFFSET,
});
Expand Down

0 comments on commit e23992f

Please sign in to comment.