Skip to content

Commit

Permalink
fix(draw): memorize line text property #WIK-15737 (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa authored Jun 26, 2024
1 parent 2d8b964 commit 4bd014d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-pears-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/draw': patch
---

memorize line text property
6 changes: 4 additions & 2 deletions packages/draw/src/line.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaitBoard, PlaitPluginElementContext, OnContextChanged, getElementById, createDebugGenerator } from '@plait/core';
import { PlaitBoard, PlaitPluginElementContext, OnContextChanged, getElementById, createDebugGenerator, PlaitNode } from '@plait/core';
import { LineText, PlaitGeometry, PlaitLine } from './interfaces';
import { LineShapeGenerator } from './generators/line.generator';
import { LineActiveGenerator } from './generators/line-active.generator';
Expand Down Expand Up @@ -127,7 +127,9 @@ export class LineComponent extends CommonElementFlavour<PlaitLine, PlaitBoard> i
return getLineTextRectangle(this.board, this.element, index);
},
onChange: (textManageChangeData: TextManageChangeData) => {
const texts = [...this.element.texts];
const path = PlaitBoard.findPath(this.board, this.element);
const node = PlaitNode.get(this.board, path) as PlaitLine;
const texts = [...node.texts];
const newWidth = textManageChangeData.width < MIN_TEXT_WIDTH ? MIN_TEXT_WIDTH : textManageChangeData.width;
texts.splice(index, 1, {
text: textManageChangeData.newText ? textManageChangeData.newText : this.element.texts[index].text,
Expand Down
5 changes: 3 additions & 2 deletions packages/draw/src/plugins/with-line-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@plait/core';
import { PlaitDrawElement, PlaitLine } from '../interfaces';
import { Node } from 'slate';
import { buildText, getRatioByPoint, getTextManages } from '@plait/common';
import { buildText, getMemorizedLatest, getRatioByPoint, getTextManages } from '@plait/common';
import { DrawTransforms } from '../transforms';
import { getLinePoints } from '../utils/line/line-basic';
import { getHitLineTextIndex } from '../utils/position/line';
Expand All @@ -36,8 +36,9 @@ export const withLineText = (board: PlaitBoard) => {
editHandle(board, hitTarget, textIndex);
} else {
const ratio = getRatioByPoint(points, point);
const textMemory = getMemorizedLatest('line')?.text || {};
texts.push({
text: buildText(LINE_TEXT),
text: buildText(LINE_TEXT, undefined, textMemory),
position: ratio,
width: 28,
height: 20
Expand Down
1 change: 0 additions & 1 deletion packages/draw/src/utils/memorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const getMemorizeKey = (element: PlaitElement) => {

export const getLineMemorizedLatest = () => {
const properties = getMemorizedLatest(MemorizeKey.line);
delete properties?.text;
return { ...properties } || {};
};

Expand Down

0 comments on commit 4bd014d

Please sign in to comment.