@mun-ui/ui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/dev-protocol.mjs +94 -0
  5. package/bin/formatter.mjs +109 -0
  6. package/bin/hot-reload.mjs +38 -0
  7. package/bin/mun.mjs +521 -0
  8. package/bin/native.mjs +133 -0
  9. package/bin/pnpm-workspace.mjs +58 -0
  10. package/bin/program-patch.mjs +104 -0
  11. package/bin/project.mjs +322 -0
  12. package/bin/watch.mjs +316 -0
  13. package/bin/workflow.mjs +261 -0
  14. package/dist/astro.d.ts +3 -0
  15. package/dist/astro.d.ts.map +1 -0
  16. package/dist/astro.js +3 -0
  17. package/dist/astro.js.map +1 -0
  18. package/dist/closures.d.ts +2 -0
  19. package/dist/closures.d.ts.map +1 -0
  20. package/dist/closures.js +2 -0
  21. package/dist/closures.js.map +1 -0
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.d.ts.map +1 -0
  24. package/dist/compiler/index.js +2 -0
  25. package/dist/compiler/index.js.map +1 -0
  26. package/dist/core.d.ts +3 -0
  27. package/dist/core.d.ts.map +1 -0
  28. package/dist/core.js +3 -0
  29. package/dist/core.js.map +1 -0
  30. package/dist/experimental.d.ts +2 -0
  31. package/dist/experimental.d.ts.map +1 -0
  32. package/dist/experimental.js +2 -0
  33. package/dist/experimental.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +3 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsx-dev-runtime.d.ts +2 -0
  39. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  40. package/dist/jsx-dev-runtime.js +2 -0
  41. package/dist/jsx-dev-runtime.js.map +1 -0
  42. package/dist/jsx-runtime.d.ts +2 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/jsx-runtime.js.map +1 -0
  46. package/dist/legacy.d.ts +3 -0
  47. package/dist/legacy.d.ts.map +1 -0
  48. package/dist/legacy.js +3 -0
  49. package/dist/legacy.js.map +1 -0
  50. package/dist/mun.d.ts +5 -0
  51. package/dist/mun.d.ts.map +1 -0
  52. package/dist/mun.js +4 -0
  53. package/dist/mun.js.map +1 -0
  54. package/dist/progressive-blur/index.d.ts +8 -0
  55. package/dist/progressive-blur/index.d.ts.map +1 -0
  56. package/dist/progressive-blur/index.js +8 -0
  57. package/dist/progressive-blur/index.js.map +1 -0
  58. package/dist/progressive-blur/plan.d.ts +3 -0
  59. package/dist/progressive-blur/plan.d.ts.map +1 -0
  60. package/dist/progressive-blur/plan.js +3 -0
  61. package/dist/progressive-blur/plan.js.map +1 -0
  62. package/dist/react-types.d.ts +2 -0
  63. package/dist/react-types.d.ts.map +1 -0
  64. package/dist/react-types.js +2 -0
  65. package/dist/react-types.js.map +1 -0
  66. package/dist/rendering-quality.d.ts +4 -0
  67. package/dist/rendering-quality.d.ts.map +1 -0
  68. package/dist/rendering-quality.js +4 -0
  69. package/dist/rendering-quality.js.map +1 -0
  70. package/dist/state.d.ts +2 -0
  71. package/dist/state.d.ts.map +1 -0
  72. package/dist/state.js +2 -0
  73. package/dist/state.js.map +1 -0
  74. package/dist/types.d.ts +2 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/vite.d.ts +2 -0
  79. package/dist/vite.d.ts.map +1 -0
  80. package/dist/vite.js +2 -0
  81. package/dist/vite.js.map +1 -0
  82. package/editors/install.mjs +102 -0
  83. package/editors/lsp/mun-lsp.mjs +123 -0
  84. package/editors/lsp/service.mjs +306 -0
  85. package/editors/lsp/source.mjs +58 -0
  86. package/editors/vscode/client.mjs +40 -0
  87. package/editors/vscode/dev-client.mjs +83 -0
  88. package/editors/vscode/discovery.mjs +46 -0
  89. package/editors/vscode/export.mjs +42 -0
  90. package/editors/vscode/extension.cjs +226 -0
  91. package/editors/vscode/language-configuration.json +15 -0
  92. package/editors/vscode/package.json +119 -0
  93. package/editors/vscode/protocol.mjs +29 -0
  94. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  95. package/native/Cargo.lock +3581 -0
  96. package/native/Cargo.toml +21 -0
  97. package/native/README.md +21 -0
  98. package/native/mun-native/Cargo.toml +23 -0
  99. package/native/mun-native/src/accessibility.rs +738 -0
  100. package/native/mun-native/src/dev.rs +604 -0
  101. package/native/mun-native/src/lib.rs +2676 -0
  102. package/native/mun-native/src/main.rs +204 -0
  103. package/native/mun-native/src/offscreen.rs +393 -0
  104. package/native/mun-native/src/rect.wgsl +63 -0
  105. package/native/mun-native/src/text.rs +310 -0
  106. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  107. package/native/mun-native/tests/stress.rs +408 -0
  108. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  109. package/native/mun-runtime/Cargo.toml +13 -0
  110. package/native/mun-runtime/src/accessibility.rs +193 -0
  111. package/native/mun-runtime/src/collection.rs +1073 -0
  112. package/native/mun-runtime/src/gesture.rs +1070 -0
  113. package/native/mun-runtime/src/input.rs +325 -0
  114. package/native/mun-runtime/src/ir.rs +782 -0
  115. package/native/mun-runtime/src/kinetics.rs +500 -0
  116. package/native/mun-runtime/src/layout.rs +173 -0
  117. package/native/mun-runtime/src/layout_cache.rs +209 -0
  118. package/native/mun-runtime/src/lib.rs +49 -0
  119. package/native/mun-runtime/src/motion.rs +1162 -0
  120. package/native/mun-runtime/src/retained.rs +574 -0
  121. package/native/mun-runtime/src/runtime.rs +7078 -0
  122. package/native/mun-runtime/src/scene.rs +530 -0
  123. package/native/mun-runtime/src/scroll.rs +521 -0
  124. package/native/mun-runtime/src/scroll_view.rs +220 -0
  125. package/native/mun-runtime/src/text_edit.rs +670 -0
  126. package/native/mun-runtime/src/timeline.rs +1534 -0
  127. package/native/mun-runtime/src/validate.rs +677 -0
  128. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  129. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  130. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  131. package/native/mun-runtime/tests/hot_update.rs +367 -0
  132. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  133. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  134. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  135. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  136. package/native/mun-runtime/tests/native_demo.rs +285 -0
  137. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  138. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  139. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  140. package/native/mun-runtime/tests/text_editing.rs +491 -0
  141. package/package.json +210 -3
  142. package/schemas/README.md +19 -0
  143. package/schemas/semantic-ui-ir-v1.schema.json +1972 -0
  144. package/templates/native/App.mun +15 -0
  145. package/templates/native/gitignore +3 -0
  146. package/templates/native/mun.toml +8 -0
  147. package/templates/project/gitignore +5 -0
  148. package/templates/project/index.html +13 -0
  149. package/templates/project/package.json +21 -0
  150. package/templates/project/src/App.mun +13 -0
  151. package/templates/project/src/index.css +21 -0
  152. package/templates/project/src/main.ts +5 -0
  153. package/templates/project/tsconfig.json +20 -0
  154. package/templates/project/vite.config.ts +6 -0
  155. package/templates/vite/src/App.css +134 -0
  156. package/templates/vite/src/App.tsx +91 -0
  157. package/templates/vite/src/index.css +23 -0
  158. package/templates/vite/vite.config.ts +10 -0
@@ -0,0 +1,491 @@
1
+ use mun_runtime::input::ClipboardRequest;
2
+ use mun_runtime::text_edit::{Composition, TextEdit};
3
+ use mun_runtime::{
4
+ ButtonState, ImeRequest, InputEvent, InputPoint, KeyState, LogicalKey, Modifiers, PhysicalKey,
5
+ PointerButton, PointerId, Runtime,
6
+ };
7
+ fn runtime() -> Runtime {
8
+ Runtime::from_json(r#"{"version":1,"sourceLanguage":"mun","entry":"Test","states":[{"name":"name","initial":"Ada"}],"root":{"kind":"window","id":"window","title":"Test","child":{"kind":"column","id":"stack","children":[{"kind":"textField","id":"field","state":"name"},{"kind":"textField","id":"other","state":"name"}]}}}"#).unwrap()
9
+ }
10
+ fn input(runtime: &mut Runtime, event: InputEvent) {
11
+ runtime.handle_input(event, 400.0, 300.0).unwrap();
12
+ }
13
+ fn key(runtime: &mut Runtime, logical: LogicalKey) {
14
+ input(
15
+ runtime,
16
+ InputEvent::Key {
17
+ logical,
18
+ physical: PhysicalKey::Other,
19
+ state: KeyState::Pressed,
20
+ repeat: false,
21
+ },
22
+ );
23
+ }
24
+ #[test]
25
+ fn composition_binding_scene_focus_and_commit_contract() {
26
+ let mut r = runtime();
27
+ assert!(r.focus_action("field"));
28
+ input(&mut r, InputEvent::TextEdit(TextEdit::SelectAll));
29
+ input(
30
+ &mut r,
31
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
32
+ text: "한".into(),
33
+ selection: Some((1, 1)),
34
+ })),
35
+ );
36
+ // Bound views see a partial syllable immediately.
37
+ assert_eq!(r.state_value("name").unwrap(), "한");
38
+ assert_eq!(
39
+ r.build_accessibility_tree(400.0, 300.0)
40
+ .unwrap()
41
+ .node("field")
42
+ .unwrap()
43
+ .value
44
+ .as_deref(),
45
+ Some("한")
46
+ );
47
+ assert_eq!(
48
+ r.build_scene(400.0, 300.0)
49
+ .unwrap()
50
+ .texts
51
+ .iter()
52
+ .find(|text| text.id == "field:text")
53
+ .unwrap()
54
+ .text,
55
+ "한"
56
+ );
57
+ // The IME owns editing keys while composing.
58
+ key(&mut r, LogicalKey::Backspace);
59
+ assert_eq!(r.state_value("name").unwrap(), "한");
60
+ // Cancelling restores the committed text; re-composing then committing
61
+ // replaces the still-selected text.
62
+ input(&mut r, InputEvent::TextEdit(TextEdit::CompositionCancel));
63
+ assert_eq!(r.state_value("name").unwrap(), "Ada");
64
+ input(
65
+ &mut r,
66
+ InputEvent::TextEdit(TextEdit::CompositionCommit("한글".into())),
67
+ );
68
+ assert_eq!(r.state_value("name").unwrap(), "한글");
69
+ key(&mut r, LogicalKey::ArrowLeft);
70
+ input(
71
+ &mut r,
72
+ InputEvent::TextInput {
73
+ text: "😀".into()
74
+ },
75
+ );
76
+ assert_eq!(r.state_value("name").unwrap(), "한😀글");
77
+ input(
78
+ &mut r,
79
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
80
+ text: "ㅎ".into(),
81
+ selection: None,
82
+ })),
83
+ );
84
+ // Moving focus deliberately commits the visible preedit into the field that
85
+ // owned it (native text-view semantics) and asks the platform to discard its
86
+ // own marked text so the IME cannot continue the syllable elsewhere.
87
+ assert!(r.focus_action("other"));
88
+ assert!(r.focused_text_editor().is_none());
89
+ assert_eq!(r.state_value("name").unwrap(), "한😀ㅎ글");
90
+ assert_eq!(r.take_ime_requests(), vec![ImeRequest::DiscardComposition]);
91
+ }
92
+ #[test]
93
+ fn clipboard_is_a_semantic_service_and_stale_paste_cannot_retarget() {
94
+ let mut r = runtime();
95
+ r.focus_action("field");
96
+ input(
97
+ &mut r,
98
+ InputEvent::ModifiersChanged(Modifiers {
99
+ control: true,
100
+ ..Default::default()
101
+ }),
102
+ );
103
+ key(&mut r, LogicalKey::Character("a".into()));
104
+ key(&mut r, LogicalKey::Character("c".into()));
105
+ assert_eq!(
106
+ r.take_clipboard_requests(),
107
+ vec![ClipboardRequest::Write("Ada".into())]
108
+ );
109
+ key(&mut r, LogicalKey::Character("x".into()));
110
+ assert_eq!(r.state_value("name").unwrap(), "Ada");
111
+ assert_eq!(
112
+ r.take_clipboard_requests(),
113
+ vec![ClipboardRequest::Cut {
114
+ request: 1,
115
+ text: "Ada".into()
116
+ }]
117
+ );
118
+ input(
119
+ &mut r,
120
+ InputEvent::ClipboardWriteCompleted {
121
+ request: 1,
122
+ success: true,
123
+ },
124
+ );
125
+ assert_eq!(r.state_value("name").unwrap(), "");
126
+ key(&mut r, LogicalKey::Character("v".into()));
127
+ assert_eq!(
128
+ r.take_clipboard_requests(),
129
+ vec![ClipboardRequest::Read {
130
+ request: 2,
131
+ target: "field".into()
132
+ }]
133
+ );
134
+ // Focus moved before the asynchronous response: the stale paste is dropped.
135
+ r.focus_action("other");
136
+ input(
137
+ &mut r,
138
+ InputEvent::ClipboardReadCompleted {
139
+ request: 2,
140
+ text: Some("wrong".into()),
141
+ },
142
+ );
143
+ assert_eq!(r.state_value("name").unwrap(), "");
144
+ key(&mut r, LogicalKey::Character("v".into()));
145
+ assert_eq!(
146
+ r.take_clipboard_requests(),
147
+ vec![ClipboardRequest::Read {
148
+ request: 3,
149
+ target: "other".into()
150
+ }]
151
+ );
152
+ input(
153
+ &mut r,
154
+ InputEvent::ClipboardReadCompleted {
155
+ request: 3,
156
+ text: Some("한\r\n국\u{7}".into()),
157
+ },
158
+ );
159
+ assert_eq!(r.state_value("name").unwrap(), "한 국");
160
+ input(&mut r, InputEvent::WindowFocusChanged(false));
161
+ key(&mut r, LogicalKey::Character("x".into()));
162
+ assert!(r.take_clipboard_requests().is_empty());
163
+ }
164
+
165
+ #[test]
166
+ fn cut_failure_or_changed_selection_never_deletes_text() {
167
+ let mut r = runtime();
168
+ r.focus_action("field");
169
+ input(
170
+ &mut r,
171
+ InputEvent::ModifiersChanged(Modifiers {
172
+ control: true,
173
+ ..Default::default()
174
+ }),
175
+ );
176
+ key(&mut r, LogicalKey::Character("a".into()));
177
+ key(&mut r, LogicalKey::Character("x".into()));
178
+ input(
179
+ &mut r,
180
+ InputEvent::ClipboardWriteCompleted {
181
+ request: 1,
182
+ success: false,
183
+ },
184
+ );
185
+ assert_eq!(r.state_value("name").unwrap(), "Ada");
186
+ key(&mut r, LogicalKey::Character("x".into()));
187
+ input(
188
+ &mut r,
189
+ InputEvent::TextEdit(TextEdit::Left { select: false }),
190
+ );
191
+ input(
192
+ &mut r,
193
+ InputEvent::ClipboardWriteCompleted {
194
+ request: 2,
195
+ success: true,
196
+ },
197
+ );
198
+ assert_eq!(r.state_value("name").unwrap(), "Ada");
199
+ }
200
+
201
+ const WIDE_FIELD: &str = r#"{"version":1,"sourceLanguage":"mun","entry":"Test","states":[{"name":"name","initial":"한국 hi"},{"name":"flag","initial":false}],"root":{"kind":"window","id":"window","title":"Test","child":{"kind":"column","id":"stack","layout":{"alignment":"leading","maxWidth":"infinity","maxHeight":"infinity"},"children":[{"kind":"textField","id":"field","state":"name","layout":{"width":{"kind":"literal","value":300},"height":{"kind":"literal","value":40}}},{"kind":"action","id":"button","label":"Go","action":{"kind":"toggle-state","state":"flag"}}]}}}"#;
202
+
203
+ fn rect<'a>(scene: &'a mun_runtime::Scene, id: &str) -> Option<&'a mun_runtime::scene::SceneRect> {
204
+ scene.rects.iter().find(|item| item.id == id)
205
+ }
206
+
207
+ fn press_at(r: &mut Runtime, x: f32, y: f32) {
208
+ input(
209
+ r,
210
+ InputEvent::PointerMoved {
211
+ pointer: PointerId::MOUSE,
212
+ position: InputPoint::new(x, y),
213
+ },
214
+ );
215
+ input(
216
+ r,
217
+ InputEvent::PointerButton {
218
+ pointer: PointerId::MOUSE,
219
+ button: PointerButton::Primary,
220
+ state: ButtonState::Pressed,
221
+ },
222
+ );
223
+ }
224
+
225
+ fn release(r: &mut Runtime) {
226
+ input(
227
+ r,
228
+ InputEvent::PointerButton {
229
+ pointer: PointerId::MOUSE,
230
+ button: PointerButton::Primary,
231
+ state: ButtonState::Released,
232
+ },
233
+ );
234
+ }
235
+
236
+ /// Headless metrics: 9.6pt per grapheme at 16pt, text origin at field.x + 12.
237
+ fn caret_x(boundary: usize) -> f32 {
238
+ 12.0 + boundary as f32 * 9.6
239
+ }
240
+
241
+ #[test]
242
+ fn caret_selection_and_preedit_are_presented_from_shaped_geometry() {
243
+ let mut r = Runtime::from_json(WIDE_FIELD).unwrap();
244
+ let scene = r.build_scene(400.0, 300.0).unwrap();
245
+ assert!(
246
+ rect(&scene, "field:caret").is_none(),
247
+ "unfocused fields draw no caret"
248
+ );
249
+
250
+ r.focus_action("field");
251
+ input(
252
+ &mut r,
253
+ InputEvent::TextEdit(TextEdit::End { select: false }),
254
+ );
255
+ let frame = r.build_frame(400.0, 300.0).unwrap();
256
+ let caret = rect(&frame.scene, "field:caret").expect("focused caret");
257
+ assert!((caret.rect.x + caret.rect.width * 0.5 - caret_x(5)).abs() < 0.01);
258
+ let ime = frame.ime_cursor_area.expect("IME caret area");
259
+ assert_eq!(ime, caret.rect);
260
+
261
+ input(
262
+ &mut r,
263
+ InputEvent::TextEdit(TextEdit::Home { select: false }),
264
+ );
265
+ input(
266
+ &mut r,
267
+ InputEvent::TextEdit(TextEdit::Right { select: true }),
268
+ );
269
+ input(
270
+ &mut r,
271
+ InputEvent::TextEdit(TextEdit::Right { select: true }),
272
+ );
273
+ let scene = r.build_scene(400.0, 300.0).unwrap();
274
+ let selection = rect(&scene, "field:selection").expect("selection highlight");
275
+ assert!((selection.rect.x - caret_x(0)).abs() < 0.01);
276
+ assert!((selection.rect.width - 2.0 * 9.6).abs() < 0.01);
277
+
278
+ input(
279
+ &mut r,
280
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
281
+ text: "にほん".into(),
282
+ selection: Some((0, 2)),
283
+ })),
284
+ );
285
+ let scene = r.build_scene(400.0, 300.0).unwrap();
286
+ assert!(rect(&scene, "field:selection").is_none());
287
+ let preedit = rect(&scene, "field:preedit").expect("preedit underline");
288
+ assert!((preedit.rect.width - 3.0 * 9.6).abs() < 0.01);
289
+ let focused_segment = rect(&scene, "field:preedit-selection").expect("composition target");
290
+ assert!((focused_segment.rect.width - 2.0 * 9.6).abs() < 0.01);
291
+ assert_eq!(r.state_value("name").unwrap(), "にほん hi");
292
+ }
293
+
294
+ #[test]
295
+ fn composition_survives_frames_and_unrelated_reconciliation() {
296
+ let mut r = Runtime::from_json(WIDE_FIELD).unwrap();
297
+ r.focus_action("field");
298
+ input(
299
+ &mut r,
300
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
301
+ text: "하".into(),
302
+ selection: None,
303
+ })),
304
+ );
305
+ for _ in 0..5 {
306
+ r.step(1.0 / 60.0);
307
+ r.build_frame(400.0, 300.0).unwrap();
308
+ r.build_accessibility_tree(400.0, 300.0).unwrap();
309
+ r.build_frame(320.0, 200.0).unwrap();
310
+ }
311
+ // An unrelated state transaction reconciles the tree but must not reset preedit.
312
+ r.activate_action("button");
313
+ let editor = r.focused_text_editor().expect("editor survives");
314
+ assert_eq!(editor.composition().unwrap().text, "하");
315
+ assert!(r.take_ime_requests().is_empty());
316
+ }
317
+
318
+ #[test]
319
+ fn pointer_maps_to_shaped_positions_drag_selects_and_shift_extends() {
320
+ let mut r = Runtime::from_json(WIDE_FIELD).unwrap();
321
+ // Click between 국 and the space (boundary 2), slightly right of the stop.
322
+ press_at(&mut r, caret_x(2) + 2.0, 20.0);
323
+ release(&mut r);
324
+ assert_eq!(r.focused_action(), Some("field"));
325
+ assert_eq!(r.focused_text_editor().unwrap().cursor(), 2);
326
+
327
+ // Drag from boundary 1 to boundary 4 creates and updates a selection.
328
+ press_at(&mut r, caret_x(1), 20.0);
329
+ input(
330
+ &mut r,
331
+ InputEvent::PointerMoved {
332
+ pointer: PointerId::MOUSE,
333
+ position: InputPoint::new(caret_x(4) - 1.0, 22.0),
334
+ },
335
+ );
336
+ release(&mut r);
337
+ assert_eq!(r.focused_text_editor().unwrap().selected_text(), "국 h");
338
+
339
+ // Shift-click extends from the anchor.
340
+ input(
341
+ &mut r,
342
+ InputEvent::ModifiersChanged(Modifiers {
343
+ shift: true,
344
+ ..Default::default()
345
+ }),
346
+ );
347
+ press_at(&mut r, caret_x(5) + 30.0, 20.0);
348
+ release(&mut r);
349
+ assert_eq!(r.focused_text_editor().unwrap().selected_text(), "국 hi");
350
+ assert_eq!(r.state_value("name").unwrap(), "한국 hi");
351
+ }
352
+
353
+ #[test]
354
+ fn click_relocation_commits_preedit_then_moves_caret() {
355
+ let mut r = Runtime::from_json(WIDE_FIELD).unwrap();
356
+ r.focus_action("field");
357
+ input(
358
+ &mut r,
359
+ InputEvent::TextEdit(TextEdit::Home { select: false }),
360
+ );
361
+ input(
362
+ &mut r,
363
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
364
+ text: "가".into(),
365
+ selection: None,
366
+ })),
367
+ );
368
+ // Presentation is "가한국 hi"; click after 국 (boundary 3 of presentation).
369
+ press_at(&mut r, caret_x(3), 20.0);
370
+ release(&mut r);
371
+ assert_eq!(r.state_value("name").unwrap(), "가한국 hi");
372
+ let editor = r.focused_text_editor().unwrap();
373
+ assert!(editor.composition().is_none());
374
+ assert_eq!(editor.cursor(), 3);
375
+ assert_eq!(r.take_ime_requests(), vec![ImeRequest::DiscardComposition]);
376
+ // Composition then continues at the relocated caret.
377
+ input(
378
+ &mut r,
379
+ InputEvent::TextEdit(TextEdit::CompositionCommit("다".into())),
380
+ );
381
+ assert_eq!(r.state_value("name").unwrap(), "가한국다 hi");
382
+ }
383
+
384
+ #[test]
385
+ fn paste_failure_unavailable_content_and_composition_never_mutate() {
386
+ let mut r = Runtime::from_json(WIDE_FIELD).unwrap();
387
+ r.focus_action("field");
388
+ input(
389
+ &mut r,
390
+ InputEvent::ModifiersChanged(Modifiers {
391
+ control: true,
392
+ ..Default::default()
393
+ }),
394
+ );
395
+ key(&mut r, LogicalKey::Character("v".into()));
396
+ let [ClipboardRequest::Read { request, .. }] = r.take_clipboard_requests()[..] else {
397
+ panic!("one read request");
398
+ };
399
+ input(
400
+ &mut r,
401
+ InputEvent::ClipboardReadCompleted {
402
+ request,
403
+ text: None,
404
+ },
405
+ );
406
+ assert_eq!(r.state_value("name").unwrap(), "한국 hi");
407
+ // A response for an unknown request id is ignored.
408
+ input(
409
+ &mut r,
410
+ InputEvent::ClipboardReadCompleted {
411
+ request: request + 40,
412
+ text: Some("x".into()),
413
+ },
414
+ );
415
+ assert_eq!(r.state_value("name").unwrap(), "한국 hi");
416
+ // A newer request supersedes an older one.
417
+ key(&mut r, LogicalKey::Character("v".into()));
418
+ key(&mut r, LogicalKey::Character("v".into()));
419
+ let requests = r.take_clipboard_requests();
420
+ let ids = requests
421
+ .iter()
422
+ .map(|item| match item {
423
+ ClipboardRequest::Read { request, .. } => *request,
424
+ _ => panic!("read"),
425
+ })
426
+ .collect::<Vec<_>>();
427
+ input(
428
+ &mut r,
429
+ InputEvent::ClipboardReadCompleted {
430
+ request: ids[0],
431
+ text: Some("old".into()),
432
+ },
433
+ );
434
+ assert_eq!(r.state_value("name").unwrap(), "한국 hi");
435
+ // Composition started while the read was in flight: the paste is dropped and
436
+ // the preedit stays uncommitted.
437
+ input(
438
+ &mut r,
439
+ InputEvent::TextEdit(TextEdit::CompositionUpdate(Composition {
440
+ text: "ㅎ".into(),
441
+ selection: None,
442
+ })),
443
+ );
444
+ input(
445
+ &mut r,
446
+ InputEvent::ClipboardReadCompleted {
447
+ request: ids[1],
448
+ text: Some("new".into()),
449
+ },
450
+ );
451
+ assert_eq!(r.state_value("name").unwrap(), "한국 hiㅎ");
452
+ assert_eq!(
453
+ r.focused_text_editor().unwrap().composition().unwrap().text,
454
+ "ㅎ"
455
+ );
456
+ }
457
+
458
+ #[test]
459
+ fn platform_conventions_choose_word_and_line_granularity() {
460
+ let mut r = runtime();
461
+ r.set_platform_conventions(mun_runtime::PlatformConventions {
462
+ apple_text_navigation: true,
463
+ });
464
+ r.focus_action("field");
465
+ input(
466
+ &mut r,
467
+ InputEvent::TextEdit(TextEdit::Insert(" Lovelace".into())),
468
+ );
469
+ input(
470
+ &mut r,
471
+ InputEvent::ModifiersChanged(Modifiers {
472
+ alt: true,
473
+ ..Default::default()
474
+ }),
475
+ );
476
+ key(&mut r, LogicalKey::ArrowLeft);
477
+ assert_eq!(r.focused_text_editor().unwrap().cursor(), 4);
478
+ key(&mut r, LogicalKey::Backspace);
479
+ assert_eq!(r.state_value("name").unwrap(), "Lovelace");
480
+ input(
481
+ &mut r,
482
+ InputEvent::ModifiersChanged(Modifiers {
483
+ meta: true,
484
+ ..Default::default()
485
+ }),
486
+ );
487
+ key(&mut r, LogicalKey::ArrowRight);
488
+ assert_eq!(r.focused_text_editor().unwrap().cursor(), 8);
489
+ key(&mut r, LogicalKey::Character("a".into()));
490
+ assert_eq!(r.focused_text_editor().unwrap().selected_text(), "Lovelace");
491
+ }