Skip to content

Commit 7eb2d22

Browse files
committed
fix: fix issue with text edit include textAlign and bounds
1 parent 143ec08 commit 7eb2d22

File tree

4 files changed

+67
-299
lines changed

4 files changed

+67
-299
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vrender-core",
5+
"comment": "fix: fix issue with text edit include textAlign and bounds",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vrender-core"
10+
}

packages/vrender-core/src/plugins/builtin-plugin/edit-module.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import type {
1818
// }
1919

2020
export function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {
21-
const { fill = 'black', stroke = false, fontWeight = 'normal', lineHeight, fontFamily = 'Arial' } = attribute;
21+
const {
22+
fill = 'black',
23+
stroke = false,
24+
fontWeight = 'normal',
25+
lineHeight,
26+
fontFamily = 'Arial',
27+
textAlign
28+
} = attribute;
2229
let { fontSize = 12 } = attribute;
2330
if (!isFinite(fontSize)) {
2431
fontSize = 12;
@@ -29,7 +36,8 @@ export function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute)
2936
fontSize,
3037
fontWeight,
3138
fontFamily,
32-
lineHeight
39+
lineHeight,
40+
textAlign
3341
} as any;
3442
}
3543

@@ -219,7 +227,12 @@ export class EditModule {
219227
} else {
220228
const configIdx = this.composingConfigIdx;
221229
const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];
222-
textConfig.splice(configIdx, 0, { fill: 'black', ...lastConfig, text: '' });
230+
textConfig.splice(configIdx, 0, {
231+
fill: 'black',
232+
...getDefaultCharacterConfig(this.currRt.attribute),
233+
...lastConfig,
234+
text: ''
235+
});
223236
}
224237
};
225238
handleCompositionEnd = () => {

packages/vrender-core/src/plugins/builtin-plugin/richtext-edit-plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ export class RichTextEditPlugin implements IPlugin {
617617
if (!editOptions || !boundsStrokeWhenInput) {
618618
return;
619619
}
620+
// 得先偏移,不然上一次的Bounds会影响后续的计算
621+
this.offsetShadowRoot();
620622
// const { attribute } = this.currRt;
621623
const b = this.getRichTextAABBBounds(this.currRt);
622624
const height = b.height();
@@ -641,7 +643,6 @@ export class RichTextEditPlugin implements IPlugin {
641643
// shadow.add(this.shadowBounds);
642644

643645
this.offsetLineBgAndShadowBounds();
644-
this.offsetShadowRoot();
645646
}
646647

647648
trySyncPlaceholderToTextConfig() {
@@ -1089,7 +1090,7 @@ export class RichTextEditPlugin implements IPlugin {
10891090
protected getShadow(rt: IRichText) {
10901091
const sr = rt.shadowRoot || rt.attachShadow();
10911092
// TODO 这里比较hack,因为emptyBoundsContainer是empty,导致shadowRoot的Bounds为空,所以这里给一个1*1的rect,让其能绘制
1092-
sr.setAttributes({ width: 1, height: 1 });
1093+
sr.setAttributes({ width: 0, height: 0 });
10931094
return sr;
10941095
}
10951096

0 commit comments

Comments
 (0)