fix: prevent IME preedit overflow in mind map node editor (#14520)

## Summary

Update the edgeless shape text editor to resize mind map node text
bounds while IME composition is in progress.

## Changes

- listen to `compositionupdate` on the inline editor container
- trigger `_updateElementWH()` on `compositionupdate` and
`compositionend`
- keep text box dimensions in sync before composition is committed

## Testing

- Not run locally: `pnpm` is not available in this environment, so
package build/tests could not be executed here.

Fixes #11515


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Editor mounting tolerates missing/null elements and validates input to
avoid errors.
* Text creation/update consistently targets the refreshed element to
prevent mismatches.
* Inline editor listens for IME composition events and schedules
layout/size recalculation (with proper cleanup) so sizing stays in sync.

* **Tests**
* Added an integration test verifying layout/size updates during IME
composition events.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com>
Co-authored-by: DarkSky <darksky2048@gmail.com>
This commit is contained in:
Cats Juice
2026-04-09 11:25:55 +08:00
committed by GitHub
parent 7138fea9db
commit 77c0b2ef47
4 changed files with 325 additions and 30 deletions
@@ -311,7 +311,6 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
id = this.surface.addElement({
type,
xywh: '[0,0,100,30]',
maxWidth: false,
...props,
...style.node,
});
@@ -345,7 +344,6 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
id = this.surface.addElement({
type,
xywh: '[0,0,113,41]',
maxWidth: false,
...props,
...rootStyle,
});
@@ -834,7 +832,12 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
}
const stashed = new Set<GfxPrimitiveElementModel>();
const stashedNodeIds = new Set<string>();
const traverse = (node: MindmapNode) => {
if (this._stashedNode.has(node.id)) return;
this._stashedNode.add(node.id);
stashedNodeIds.add(node.id);
node.element.stash('xywh');
stashed.add(node.element);
@@ -846,7 +849,9 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
traverse(mindNode);
return () => {
this._stashedNode.delete(mindNode.id);
stashedNodeIds.forEach(id => {
this._stashedNode.delete(id);
});
stashed.forEach(el => {
el.pop('xywh');
});
@@ -35,6 +35,7 @@ export type NodeStyle = {
strokeColor: Color;
textResizing: TextResizing;
maxWidth: false | number;
fontSize: number;
fontFamily: string;
@@ -62,6 +63,8 @@ export type ConnectorStyle = {
mode: ConnectorMode;
};
export const MINDMAP_NODE_MAX_WIDTH = 512;
export abstract class MindmapStyleGetter {
abstract readonly root: NodeStyle;
@@ -90,6 +93,7 @@ export class StyleOne extends MindmapStyleGetter {
radius: 8,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 4,
strokeColor: '#53b2ef',
@@ -161,6 +165,7 @@ export class StyleOne extends MindmapStyleGetter {
radius: 8,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 3,
strokeColor: color,
@@ -198,6 +203,7 @@ export class StyleTwo extends MindmapStyleGetter {
radius: 3,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 3,
strokeColor: DefaultTheme.black,
@@ -271,6 +277,7 @@ export class StyleTwo extends MindmapStyleGetter {
radius: 3,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 3,
strokeColor: DefaultTheme.black,
@@ -308,6 +315,7 @@ export class StyleThree extends MindmapStyleGetter {
radius: 10,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 0,
strokeColor: 'transparent',
@@ -343,6 +351,7 @@ export class StyleThree extends MindmapStyleGetter {
radius: 10,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 2,
strokeColor,
@@ -420,6 +429,7 @@ export class StyleFour extends MindmapStyleGetter {
radius: 0,
textResizing: TextResizing.AUTO_WIDTH_AND_HEIGHT,
maxWidth: MINDMAP_NODE_MAX_WIDTH,
strokeWidth: 0,
strokeColor: 'transparent',