@@ -31,6 +31,67 @@ sealed class LabelContext with _$LabelContext {
3131 @Default (TextSelection .collapsed (offset: 0 )) TextSelection selection,
3232 }) = MarkdownContext ;
3333
34+ LabelContext toMode (LabelMode mode) {
35+ if (tool.mode == mode) return this ;
36+ final newTool = tool.copyWith (mode: mode);
37+ switch (mode) {
38+ case LabelMode .text:
39+ return TextContext (
40+ tool: newTool,
41+ textPainter: textPainter,
42+ zoom: zoom,
43+ selection: selection,
44+ element: switch (this ) {
45+ TextContext e => e.element,
46+ MarkdownContext e =>
47+ e.element == null
48+ ? null
49+ : TextElement (
50+ id: e.element! .id,
51+ position: e.element! .position,
52+ scale: e.element! .scale,
53+ foreground: e.element! .foreground,
54+ styleSheet: e.element! .styleSheet,
55+ constraint: e.element! .constraint,
56+ extra: e.element! .extra,
57+ area: txt.TextArea (
58+ paragraph: txt.TextParagraph (
59+ textSpans: [
60+ txt.InlineSpan .text (text: e.element! .text),
61+ ],
62+ ),
63+ areaProperty: e.element! .areaProperty,
64+ ),
65+ ),
66+ },
67+ );
68+ case LabelMode .markdown:
69+ return MarkdownContext (
70+ tool: newTool,
71+ textPainter: textPainter,
72+ zoom: zoom,
73+ selection: selection,
74+ element: switch (this ) {
75+ MarkdownContext e => e.element,
76+ TextContext e =>
77+ e.element == null
78+ ? null
79+ : MarkdownElement (
80+ id: e.element! .id,
81+ position: e.element! .position,
82+ scale: e.element! .scale,
83+ foreground: e.element! .foreground,
84+ styleSheet: e.element! .styleSheet,
85+ constraint: e.element! .constraint,
86+ extra: e.element! .extra,
87+ text: e.element! .area.paragraph.text,
88+ areaProperty: e.element! .area.areaProperty,
89+ ),
90+ },
91+ );
92+ }
93+ }
94+
3495 bool get isCreating => true ;
3596
3697 String ? get text => labelElement? .text;
0 commit comments