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(sheet): editor blur (#901)

Univerf92123f95312
diff --git a/.stylelintrc.json b/.stylelintrc.json
index 0ec205013e..001f84e148 100644
--- a/.stylelintrc.json
+++ b/.stylelintrc.json
@@ -8,6 +8,7 @@
}
],
"no-duplicate-selectors": null,
- "no-descending-specificity": null
+ "no-descending-specificity": null,
+ "color-function-notation": null
}
}
diff --git a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
index afa9507484..4da6709a30 100644
--- a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts
@@ -48,6 +48,8 @@ import {
import type { DocumentSkeleton, IDocumentLayoutObject, IEditorInputConfig, Scene } from '@univerjs/engine-render';
import {
DeviceInputEventType,
+ FIX_ONE_PIXEL_BLUR_OFFSET,
+ fixLineWidthByScale,
IRenderManagerService,
ITextSelectionRenderManager,
Rect,
@@ -338,7 +340,7 @@ export class StartEditController extends Disposable {
return;
}
- const { startX, startY } = actualRangeWithCoord;
+ let { startX, startY } = actualRangeWithCoord;
const { document: documentComponent, scene, engine } = editorObject;
@@ -376,11 +378,21 @@ export class StartEditController extends Disposable {
editorWidth = clientWidth;
}
- editorWidth = Math.round(editorWidth);
+ const pixelRatio = engine.getPixelRatio();
- editorHeight = Math.round(editorHeight);
+ const scaleXPixelRatio = scaleX * pixelRatio;
- physicHeight = Math.round(editorHeight);
+ const scaleYPixelRatio = scaleY * pixelRatio;
+
+ startX = fixLineWidthByScale(startX - FIX_ONE_PIXEL_BLUR_OFFSET, scaleXPixelRatio);
+
+ startY = fixLineWidthByScale(startY - FIX_ONE_PIXEL_BLUR_OFFSET, scaleYPixelRatio);
+
+ editorWidth = fixLineWidthByScale(editorWidth, scaleXPixelRatio);
+
+ editorHeight = fixLineWidthByScale(editorHeight, scaleYPixelRatio);
+
+ physicHeight = fixLineWidthByScale(editorHeight, scaleYPixelRatio);
this._addBackground(scene, editorWidth / scaleX, editorHeight / scaleY, fill);
@@ -494,6 +506,7 @@ export class StartEditController extends Disposable {
const { skeleton } = docParam;
this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY);
+
// move selection
if (
eventType === DeviceInputEventType.Keyboard ||
diff --git a/packages/sheets-ui/src/services/selection/selection-shape.ts b/packages/sheets-ui/src/services/selection/selection-shape.ts
index bf5c4078cb..63466d9c69 100644
--- a/packages/sheets-ui/src/services/selection/selection-shape.ts
+++ b/packages/sheets-ui/src/services/selection/selection-shape.ts
@@ -475,11 +475,11 @@ export class SelectionShape {
this.dashRect.hide();
} else {
this.dashRect.transformByState({
- height: endY - startY,
- width: endX - startX,
+ height: endY - startY - strokeWidth / 2,
+ width: endX - startX - strokeWidth / 2,
strokeWidth,
- left: -1,
- top: -1,
+ left: strokeWidth / 2 - 1 / scale,
+ top: strokeWidth / 2 - 1 / scale,
});
this.dashRect.setProps({
diff --git a/packages/sheets-ui/src/views/editor-container/index.module.less b/packages/sheets-ui/src/views/editor-container/index.module.less
index 217f69dbb9..9ba23db4c0 100644
--- a/packages/sheets-ui/src/views/editor-container/index.module.less
+++ b/packages/sheets-ui/src/views/editor-container/index.module.less
@@ -10,7 +10,7 @@
height: 50px;
border: 1.5px solid rgb(var(--primary-color));
- outline: 1.5px solid rgb(var(--primary-color-hover) 0.5);
+ outline: 1.5px solid rgba(var(--primary-color-hover), 0.5);
box-shadow: none;
.editor-input {