Skip to content

Commit 9f9ff10

Browse files
committed
fix: drawing & toolbar override
1 parent 8c073a1 commit 9f9ff10

6 files changed

Lines changed: 52 additions & 66 deletions

File tree

packages/plugin/src/text/drawing.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ export const drawingBackground = (
110110
let backgroundWidth = item.width + halfGap;
111111
let isStart = true;
112112
let isEnd = true;
113-
113+
114114
// 检查是否是代码块的开始和结束
115115
if (i > 0) {
116116
const prev = matrix.items[i - 1];
117-
isStart = !prev.config[TEXT_ATTRS.BACKGROUND] || prev.config[TEXT_ATTRS.BACKGROUND] !== background;
117+
isStart =
118+
!prev.config[TEXT_ATTRS.BACKGROUND] || prev.config[TEXT_ATTRS.BACKGROUND] !== background;
118119
}
119-
120+
120121
// 合并连续的相同背景色
121122
for (let k = i + 1; k < matrix.items.length; ++k) {
122123
const next = matrix.items[k];
@@ -128,16 +129,17 @@ export const drawingBackground = (
128129
break;
129130
}
130131
}
131-
132+
132133
ctx.fillStyle = background;
133-
134+
134135
// 计算代码块的位置和尺寸,添加水平内边距
135136
const x = offsetX - halfGap - (isStart ? HORIZONTAL_PADDING : 0);
136137
const y = offsetYBaseLine - matrix.originHeight - BACKGROUND_OFFSET - 1;
137-
const width = backgroundWidth + (isStart ? HORIZONTAL_PADDING : 0) + (isEnd ? HORIZONTAL_PADDING : 0);
138+
const width =
139+
backgroundWidth + (isStart ? HORIZONTAL_PADDING : 0) + (isEnd ? HORIZONTAL_PADDING : 0);
138140
const height = matrix.originHeight + BACKGROUND_OFFSET * 2;
139141
const borderRadius = 4;
140-
142+
141143
// 根据是否是代码块的开始和结束来调整圆角
142144
if (isStart && isEnd) {
143145
// 单个字符的代码块,四个角都是圆角
@@ -172,7 +174,7 @@ export const drawingBackground = (
172174
// 代码块中间,没有圆角
173175
ctx.rect(x, y, width, height);
174176
}
175-
177+
176178
ctx.fill();
177179
ctx.closePath();
178180
}

packages/plugin/src/text/rich-text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class RichText {
6363
let matrix: TextMatrix = getDefaultMatrix();
6464
for (const fragment of line.chars) {
6565
for (const character of fragment.char) {
66-
const item = { char: character, config: fragment.config };
66+
const item = { char: character, config: { ...fragment.config } };
6767
const { metric, font } = this.measure(item.char, item.config);
6868
if (!metric) continue;
6969
const text: TextMatrixItem = {

packages/react/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"license": "MIT",
2323
"dependencies": {
2424
"@arco-design/web-react": "2.60.3",
25-
"@block-kit/core": "1.0.4",
26-
"@block-kit/delta": "1.0.4",
27-
"@block-kit/plugin": "1.0.4",
28-
"@block-kit/react": "1.0.4",
29-
"@block-kit/utils": "1.0.4",
25+
"@block-kit/core": "1.0.5",
26+
"@block-kit/delta": "1.0.5",
27+
"@block-kit/plugin": "1.0.5",
28+
"@block-kit/react": "1.0.5",
29+
"@block-kit/utils": "1.0.5",
3030
"react": "17.0.2",
3131
"react-dom": "17.0.2",
3232
"sketching-core": "workspace: *",

packages/react/src/components/right-panel/components/text/modules/editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const RichTextEditor: FC<{
102102
e && setMountDOM(blockEditor, e);
103103
});
104104

105-
const overridePosition = (l: number, t: number) => {
105+
const overridePosition = () => {
106106
const rect = blockEditor.rect.getRawSelectionRect();
107107
if (rect) {
108108
const t = rect.top - 8;
@@ -112,7 +112,7 @@ export const RichTextEditor: FC<{
112112
}
113113
return { top: t, left: l };
114114
}
115-
return { top: t, left: l };
115+
return { top: -999999, left: -999999 };
116116
};
117117

118118
return (
Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
import { Point, Range, RawPoint } from "@block-kit/core";
2-
import { Delta } from "@block-kit/delta";
31
import type { ShortcutFuncMap } from "@block-kit/plugin";
4-
import { DIVIDER_KEY, isKeyCode } from "@block-kit/plugin";
5-
import { KEY_CODE, TRULY } from "@block-kit/utils";
2+
import { HEADING_KEY } from "@block-kit/plugin";
63

74
export const PRESET_SHORTCUT: ShortcutFuncMap = {
8-
[DIVIDER_KEY]: (event, payload) => {
9-
if (isKeyCode(event, KEY_CODE.SPACE) && payload.sel && payload.sel.isCollapsed) {
10-
const { editor, sel } = payload;
11-
const line = editor.state.block.getLine(sel.start.line);
12-
const firstLeaf = line && line.getFirstLeaf();
13-
const text = firstLeaf && firstLeaf.getText();
14-
if (text === "---") {
15-
editor.perform.deleteForward(Range.fromTuple([sel.start.line, 0], [sel.start.line, 3]));
16-
const start = RawPoint.fromPoint(editor, new Point(sel.start.line, 0));
17-
if (!start) return void 0;
18-
const delta = new Delta().retain(start.offset).insert(" ", { [DIVIDER_KEY]: TRULY });
19-
editor.state.apply(delta);
20-
event.preventDefault();
21-
return true;
22-
}
23-
}
5+
[HEADING_KEY]: () => {
6+
// 覆盖默认的标题快捷键
7+
return void 0;
248
},
259
};

pnpm-lock.yaml

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)