@xincli/opentui-core 0.4.6 → 0.4.7

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 (619) hide show
  1. package/LICENSE +21 -0
  2. package/NativeSpanFeed.d.ts +52 -0
  3. package/README.md +0 -0
  4. package/Renderable.d.ts +346 -0
  5. package/animation/Timeline.d.ts +126 -0
  6. package/ansi.d.ts +17 -0
  7. package/audio.d.ts +89 -0
  8. package/buffer.d.ts +113 -0
  9. package/console.d.ts +146 -0
  10. package/edit-buffer.d.ts +97 -0
  11. package/editor-view.d.ts +72 -0
  12. package/index-m1y9e40w.js +10045 -0
  13. package/index-m1y9e40w.js.map +32 -0
  14. package/index-sqk4ajdf.js +16121 -0
  15. package/index-sqk4ajdf.js.map +58 -0
  16. package/index.d.ts +24 -0
  17. package/index.js +11709 -0
  18. package/index.js.map +35 -0
  19. package/lib/KeyHandler.d.ts +61 -0
  20. package/lib/RGBA.d.ts +42 -0
  21. package/lib/ascii.font.d.ts +508 -0
  22. package/lib/border.d.ts +51 -0
  23. package/lib/bunfs.d.ts +7 -0
  24. package/lib/clipboard.d.ts +15 -0
  25. package/lib/clock.d.ts +15 -0
  26. package/lib/data-paths.d.ts +26 -0
  27. package/lib/debounce.d.ts +42 -0
  28. package/lib/detect-links.d.ts +6 -0
  29. package/lib/env.d.ts +42 -0
  30. package/lib/extmarks-history.d.ts +17 -0
  31. package/lib/extmarks.d.ts +90 -0
  32. package/lib/hast-styled-text.d.ts +17 -0
  33. package/lib/index.d.ts +22 -0
  34. package/lib/keybinding.internal.d.ts +33 -0
  35. package/lib/objects-in-viewport.d.ts +24 -0
  36. package/lib/output.capture.d.ts +24 -0
  37. package/lib/parse.keypress-kitty.d.ts +3 -0
  38. package/lib/parse.keypress.d.ts +27 -0
  39. package/lib/parse.mouse.d.ts +30 -0
  40. package/lib/paste.d.ts +7 -0
  41. package/lib/queue.d.ts +15 -0
  42. package/lib/render-geometry.d.ts +8 -0
  43. package/lib/renderable.validations.d.ts +12 -0
  44. package/lib/scroll-acceleration.d.ts +43 -0
  45. package/lib/selection.d.ts +64 -0
  46. package/lib/singleton.d.ts +8 -0
  47. package/lib/stdin-parser.d.ts +90 -0
  48. package/lib/styled-text.d.ts +63 -0
  49. package/lib/terminal-capability-detection.d.ts +32 -0
  50. package/lib/terminal-palette.d.ts +65 -0
  51. package/lib/tree-sitter/assets/update.d.ts +12 -0
  52. package/lib/tree-sitter/client.d.ts +65 -0
  53. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  54. package/lib/tree-sitter/download-utils.d.ts +21 -0
  55. package/lib/tree-sitter/index.d.ts +7 -0
  56. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  57. package/lib/tree-sitter/parsers-config.d.ts +53 -0
  58. package/lib/tree-sitter/resolve-ft.d.ts +5 -0
  59. package/lib/tree-sitter/types.d.ts +185 -0
  60. package/lib/tree-sitter/update-assets.d.ts +3 -0
  61. package/lib/tree-sitter/update-assets.js +379 -0
  62. package/lib/tree-sitter/update-assets.js.map +12 -0
  63. package/lib/tree-sitter-styled-text.d.ts +16 -0
  64. package/lib/validate-dir-name.d.ts +1 -0
  65. package/lib/yoga.options.d.ts +32 -0
  66. package/native-event-worker-repro.worker.d.ts +1 -0
  67. package/package.json +52 -74
  68. package/parser.worker.js +1399 -0
  69. package/parser.worker.js.map +20 -0
  70. package/platform/ffi.d.ts +129 -0
  71. package/platform/runtime.d.ts +14 -0
  72. package/platform/test.d.ts +12 -0
  73. package/platform/worker.d.ts +26 -0
  74. package/platform/worker.node-test.d.ts +1 -0
  75. package/plugins/core-slot.d.ts +72 -0
  76. package/plugins/registry.d.ts +42 -0
  77. package/plugins/types.d.ts +34 -0
  78. package/post/effects.d.ts +147 -0
  79. package/post/filters.d.ts +65 -0
  80. package/post/matrices.d.ts +20 -0
  81. package/renderables/ASCIIFont.d.ts +52 -0
  82. package/renderables/Box.d.ts +85 -0
  83. package/renderables/Code.d.ts +97 -0
  84. package/renderables/Diff.d.ts +147 -0
  85. package/renderables/EditBufferRenderable.d.ts +238 -0
  86. package/renderables/FrameBuffer.d.ts +16 -0
  87. package/renderables/Input.d.ts +72 -0
  88. package/renderables/LineNumberRenderable.d.ts +78 -0
  89. package/renderables/Markdown.d.ts +255 -0
  90. package/renderables/ScrollBar.d.ts +77 -0
  91. package/renderables/ScrollBox.d.ts +128 -0
  92. package/renderables/Select.d.ts +122 -0
  93. package/renderables/Slider.d.ts +47 -0
  94. package/renderables/TabSelect.d.ts +98 -0
  95. package/renderables/Text.d.ts +36 -0
  96. package/renderables/TextBufferRenderable.d.ts +107 -0
  97. package/renderables/TextNode.d.ts +92 -0
  98. package/renderables/TextTable.d.ts +154 -0
  99. package/renderables/Textarea.d.ts +65 -0
  100. package/renderables/TimeToFirstDraw.d.ts +24 -0
  101. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  102. package/renderables/composition/VRenderable.d.ts +16 -0
  103. package/renderables/composition/constructs.d.ts +35 -0
  104. package/renderables/composition/vnode.d.ts +46 -0
  105. package/renderables/index.d.ts +23 -0
  106. package/renderables/markdown-parser.d.ts +11 -0
  107. package/renderer-theme-mode.d.ts +29 -0
  108. package/renderer.d.ts +601 -0
  109. package/runtime-plugin-support-configure.d.ts +4 -0
  110. package/runtime-plugin-support-configure.js +36 -0
  111. package/runtime-plugin-support-configure.js.map +1 -0
  112. package/runtime-plugin-support-configure.node.js +15 -0
  113. package/runtime-plugin-support.d.ts +3 -0
  114. package/runtime-plugin-support.js +5 -0
  115. package/runtime-plugin-support.js.map +1 -0
  116. package/runtime-plugin-support.node.js +15 -0
  117. package/runtime-plugin.d.ts +16 -0
  118. package/runtime-plugin.js +473 -0
  119. package/runtime-plugin.js.map +1 -0
  120. package/runtime-plugin.node.js +15 -0
  121. package/syntax-style.d.ts +61 -0
  122. package/testing/bun-test-node.d.ts +87 -0
  123. package/testing/manual-clock.d.ts +17 -0
  124. package/testing/mock-keys.d.ts +81 -0
  125. package/testing/mock-mouse.d.ts +38 -0
  126. package/testing/mock-tree-sitter-client.d.ts +27 -0
  127. package/testing/spy.d.ts +7 -0
  128. package/testing/terminal-capabilities.d.ts +7 -0
  129. package/testing/test-recorder.d.ts +61 -0
  130. package/testing/test-renderer.d.ts +54 -0
  131. package/testing/test-streams.d.ts +12 -0
  132. package/testing.d.ts +8 -0
  133. package/testing.js +1004 -0
  134. package/testing.js.map +18 -0
  135. package/tests/yoga-upstream/tools/MeasureCounter.d.ts +16 -0
  136. package/tests/yoga-upstream/tools/utils.d.ts +11 -0
  137. package/text-buffer-view.d.ts +42 -0
  138. package/text-buffer.d.ts +66 -0
  139. package/types.d.ts +175 -0
  140. package/utils.d.ts +14 -0
  141. package/yoga.d.ts +437 -0
  142. package/yoga.js +193 -0
  143. package/yoga.js.map +9 -0
  144. package/zig-structs.d.ts +256 -0
  145. package/zig.d.ts +496 -0
  146. package/dev/keypress-debug-renderer.ts +0 -148
  147. package/dev/keypress-debug.ts +0 -43
  148. package/dev/print-env-vars.ts +0 -32
  149. package/dev/test-tmux-graphics-334.sh +0 -68
  150. package/dev/test-tmux-theme-queries.sh +0 -151
  151. package/dev/thai-debug-test.ts +0 -68
  152. package/dev/theme-mode.ts +0 -290
  153. package/docs/development.md +0 -144
  154. package/prebuilt/aarch64-android/libopentui.so +0 -0
  155. package/scripts/build-android.ts +0 -226
  156. package/scripts/build-native-termux.sh +0 -525
  157. package/scripts/build.ts +0 -530
  158. package/scripts/dist-test.ts +0 -312
  159. package/scripts/package-prebuilt.ts +0 -110
  160. package/scripts/publish.ts +0 -60
  161. package/scripts/test-node-hook.mjs +0 -16
  162. package/scripts/test-node.ts +0 -241
  163. package/scripts/vendor-deps.sh +0 -73
  164. package/src/NativeSpanFeed.ts +0 -375
  165. package/src/Renderable.ts +0 -1878
  166. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  167. package/src/animation/Timeline.test.ts +0 -2709
  168. package/src/animation/Timeline.ts +0 -598
  169. package/src/ansi.ts +0 -22
  170. package/src/audio.ts +0 -479
  171. package/src/benchmark/attenuation-benchmark.ts +0 -81
  172. package/src/benchmark/audio-playback-benchmark.ts +0 -344
  173. package/src/benchmark/box-draw-benchmark.ts +0 -1042
  174. package/src/benchmark/colormatrix-benchmark.ts +0 -123
  175. package/src/benchmark/gain-benchmark.ts +0 -80
  176. package/src/benchmark/latest-all-bench-run.json +0 -707
  177. package/src/benchmark/latest-async-bench-run.json +0 -336
  178. package/src/benchmark/latest-default-bench-run.json +0 -657
  179. package/src/benchmark/latest-large-bench-run.json +0 -707
  180. package/src/benchmark/latest-quick-bench-run.json +0 -207
  181. package/src/benchmark/layout-benchmark.ts +0 -2547
  182. package/src/benchmark/markdown-benchmark.ts +0 -1796
  183. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  184. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  185. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  186. package/src/benchmark/native-span-feed-compare.ts +0 -280
  187. package/src/benchmark/render-traversal-benchmark.ts +0 -928
  188. package/src/benchmark/text-buffer-render-benchmark.ts +0 -874
  189. package/src/benchmark/text-table-benchmark.ts +0 -948
  190. package/src/buffer.test.ts +0 -292
  191. package/src/buffer.ts +0 -564
  192. package/src/console.test.ts +0 -629
  193. package/src/console.ts +0 -1253
  194. package/src/edit-buffer.test.ts +0 -1852
  195. package/src/edit-buffer.ts +0 -417
  196. package/src/editor-view.test.ts +0 -1056
  197. package/src/editor-view.ts +0 -290
  198. package/src/index.ts +0 -25
  199. package/src/lib/KeyHandler.integration.test.ts +0 -292
  200. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  201. package/src/lib/KeyHandler.test.ts +0 -662
  202. package/src/lib/KeyHandler.ts +0 -222
  203. package/src/lib/RGBA.test.ts +0 -60
  204. package/src/lib/RGBA.ts +0 -343
  205. package/src/lib/ascii.font.ts +0 -330
  206. package/src/lib/border.test.ts +0 -83
  207. package/src/lib/border.ts +0 -170
  208. package/src/lib/bunfs.test.ts +0 -27
  209. package/src/lib/bunfs.ts +0 -18
  210. package/src/lib/clipboard.test.ts +0 -63
  211. package/src/lib/clipboard.ts +0 -41
  212. package/src/lib/clock.ts +0 -35
  213. package/src/lib/data-paths.test.ts +0 -133
  214. package/src/lib/data-paths.ts +0 -109
  215. package/src/lib/debounce.ts +0 -106
  216. package/src/lib/detect-links.test.ts +0 -98
  217. package/src/lib/detect-links.ts +0 -56
  218. package/src/lib/env.test.ts +0 -228
  219. package/src/lib/env.ts +0 -209
  220. package/src/lib/extmarks-history.ts +0 -51
  221. package/src/lib/extmarks-multiwidth.test.ts +0 -324
  222. package/src/lib/extmarks.test.ts +0 -3547
  223. package/src/lib/extmarks.ts +0 -861
  224. package/src/lib/fonts/block.json +0 -405
  225. package/src/lib/fonts/grid.json +0 -265
  226. package/src/lib/fonts/huge.json +0 -741
  227. package/src/lib/fonts/pallet.json +0 -314
  228. package/src/lib/fonts/shade.json +0 -591
  229. package/src/lib/fonts/slick.json +0 -321
  230. package/src/lib/fonts/tiny.json +0 -69
  231. package/src/lib/hast-styled-text.ts +0 -59
  232. package/src/lib/index.ts +0 -22
  233. package/src/lib/keybinding.internal.test.ts +0 -342
  234. package/src/lib/keybinding.internal.ts +0 -182
  235. package/src/lib/objects-in-viewport.test.ts +0 -789
  236. package/src/lib/objects-in-viewport.ts +0 -153
  237. package/src/lib/output.capture.ts +0 -58
  238. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -347
  239. package/src/lib/parse.keypress-kitty.test.ts +0 -712
  240. package/src/lib/parse.keypress-kitty.ts +0 -470
  241. package/src/lib/parse.keypress.test.ts +0 -2020
  242. package/src/lib/parse.keypress.ts +0 -480
  243. package/src/lib/parse.mouse.test.ts +0 -552
  244. package/src/lib/parse.mouse.ts +0 -232
  245. package/src/lib/paste.ts +0 -18
  246. package/src/lib/queue.ts +0 -65
  247. package/src/lib/render-geometry.ts +0 -36
  248. package/src/lib/renderable.validations.test.ts +0 -87
  249. package/src/lib/renderable.validations.ts +0 -83
  250. package/src/lib/scroll-acceleration.ts +0 -98
  251. package/src/lib/selection.ts +0 -261
  252. package/src/lib/singleton.ts +0 -34
  253. package/src/lib/stdin-parser.test.ts +0 -2439
  254. package/src/lib/stdin-parser.ts +0 -2007
  255. package/src/lib/styled-text.ts +0 -178
  256. package/src/lib/terminal-capability-detection.test.ts +0 -226
  257. package/src/lib/terminal-capability-detection.ts +0 -98
  258. package/src/lib/terminal-palette.test.ts +0 -954
  259. package/src/lib/terminal-palette.ts +0 -441
  260. package/src/lib/tree-sitter/assets/README.md +0 -119
  261. package/src/lib/tree-sitter/assets/update.ts +0 -360
  262. package/src/lib/tree-sitter/assets.d.ts +0 -9
  263. package/src/lib/tree-sitter/cache.test.ts +0 -291
  264. package/src/lib/tree-sitter/client.test.ts +0 -1434
  265. package/src/lib/tree-sitter/client.ts +0 -847
  266. package/src/lib/tree-sitter/default-parsers.ts +0 -133
  267. package/src/lib/tree-sitter/download-utils.ts +0 -148
  268. package/src/lib/tree-sitter/index.ts +0 -75
  269. package/src/lib/tree-sitter/parser.worker.ts +0 -1098
  270. package/src/lib/tree-sitter/parsers-config.ts +0 -81
  271. package/src/lib/tree-sitter/resolve-ft.test.ts +0 -55
  272. package/src/lib/tree-sitter/resolve-ft.ts +0 -189
  273. package/src/lib/tree-sitter/types.ts +0 -132
  274. package/src/lib/tree-sitter/update-assets.ts +0 -10
  275. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  276. package/src/lib/tree-sitter-styled-text.ts +0 -314
  277. package/src/lib/validate-dir-name.ts +0 -55
  278. package/src/lib/yoga.options.test.ts +0 -628
  279. package/src/lib/yoga.options.ts +0 -346
  280. package/src/native-event-worker-repro.test.ts +0 -48
  281. package/src/native-event-worker-repro.worker.ts +0 -9
  282. package/src/native-handle.test.ts +0 -221
  283. package/src/platform/ffi.test.ts +0 -516
  284. package/src/platform/ffi.ts +0 -653
  285. package/src/platform/runtime.test.ts +0 -52
  286. package/src/platform/runtime.ts +0 -121
  287. package/src/platform/test.ts +0 -45
  288. package/src/platform/worker-handler-cleanup.fixture.ts +0 -12
  289. package/src/platform/worker-onmessage-startup.fixture.ts +0 -10
  290. package/src/platform/worker-startup.fixture.ts +0 -9
  291. package/src/platform/worker.node-test.ts +0 -153
  292. package/src/platform/worker.ts +0 -425
  293. package/src/plugins/core-slot.ts +0 -579
  294. package/src/plugins/registry.ts +0 -402
  295. package/src/plugins/types.ts +0 -46
  296. package/src/post/effects.ts +0 -948
  297. package/src/post/filters.ts +0 -512
  298. package/src/post/matrices.ts +0 -288
  299. package/src/renderables/ASCIIFont.ts +0 -219
  300. package/src/renderables/Box.test.ts +0 -474
  301. package/src/renderables/Box.ts +0 -353
  302. package/src/renderables/Code.test.ts +0 -2388
  303. package/src/renderables/Code.ts +0 -555
  304. package/src/renderables/Diff.regression.test.ts +0 -381
  305. package/src/renderables/Diff.test.ts +0 -3212
  306. package/src/renderables/Diff.ts +0 -1278
  307. package/src/renderables/EditBufferRenderable.test.ts +0 -288
  308. package/src/renderables/EditBufferRenderable.ts +0 -1152
  309. package/src/renderables/FrameBuffer.ts +0 -47
  310. package/src/renderables/Input.test.ts +0 -1310
  311. package/src/renderables/Input.ts +0 -273
  312. package/src/renderables/LineNumberRenderable.ts +0 -725
  313. package/src/renderables/Markdown.ts +0 -2144
  314. package/src/renderables/ScrollBar.ts +0 -423
  315. package/src/renderables/ScrollBox.ts +0 -903
  316. package/src/renderables/Select.test.ts +0 -1134
  317. package/src/renderables/Select.ts +0 -535
  318. package/src/renderables/Slider.test.ts +0 -456
  319. package/src/renderables/Slider.ts +0 -342
  320. package/src/renderables/TabSelect.test.ts +0 -238
  321. package/src/renderables/TabSelect.ts +0 -447
  322. package/src/renderables/Text.selection-buffer.test.ts +0 -118
  323. package/src/renderables/Text.test.ts +0 -2662
  324. package/src/renderables/Text.ts +0 -147
  325. package/src/renderables/TextBufferRenderable.ts +0 -504
  326. package/src/renderables/TextNode.test.ts +0 -1137
  327. package/src/renderables/TextNode.ts +0 -379
  328. package/src/renderables/TextTable.test.ts +0 -1411
  329. package/src/renderables/TextTable.ts +0 -1434
  330. package/src/renderables/Textarea.ts +0 -425
  331. package/src/renderables/TimeToFirstDraw.ts +0 -89
  332. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  333. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  334. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  335. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  336. package/src/renderables/__tests__/Code.test.ts +0 -55
  337. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  338. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -827
  339. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1906
  340. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  341. package/src/renderables/__tests__/Markdown.code-colors.test.ts +0 -288
  342. package/src/renderables/__tests__/Markdown.test.ts +0 -4175
  343. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  344. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -683
  345. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  346. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2120
  347. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  348. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  349. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  350. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3275
  351. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  352. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1927
  353. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  354. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1589
  355. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  356. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  357. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  358. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  359. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  360. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  361. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  362. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  363. package/src/renderables/__tests__/markdown-parser.test.ts +0 -241
  364. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  365. package/src/renderables/composition/README.md +0 -8
  366. package/src/renderables/composition/VRenderable.ts +0 -32
  367. package/src/renderables/composition/constructs.ts +0 -127
  368. package/src/renderables/composition/vnode.ts +0 -277
  369. package/src/renderables/index.ts +0 -23
  370. package/src/renderables/markdown-parser.ts +0 -79
  371. package/src/renderer-theme-mode.ts +0 -199
  372. package/src/renderer.ts +0 -4975
  373. package/src/runtime-plugin-support-configure.ts +0 -63
  374. package/src/runtime-plugin-support.ts +0 -13
  375. package/src/runtime-plugin.ts +0 -626
  376. package/src/specs/terminal-startup.md +0 -64
  377. package/src/syntax-style.test.ts +0 -841
  378. package/src/syntax-style.ts +0 -274
  379. package/src/testing/README.md +0 -219
  380. package/src/testing/bun-test-node.ts +0 -880
  381. package/src/testing/capture-spans.test.ts +0 -216
  382. package/src/testing/integration.test.ts +0 -276
  383. package/src/testing/manual-clock.ts +0 -117
  384. package/src/testing/mock-keys.test.ts +0 -1378
  385. package/src/testing/mock-keys.ts +0 -457
  386. package/src/testing/mock-mouse.test.ts +0 -218
  387. package/src/testing/mock-mouse.ts +0 -247
  388. package/src/testing/mock-tree-sitter-client.ts +0 -81
  389. package/src/testing/spy.ts +0 -13
  390. package/src/testing/terminal-capabilities.ts +0 -47
  391. package/src/testing/test-recorder.test.ts +0 -410
  392. package/src/testing/test-recorder.ts +0 -133
  393. package/src/testing/test-renderer.ts +0 -375
  394. package/src/testing/test-renderer.wait.test.ts +0 -278
  395. package/src/testing/test-streams.ts +0 -31
  396. package/src/testing.ts +0 -9
  397. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  398. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  399. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  400. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  401. package/src/tests/allocator-stats.test.ts +0 -53
  402. package/src/tests/audio.test.ts +0 -303
  403. package/src/tests/destroy-during-render.test.ts +0 -200
  404. package/src/tests/destroy-on-exit.fixture.ts +0 -36
  405. package/src/tests/destroy-on-exit.test.ts +0 -62
  406. package/src/tests/ffi-borrowed-pointer-callsites.test.ts +0 -153
  407. package/src/tests/hover-cursor.test.ts +0 -98
  408. package/src/tests/native-backed-measurement-lifecycle.test.ts +0 -133
  409. package/src/tests/native-backed-measurement-parity.test.ts +0 -322
  410. package/src/tests/native-span-feed-async.test.ts +0 -173
  411. package/src/tests/native-span-feed-close.test.ts +0 -120
  412. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  413. package/src/tests/native-span-feed-edge-cases.test.ts +0 -384
  414. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  415. package/src/tests/opacity.test.ts +0 -123
  416. package/src/tests/renderable.snapshot.test.ts +0 -524
  417. package/src/tests/renderable.test.ts +0 -1851
  418. package/src/tests/renderer.clock.test.ts +0 -270
  419. package/src/tests/renderer.console-startup.test.ts +0 -2151
  420. package/src/tests/renderer.control.test.ts +0 -458
  421. package/src/tests/renderer.core-slot-binding.test.ts +0 -962
  422. package/src/tests/renderer.cursor.test.ts +0 -26
  423. package/src/tests/renderer.custom-stdout.test.ts +0 -1112
  424. package/src/tests/renderer.destroy-during-render.test.ts +0 -147
  425. package/src/tests/renderer.focus-restore.test.ts +0 -257
  426. package/src/tests/renderer.focus.test.ts +0 -329
  427. package/src/tests/renderer.idle.test.ts +0 -219
  428. package/src/tests/renderer.input.test.ts +0 -2615
  429. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  430. package/src/tests/renderer.lifecycle.test.ts +0 -34
  431. package/src/tests/renderer.mouse.test.ts +0 -1315
  432. package/src/tests/renderer.notifications.test.ts +0 -27
  433. package/src/tests/renderer.palette.test.ts +0 -1199
  434. package/src/tests/renderer.remote.test.ts +0 -247
  435. package/src/tests/renderer.render-stats.test.ts +0 -146
  436. package/src/tests/renderer.scrollback-surface.test.ts +0 -474
  437. package/src/tests/renderer.selection.test.ts +0 -138
  438. package/src/tests/renderer.slot-registry.test.ts +0 -684
  439. package/src/tests/renderer.tracker.test.ts +0 -202
  440. package/src/tests/renderer.useMouse.test.ts +0 -83
  441. package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +0 -76
  442. package/src/tests/runtime-plugin-node-modules-import-like-string.fixture.ts +0 -48
  443. package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +0 -43
  444. package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +0 -67
  445. package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +0 -72
  446. package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +0 -44
  447. package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +0 -85
  448. package/src/tests/runtime-plugin-path-alias.fixture.ts +0 -43
  449. package/src/tests/runtime-plugin-resolve-roots.fixture.ts +0 -65
  450. package/src/tests/runtime-plugin-support-configure.fixture.ts +0 -31
  451. package/src/tests/runtime-plugin-support-late-addition.fixture.ts +0 -17
  452. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  453. package/src/tests/runtime-plugin-support.test.ts +0 -54
  454. package/src/tests/runtime-plugin-windows-file-url.fixture.ts +0 -30
  455. package/src/tests/runtime-plugin.fixture.ts +0 -40
  456. package/src/tests/runtime-plugin.test.ts +0 -369
  457. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  458. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  459. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  460. package/src/tests/scrollbox.test.ts +0 -1895
  461. package/src/tests/wrap-resize-perf.test.ts +0 -276
  462. package/src/tests/yoga-api-coverage.test.ts +0 -409
  463. package/src/tests/yoga-callback-stress.test.ts +0 -122
  464. package/src/tests/yoga-ffi.test.ts +0 -117
  465. package/src/tests/yoga-setters.test.ts +0 -921
  466. package/src/tests/yoga-upstream/YGAlignBaselineTest.test.ts +0 -124
  467. package/src/tests/yoga-upstream/YGComputedBorderTest.test.ts +0 -27
  468. package/src/tests/yoga-upstream/YGComputedMarginTest.test.ts +0 -27
  469. package/src/tests/yoga-upstream/YGComputedPaddingTest.test.ts +0 -27
  470. package/src/tests/yoga-upstream/YGDirtiedTest.test.ts +0 -157
  471. package/src/tests/yoga-upstream/YGErrataTest.test.ts +0 -40
  472. package/src/tests/yoga-upstream/YGFlexBasisAuto.test.ts +0 -23
  473. package/src/tests/yoga-upstream/YGHasNewLayout.test.ts +0 -81
  474. package/src/tests/yoga-upstream/YGMeasureCacheTest.test.ts +0 -31
  475. package/src/tests/yoga-upstream/YGMeasureTest.test.ts +0 -70
  476. package/src/tests/yoga-upstream/generated/YGAbsolutePositionTest.test.ts +0 -1864
  477. package/src/tests/yoga-upstream/generated/YGAlignContentTest.test.ts +0 -5829
  478. package/src/tests/yoga-upstream/generated/YGAlignItemsTest.test.ts +0 -2444
  479. package/src/tests/yoga-upstream/generated/YGAlignSelfTest.test.ts +0 -293
  480. package/src/tests/yoga-upstream/generated/YGAndroidNewsFeed.test.ts +0 -315
  481. package/src/tests/yoga-upstream/generated/YGAspectRatioTest.test.ts +0 -231
  482. package/src/tests/yoga-upstream/generated/YGAutoTest.test.ts +0 -347
  483. package/src/tests/yoga-upstream/generated/YGBorderTest.test.ts +0 -256
  484. package/src/tests/yoga-upstream/generated/YGBoxSizingTest.test.ts +0 -2747
  485. package/src/tests/yoga-upstream/generated/YGDimensionTest.test.ts +0 -129
  486. package/src/tests/yoga-upstream/generated/YGDisplayContentsTest.test.ts +0 -109
  487. package/src/tests/yoga-upstream/generated/YGDisplayTest.test.ts +0 -1097
  488. package/src/tests/yoga-upstream/generated/YGFlexDirectionTest.test.ts +0 -4562
  489. package/src/tests/yoga-upstream/generated/YGFlexTest.test.ts +0 -677
  490. package/src/tests/yoga-upstream/generated/YGFlexWrapTest.test.ts +0 -2071
  491. package/src/tests/yoga-upstream/generated/YGGapTest.test.ts +0 -3303
  492. package/src/tests/yoga-upstream/generated/YGIntrinsicSizeTest.test.ts +0 -582
  493. package/src/tests/yoga-upstream/generated/YGJustifyContentTest.test.ts +0 -2150
  494. package/src/tests/yoga-upstream/generated/YGMarginTest.test.ts +0 -1963
  495. package/src/tests/yoga-upstream/generated/YGMinMaxDimensionTest.test.ts +0 -1446
  496. package/src/tests/yoga-upstream/generated/YGPaddingTest.test.ts +0 -354
  497. package/src/tests/yoga-upstream/generated/YGPercentageTest.test.ts +0 -1760
  498. package/src/tests/yoga-upstream/generated/YGRoundingTest.test.ts +0 -1161
  499. package/src/tests/yoga-upstream/generated/YGSizeOverflowTest.test.ts +0 -207
  500. package/src/tests/yoga-upstream/generated/YGStaticPositionTest.test.ts +0 -6338
  501. package/src/tests/yoga-upstream/tools/MeasureCounter.ts +0 -54
  502. package/src/tests/yoga-upstream/tools/utils.ts +0 -81
  503. package/src/text-buffer-view.test.ts +0 -722
  504. package/src/text-buffer-view.ts +0 -193
  505. package/src/text-buffer.test.ts +0 -512
  506. package/src/text-buffer.ts +0 -250
  507. package/src/types.ts +0 -199
  508. package/src/utils.ts +0 -88
  509. package/src/yoga.ts +0 -1146
  510. package/src/zig/ansi.zig +0 -502
  511. package/src/zig/audio.zig +0 -1206
  512. package/src/zig/bench/README.md +0 -50
  513. package/src/zig/bench/buffer-color-blending_bench.zig +0 -350
  514. package/src/zig/bench/buffer-draw-box_bench.zig +0 -786
  515. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -894
  516. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  517. package/src/zig/bench/editor-view_bench.zig +0 -169
  518. package/src/zig/bench/native-span-feed_bench.zig +0 -107
  519. package/src/zig/bench/rope-markers_bench.zig +0 -713
  520. package/src/zig/bench/rope_bench.zig +0 -514
  521. package/src/zig/bench/styled-text_bench.zig +0 -476
  522. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  523. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  524. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -272
  525. package/src/zig/bench/utf8_bench.zig +0 -799
  526. package/src/zig/bench-utils.zig +0 -431
  527. package/src/zig/bench.zig +0 -223
  528. package/src/zig/buffer-methods.zig +0 -215
  529. package/src/zig/buffer.zig +0 -2515
  530. package/src/zig/build.zig +0 -700
  531. package/src/zig/build.zig.zon +0 -19
  532. package/src/zig/edit-buffer.zig +0 -900
  533. package/src/zig/editor-view.zig +0 -812
  534. package/src/zig/event-bus.zig +0 -28
  535. package/src/zig/event-emitter.zig +0 -65
  536. package/src/zig/file-logger.zig +0 -92
  537. package/src/zig/grapheme.zig +0 -838
  538. package/src/zig/handles.zig +0 -267
  539. package/src/zig/lib.zig +0 -2813
  540. package/src/zig/link.zig +0 -349
  541. package/src/zig/logger.zig +0 -43
  542. package/src/zig/mem-registry.zig +0 -126
  543. package/src/zig/miniaudio_shim.c +0 -21
  544. package/src/zig/native-renderable.zig +0 -112
  545. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  546. package/src/zig/native-span-feed.zig +0 -747
  547. package/src/zig/renderer-output.zig +0 -677
  548. package/src/zig/renderer.zig +0 -2106
  549. package/src/zig/rope.zig +0 -1220
  550. package/src/zig/split-scrollback.zig +0 -88
  551. package/src/zig/syntax-style.zig +0 -174
  552. package/src/zig/terminal.zig +0 -1652
  553. package/src/zig/test.zig +0 -82
  554. package/src/zig/tests/README.md +0 -18
  555. package/src/zig/tests/ansi_test.zig +0 -18
  556. package/src/zig/tests/audio_test.zig +0 -439
  557. package/src/zig/tests/buffer-methods_test.zig +0 -1111
  558. package/src/zig/tests/buffer_test.zig +0 -2926
  559. package/src/zig/tests/edit-buffer-history_test.zig +0 -299
  560. package/src/zig/tests/edit-buffer_test.zig +0 -1688
  561. package/src/zig/tests/editor-view_test.zig +0 -3454
  562. package/src/zig/tests/event-emitter_test.zig +0 -249
  563. package/src/zig/tests/grapheme_test.zig +0 -1329
  564. package/src/zig/tests/handles_test.zig +0 -123
  565. package/src/zig/tests/link_test.zig +0 -220
  566. package/src/zig/tests/mem-registry_test.zig +0 -473
  567. package/src/zig/tests/memory_leak_regression_test.zig +0 -234
  568. package/src/zig/tests/native-renderable_test.zig +0 -16
  569. package/src/zig/tests/native-span-feed_test.zig +0 -1266
  570. package/src/zig/tests/renderer_test.zig +0 -2604
  571. package/src/zig/tests/rope-nested_test.zig +0 -712
  572. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  573. package/src/zig/tests/rope_test.zig +0 -2362
  574. package/src/zig/tests/segment-merge.test.zig +0 -148
  575. package/src/zig/tests/split-scrollback_test.zig +0 -70
  576. package/src/zig/tests/syntax-style_test.zig +0 -558
  577. package/src/zig/tests/terminal_test.zig +0 -1489
  578. package/src/zig/tests/test-renderer.zig +0 -126
  579. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3291
  580. package/src/zig/tests/text-buffer-highlights_test.zig +0 -706
  581. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  582. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  583. package/src/zig/tests/text-buffer-selection_test.zig +0 -1056
  584. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  585. package/src/zig/tests/text-buffer-view_test.zig +0 -3672
  586. package/src/zig/tests/text-buffer_test.zig +0 -2191
  587. package/src/zig/tests/unicode-width-map.zon +0 -3909
  588. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  589. package/src/zig/tests/utf8_test.zig +0 -4060
  590. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  591. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  592. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  593. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  594. package/src/zig/tests/yoga_test.zig +0 -65
  595. package/src/zig/text-buffer-iterators.zig +0 -496
  596. package/src/zig/text-buffer-segment.zig +0 -403
  597. package/src/zig/text-buffer-view.zig +0 -1428
  598. package/src/zig/text-buffer.zig +0 -1272
  599. package/src/zig/utf8.zig +0 -1954
  600. package/src/zig/utils.zig +0 -12
  601. package/src/zig/uucode-stub.zig +0 -76
  602. package/src/zig/vendor/miniaudio/miniaudio.h +0 -93468
  603. package/src/zig/yoga.zig +0 -658
  604. package/src/zig-structs.ts +0 -381
  605. package/src/zig.ts +0 -5260
  606. package/tsconfig.build.json +0 -17
  607. package/tsconfig.json +0 -27
  608. package/tsconfig.node-test.json +0 -138
  609. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  610. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  611. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  612. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  613. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  614. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  615. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  616. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  617. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  618. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  619. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,3547 +0,0 @@
1
- import { describe, expect, it, afterEach } from "bun:test"
2
- import { TextareaRenderable } from "../renderables/Textarea.js"
3
- import { createTestRenderer, type TestRenderer, type MockInput } from "../testing/test-renderer.js"
4
- import { type ExtmarksController } from "./extmarks.js"
5
- import { SyntaxStyle } from "../syntax-style.js"
6
- import { RGBA } from "./RGBA.js"
7
-
8
- let currentRenderer: TestRenderer
9
- let renderOnce: () => Promise<void>
10
- let currentMockInput: MockInput
11
- let textarea: TextareaRenderable
12
- let extmarks: ExtmarksController
13
-
14
- async function setup(initialValue: string = "Hello World") {
15
- const result = await createTestRenderer({ width: 80, height: 24 })
16
- currentRenderer = result.renderer
17
- renderOnce = result.renderOnce
18
- currentMockInput = result.mockInput
19
-
20
- textarea = new TextareaRenderable(currentRenderer, {
21
- left: 0,
22
- top: 0,
23
- width: 40,
24
- height: 10,
25
- initialValue,
26
- })
27
-
28
- currentRenderer.root.add(textarea)
29
- await renderOnce()
30
-
31
- extmarks = textarea.extmarks
32
-
33
- return { textarea, extmarks }
34
- }
35
-
36
- describe("ExtmarksController", () => {
37
- afterEach(() => {
38
- if (extmarks) extmarks.destroy()
39
- if (currentRenderer) currentRenderer.destroy()
40
- })
41
-
42
- describe("Creation and Basic Operations", () => {
43
- it("should create extmark with basic options", async () => {
44
- await setup()
45
-
46
- const id = extmarks.create({
47
- start: 0,
48
- end: 5,
49
- })
50
-
51
- expect(id).toBe(1)
52
- const extmark = extmarks.get(id)
53
- expect(extmark).not.toBeNull()
54
- expect(extmark?.start).toBe(0)
55
- expect(extmark?.end).toBe(5)
56
- expect(extmark?.virtual).toBe(false)
57
- })
58
-
59
- it("should create virtual extmark", async () => {
60
- await setup()
61
-
62
- const id = extmarks.create({
63
- start: 6,
64
- end: 11,
65
- virtual: true,
66
- })
67
-
68
- const extmark = extmarks.get(id)
69
- expect(extmark?.virtual).toBe(true)
70
- })
71
-
72
- it("should create multiple extmarks with unique IDs", async () => {
73
- await setup()
74
-
75
- const id1 = extmarks.create({ start: 0, end: 5 })
76
- const id2 = extmarks.create({ start: 6, end: 11 })
77
-
78
- expect(id1).toBe(1)
79
- expect(id2).toBe(2)
80
- expect(extmarks.getAll().length).toBe(2)
81
- })
82
-
83
- it("should store custom data with extmark", async () => {
84
- await setup()
85
-
86
- const id = extmarks.create({
87
- start: 0,
88
- end: 5,
89
- data: { type: "link", url: "https://example.com" },
90
- })
91
-
92
- const extmark = extmarks.get(id)
93
- expect(extmark?.data).toEqual({ type: "link", url: "https://example.com" })
94
- })
95
- })
96
-
97
- describe("Delete Operations", () => {
98
- it("should delete extmark", async () => {
99
- await setup()
100
-
101
- const id = extmarks.create({ start: 0, end: 5 })
102
- const result = extmarks.delete(id)
103
-
104
- expect(result).toBe(true)
105
- expect(extmarks.get(id)).toBeNull()
106
- })
107
-
108
- it("should return false when deleting non-existent extmark", async () => {
109
- await setup()
110
-
111
- const result = extmarks.delete(999)
112
- expect(result).toBe(false)
113
- })
114
-
115
- it("should delete extmark without emitting events", async () => {
116
- await setup()
117
-
118
- const id = extmarks.create({ start: 0, end: 5 })
119
- extmarks.delete(id)
120
- expect(extmarks.get(id)).toBeNull()
121
- })
122
-
123
- it("should clear all extmarks", async () => {
124
- await setup()
125
-
126
- extmarks.create({ start: 0, end: 5 })
127
- extmarks.create({ start: 6, end: 11 })
128
-
129
- expect(extmarks.getAll().length).toBe(2)
130
-
131
- extmarks.clear()
132
-
133
- expect(extmarks.getAll().length).toBe(0)
134
- })
135
- })
136
-
137
- describe("Query Operations", () => {
138
- it("should get all extmarks", async () => {
139
- await setup()
140
-
141
- extmarks.create({ start: 0, end: 5 })
142
- extmarks.create({ start: 6, end: 11 })
143
-
144
- const all = extmarks.getAll()
145
- expect(all.length).toBe(2)
146
- })
147
-
148
- it("should get only virtual extmarks", async () => {
149
- await setup()
150
-
151
- extmarks.create({ start: 0, end: 5, virtual: false })
152
- extmarks.create({ start: 6, end: 11, virtual: true })
153
- extmarks.create({ start: 12, end: 15, virtual: true })
154
-
155
- const virtual = extmarks.getVirtual()
156
- expect(virtual.length).toBe(2)
157
- expect(virtual.every((e) => e.virtual)).toBe(true)
158
- })
159
-
160
- it("should get extmarks at specific offset", async () => {
161
- await setup()
162
-
163
- extmarks.create({ start: 0, end: 5 })
164
- extmarks.create({ start: 3, end: 8 })
165
- extmarks.create({ start: 10, end: 15 })
166
-
167
- const atOffset4 = extmarks.getAtOffset(4)
168
- expect(atOffset4.length).toBe(2)
169
-
170
- const atOffset10 = extmarks.getAtOffset(10)
171
- expect(atOffset10.length).toBe(1)
172
- })
173
- })
174
-
175
- describe("Virtual Extmark - Cursor Jumping Right", () => {
176
- it("should jump cursor over virtual extmark when moving right", async () => {
177
- await setup("abcdefgh")
178
-
179
- textarea.focus()
180
- textarea.cursorOffset = 2
181
-
182
- extmarks.create({
183
- start: 3,
184
- end: 6,
185
- virtual: true,
186
- })
187
-
188
- expect(textarea.cursorOffset).toBe(2)
189
-
190
- currentMockInput.pressArrow("right")
191
- expect(textarea.cursorOffset).toBe(6)
192
- })
193
-
194
- it("should jump to position AFTER extmark end when moving right from before extmark", async () => {
195
- await setup("abcdefgh")
196
-
197
- textarea.focus()
198
- textarea.cursorOffset = 2
199
-
200
- extmarks.create({
201
- start: 3,
202
- end: 6,
203
- virtual: true,
204
- })
205
-
206
- expect(textarea.cursorOffset).toBe(2)
207
-
208
- // When moving right from position 2 (before extmark start at 3),
209
- // should jump to position 6 (after extmark end)
210
- currentMockInput.pressArrow("right")
211
- expect(textarea.cursorOffset).toBe(6)
212
- })
213
-
214
- it("should allow cursor to move normally outside virtual extmark", async () => {
215
- await setup("abcdefgh")
216
-
217
- textarea.focus()
218
- textarea.cursorOffset = 0
219
-
220
- extmarks.create({
221
- start: 3,
222
- end: 6,
223
- virtual: true,
224
- })
225
-
226
- currentMockInput.pressArrow("right")
227
- expect(textarea.cursorOffset).toBe(1)
228
-
229
- currentMockInput.pressArrow("right")
230
- expect(textarea.cursorOffset).toBe(2)
231
- })
232
-
233
- it("should jump over multiple virtual extmarks", async () => {
234
- await setup("abcdefghij")
235
-
236
- textarea.focus()
237
- textarea.cursorOffset = 0
238
-
239
- extmarks.create({ start: 2, end: 4, virtual: true })
240
- extmarks.create({ start: 5, end: 7, virtual: true })
241
-
242
- currentMockInput.pressArrow("right")
243
- expect(textarea.cursorOffset).toBe(1)
244
-
245
- currentMockInput.pressArrow("right")
246
- expect(textarea.cursorOffset).toBe(4)
247
-
248
- currentMockInput.pressArrow("right")
249
- expect(textarea.cursorOffset).toBe(7)
250
- })
251
- })
252
-
253
- describe("Virtual Extmark - Cursor Jumping Left", () => {
254
- it("should jump cursor over virtual extmark when moving left", async () => {
255
- await setup("abcdefgh")
256
-
257
- textarea.focus()
258
- textarea.cursorOffset = 7
259
-
260
- extmarks.create({
261
- start: 3,
262
- end: 6,
263
- virtual: true,
264
- })
265
-
266
- expect(textarea.cursorOffset).toBe(7)
267
-
268
- currentMockInput.pressArrow("left")
269
- expect(textarea.cursorOffset).toBe(6)
270
-
271
- currentMockInput.pressArrow("left")
272
- expect(textarea.cursorOffset).toBe(2)
273
- })
274
-
275
- it("should jump to position BEFORE extmark start when moving left from after extmark", async () => {
276
- await setup("abcdefgh")
277
-
278
- textarea.focus()
279
- textarea.cursorOffset = 6
280
-
281
- extmarks.create({
282
- start: 3,
283
- end: 6,
284
- virtual: true,
285
- })
286
-
287
- expect(textarea.cursorOffset).toBe(6)
288
-
289
- // When moving left from position 6 (right after extmark end),
290
- // should jump to position 2 (before extmark start at 3)
291
- currentMockInput.pressArrow("left")
292
- expect(textarea.cursorOffset).toBe(2)
293
- })
294
-
295
- it("should allow normal cursor movement left outside virtual extmark", async () => {
296
- await setup("abcdefgh")
297
-
298
- textarea.focus()
299
- textarea.cursorOffset = 2
300
-
301
- extmarks.create({
302
- start: 3,
303
- end: 6,
304
- virtual: true,
305
- })
306
-
307
- currentMockInput.pressArrow("left")
308
- expect(textarea.cursorOffset).toBe(1)
309
-
310
- currentMockInput.pressArrow("left")
311
- expect(textarea.cursorOffset).toBe(0)
312
- })
313
- })
314
-
315
- describe("Virtual Extmark - Selection Mode", () => {
316
- it("should allow selection through virtual extmark", async () => {
317
- await setup("abcdefgh")
318
-
319
- textarea.focus()
320
- textarea.cursorOffset = 0
321
-
322
- extmarks.create({
323
- start: 2,
324
- end: 5,
325
- virtual: true,
326
- })
327
-
328
- currentMockInput.pressArrow("right", { shift: true })
329
- currentMockInput.pressArrow("right", { shift: true })
330
- currentMockInput.pressArrow("right", { shift: true })
331
-
332
- expect(textarea.cursorOffset).toBe(3)
333
- expect(textarea.hasSelection()).toBe(true)
334
- })
335
- })
336
-
337
- describe("Virtual Extmark - Backspace Deletion", () => {
338
- it("should delete entire virtual extmark on backspace at end", async () => {
339
- await setup("abc[LINK]def")
340
-
341
- textarea.focus()
342
- textarea.cursorOffset = 9
343
-
344
- const id = extmarks.create({
345
- start: 3,
346
- end: 9,
347
- virtual: true,
348
- })
349
-
350
- currentMockInput.pressBackspace()
351
-
352
- expect(textarea.plainText).toBe("abcdef")
353
- expect(textarea.cursorOffset).toBe(3)
354
- expect(extmarks.get(id)).toBeNull()
355
- })
356
-
357
- it("should not delete virtual extmark on backspace outside range", async () => {
358
- await setup("abc[LINK]def")
359
-
360
- textarea.focus()
361
- textarea.cursorOffset = 2
362
-
363
- const id = extmarks.create({
364
- start: 3,
365
- end: 9,
366
- virtual: true,
367
- })
368
-
369
- currentMockInput.pressBackspace()
370
-
371
- expect(textarea.plainText).toBe("ac[LINK]def")
372
- expect(extmarks.get(id)).not.toBeNull()
373
- })
374
-
375
- it("should delete normal character inside virtual extmark", async () => {
376
- await setup("abc[LINK]def")
377
-
378
- textarea.focus()
379
- textarea.cursorOffset = 5
380
-
381
- extmarks.create({
382
- start: 3,
383
- end: 9,
384
- virtual: true,
385
- })
386
-
387
- currentMockInput.pressBackspace()
388
-
389
- expect(textarea.plainText).toBe("abc[INK]def")
390
- })
391
- })
392
-
393
- describe("Virtual Extmark - Delete Key", () => {
394
- it("should delete entire virtual extmark on delete at start", async () => {
395
- await setup("abc[LINK]def")
396
-
397
- textarea.focus()
398
- textarea.cursorOffset = 3
399
-
400
- const id = extmarks.create({
401
- start: 3,
402
- end: 9,
403
- virtual: true,
404
- })
405
-
406
- currentMockInput.pressKey("DELETE")
407
-
408
- expect(textarea.plainText).toBe("abcdef")
409
- expect(textarea.cursorOffset).toBe(3)
410
- expect(extmarks.get(id)).toBeNull()
411
- })
412
- })
413
-
414
- describe("Extmark Position Adjustment - Insertion", () => {
415
- it("should adjust extmark positions after insertion before extmark", async () => {
416
- await setup("Hello World")
417
-
418
- const id = extmarks.create({
419
- start: 6,
420
- end: 11,
421
- })
422
-
423
- textarea.focus()
424
- textarea.cursorOffset = 0
425
-
426
- currentMockInput.pressKey("X")
427
- currentMockInput.pressKey("X")
428
-
429
- const extmark = extmarks.get(id)
430
- expect(extmark?.start).toBe(8)
431
- expect(extmark?.end).toBe(13)
432
- })
433
-
434
- it("should expand extmark when inserting inside", async () => {
435
- await setup("Hello World")
436
-
437
- const id = extmarks.create({
438
- start: 6,
439
- end: 11,
440
- })
441
-
442
- textarea.focus()
443
- textarea.cursorOffset = 8
444
-
445
- currentMockInput.pressKey("X")
446
- currentMockInput.pressKey("X")
447
-
448
- const extmark = extmarks.get(id)
449
- expect(extmark?.start).toBe(6)
450
- expect(extmark?.end).toBe(13)
451
- })
452
-
453
- it("should not adjust extmark when inserting after", async () => {
454
- await setup("Hello World")
455
-
456
- const id = extmarks.create({
457
- start: 0,
458
- end: 5,
459
- })
460
-
461
- textarea.focus()
462
- textarea.cursorOffset = 11
463
-
464
- currentMockInput.pressKey("X")
465
- currentMockInput.pressKey("X")
466
-
467
- const extmark = extmarks.get(id)
468
- expect(extmark?.start).toBe(0)
469
- expect(extmark?.end).toBe(5)
470
- })
471
-
472
- it("should adjust extmark positions by display width after multi-width text insertion before extmark", async () => {
473
- await setup("abc")
474
-
475
- const id = extmarks.create({
476
- start: 1,
477
- end: 3,
478
- })
479
-
480
- textarea.focus()
481
- textarea.cursorOffset = 0
482
- textarea.insertText("한글")
483
-
484
- const extmark = extmarks.get(id)
485
- expect(textarea.plainText).toBe("한글abc")
486
- expect(extmark?.start).toBe(5)
487
- expect(extmark?.end).toBe(7)
488
- })
489
-
490
- it("should adjust extmark positions by display width after multi-width char insertion before extmark", async () => {
491
- await setup("abc")
492
-
493
- const id = extmarks.create({
494
- start: 1,
495
- end: 3,
496
- })
497
-
498
- textarea.focus()
499
- textarea.cursorOffset = 0
500
- textarea.insertChar("한")
501
-
502
- const extmark = extmarks.get(id)
503
- expect(textarea.plainText).toBe("한abc")
504
- expect(extmark?.start).toBe(3)
505
- expect(extmark?.end).toBe(5)
506
- })
507
-
508
- it("should count newlines in display offsets after multi-line multi-width insertion before extmark", async () => {
509
- await setup("abc")
510
-
511
- const id = extmarks.create({
512
- start: 1,
513
- end: 3,
514
- })
515
-
516
- textarea.focus()
517
- textarea.cursorOffset = 0
518
- textarea.insertText("한\n글")
519
-
520
- const extmark = extmarks.get(id)
521
- expect(textarea.plainText).toBe("한\n글abc")
522
- expect(extmark?.start).toBe(6)
523
- expect(extmark?.end).toBe(8)
524
- })
525
- })
526
-
527
- describe("Extmark Position Adjustment - Deletion", () => {
528
- it("should adjust extmark positions after deletion before extmark", async () => {
529
- await setup("XXHello World")
530
-
531
- const id = extmarks.create({
532
- start: 8,
533
- end: 13,
534
- })
535
-
536
- textarea.focus()
537
- textarea.cursorOffset = 2
538
-
539
- currentMockInput.pressBackspace()
540
- currentMockInput.pressBackspace()
541
-
542
- const extmark = extmarks.get(id)
543
- expect(extmark?.start).toBe(6)
544
- expect(extmark?.end).toBe(11)
545
- })
546
-
547
- it("should remove extmark when its range is deleted", async () => {
548
- await setup("Hello World")
549
-
550
- const id = extmarks.create({
551
- start: 6,
552
- end: 11,
553
- })
554
-
555
- textarea.deleteRange(0, 6, 0, 11)
556
-
557
- expect(extmarks.get(id)).toBeNull()
558
- })
559
-
560
- it("should adjust extmark positions by display width after backspacing multi-width text before extmark", async () => {
561
- await setup("한글abc")
562
-
563
- const id = extmarks.create({
564
- start: 4,
565
- end: 7,
566
- })
567
-
568
- textarea.focus()
569
- textarea.cursorOffset = 4
570
- currentMockInput.pressBackspace()
571
-
572
- const extmark = extmarks.get(id)
573
- expect(textarea.plainText).toBe("한abc")
574
- expect(extmark?.start).toBe(2)
575
- expect(extmark?.end).toBe(5)
576
- })
577
-
578
- it("should adjust extmark positions by display width after deleting multi-width text before extmark", async () => {
579
- await setup("한abc")
580
-
581
- const id = extmarks.create({
582
- start: 2,
583
- end: 5,
584
- })
585
-
586
- textarea.focus()
587
- textarea.cursorOffset = 0
588
- currentMockInput.pressKey("DELETE")
589
-
590
- const extmark = extmarks.get(id)
591
- expect(textarea.plainText).toBe("abc")
592
- expect(extmark?.start).toBe(0)
593
- expect(extmark?.end).toBe(3)
594
- })
595
- })
596
-
597
- describe("Highlighting Integration", () => {
598
- it("should apply highlight for extmark with styleId", async () => {
599
- await setup("Hello World")
600
-
601
- const style = SyntaxStyle.create()
602
- const styleId = style.registerStyle("link", {
603
- fg: RGBA.fromValues(0, 0, 1, 1),
604
- })
605
-
606
- textarea.syntaxStyle = style
607
-
608
- extmarks.create({
609
- start: 0,
610
- end: 5,
611
- styleId,
612
- })
613
-
614
- const highlights = textarea.getLineHighlights(0)
615
- expect(highlights.length).toBe(1)
616
- expect(highlights[0].start).toBe(0)
617
- expect(highlights[0].end).toBe(5)
618
- expect(highlights[0].styleId).toBe(styleId)
619
- })
620
-
621
- it("should correctly position highlights in middle of single line", async () => {
622
- await setup("AAAA")
623
-
624
- const style = SyntaxStyle.create()
625
- const styleId = style.registerStyle("test", {
626
- fg: RGBA.fromValues(1, 0, 0, 1),
627
- })
628
-
629
- textarea.syntaxStyle = style
630
-
631
- // Highlight just the middle two chars (positions 1-2, which is "AA")
632
- extmarks.create({
633
- start: 1,
634
- end: 3,
635
- styleId,
636
- })
637
-
638
- const highlights = textarea.getLineHighlights(0)
639
- expect(highlights.length).toBe(1)
640
- expect(highlights[0].start).toBe(1)
641
- expect(highlights[0].end).toBe(3)
642
- })
643
-
644
- it("should correctly position highlights across newlines", async () => {
645
- await setup("AAAA\nBBBB\nCCCC")
646
-
647
- const style = SyntaxStyle.create()
648
- const styleId = style.registerStyle("test", {
649
- fg: RGBA.fromValues(1, 0, 0, 1),
650
- })
651
-
652
- textarea.syntaxStyle = style
653
-
654
- // Text: "AAAA\nBBBB\nCCCC"
655
- // Cursor offsets (with newlines): 0-3="AAAA", 4="\n", 5-8="BBBB", 9="\n", 10-13="CCCC"
656
- // Want to highlight just "BBBB" which is cursor offset 5-9
657
- extmarks.create({
658
- start: 5,
659
- end: 9,
660
- styleId,
661
- })
662
-
663
- const hl0 = textarea.getLineHighlights(0)
664
- const hl1 = textarea.getLineHighlights(1)
665
- const hl2 = textarea.getLineHighlights(2)
666
-
667
- // Line 0 should have no highlights
668
- expect(hl0.length).toBe(0)
669
-
670
- // Line 1 should have the entire "BBBB" highlighted
671
- expect(hl1.length).toBe(1)
672
- expect(hl1[0].start).toBe(0)
673
- expect(hl1[0].end).toBe(4)
674
-
675
- // Line 2 should have no highlights
676
- expect(hl2.length).toBe(0)
677
- })
678
-
679
- it("should correctly position multiline highlights", async () => {
680
- await setup("AAA\nBBB\nCCC")
681
-
682
- const style = SyntaxStyle.create()
683
- const styleId = style.registerStyle("test", {
684
- fg: RGBA.fromValues(0, 1, 0, 1),
685
- })
686
-
687
- textarea.syntaxStyle = style
688
-
689
- // Text: "AAA\nBBB\nCCC"
690
- // Cursor offsets: 0-2="AAA", 3="\n", 4-6="BBB", 7="\n", 8-10="CCC"
691
- // Want to highlight from middle of line 0 to middle of line 2
692
- // From cursor offset 1 (second 'A') to 9 (second 'C')
693
- extmarks.create({
694
- start: 1,
695
- end: 9,
696
- styleId,
697
- })
698
-
699
- const hl0 = textarea.getLineHighlights(0)
700
- const hl1 = textarea.getLineHighlights(1)
701
- const hl2 = textarea.getLineHighlights(2)
702
-
703
- // Line 0: should highlight from position 1 to end (last two A's)
704
- expect(hl0.length).toBe(1)
705
- expect(hl0[0].start).toBe(1)
706
- expect(hl0[0].end).toBe(3)
707
-
708
- // Line 1: should highlight entire line (all of BBB)
709
- expect(hl1.length).toBe(1)
710
- expect(hl1[0].start).toBe(0)
711
- expect(hl1[0].end).toBe(3)
712
-
713
- // Line 2: should highlight from start to position 1 (first C only)
714
- // Cursor offset 9 = char offset 7 = second 'C'
715
- // Line 2 starts at char offset 6, so we highlight positions 0-1 (first 'C')
716
- expect(hl2.length).toBe(1)
717
- expect(hl2[0].start).toBe(0)
718
- expect(hl2[0].end).toBe(1)
719
- })
720
-
721
- it("should update highlights when extmark position changes", async () => {
722
- await setup("Hello World")
723
-
724
- const style = SyntaxStyle.create()
725
- const styleId = style.registerStyle("link", {
726
- fg: RGBA.fromValues(0, 0, 1, 1),
727
- })
728
-
729
- textarea.syntaxStyle = style
730
-
731
- const id = extmarks.create({
732
- start: 0,
733
- end: 5,
734
- styleId,
735
- })
736
-
737
- textarea.focus()
738
- textarea.cursorOffset = 0
739
- currentMockInput.pressKey("X")
740
-
741
- const extmark = extmarks.get(id)
742
- expect(extmark?.start).toBe(1)
743
- expect(extmark?.end).toBe(6)
744
- })
745
-
746
- it("should remove highlight when extmark is deleted", async () => {
747
- await setup("Hello World")
748
-
749
- const style = SyntaxStyle.create()
750
- const styleId = style.registerStyle("link", {
751
- fg: RGBA.fromValues(0, 0, 1, 1),
752
- })
753
-
754
- textarea.syntaxStyle = style
755
-
756
- const id = extmarks.create({
757
- start: 0,
758
- end: 5,
759
- styleId,
760
- })
761
-
762
- const highlightsBefore = textarea.getLineHighlights(0)
763
- expect(highlightsBefore.length).toBeGreaterThan(0)
764
-
765
- extmarks.delete(id)
766
-
767
- const highlightsAfter = textarea.getLineHighlights(0)
768
- expect(highlightsAfter.length).toBe(0)
769
- })
770
- })
771
-
772
- describe("Multiline Text Support", () => {
773
- it("should handle extmarks in multiline text", async () => {
774
- await setup("Line 1\nLine 2\nLine 3")
775
-
776
- const id = extmarks.create({
777
- start: 7,
778
- end: 13,
779
- })
780
-
781
- textarea.focus()
782
- textarea.cursorOffset = 0
783
- currentMockInput.pressKey("X")
784
-
785
- const extmark = extmarks.get(id)
786
- expect(extmark?.start).toBe(8)
787
- expect(extmark?.end).toBe(14)
788
- })
789
-
790
- it("should handle virtual extmark across lines", async () => {
791
- await setup("Line 1\nLine 2\nLine 3")
792
-
793
- textarea.focus()
794
- textarea.cursorOffset = 5
795
-
796
- extmarks.create({
797
- start: 7,
798
- end: 13,
799
- virtual: true,
800
- })
801
-
802
- for (let i = 0; i < 3; i++) {
803
- currentMockInput.pressArrow("right")
804
- }
805
-
806
- expect(textarea.cursorOffset).toBe(14)
807
- })
808
- })
809
-
810
- describe("Destroy", () => {
811
- it("should restore original methods on destroy", async () => {
812
- await setup("Hello World")
813
-
814
- textarea.focus()
815
- textarea.cursorOffset = 2
816
-
817
- extmarks.create({
818
- start: 3,
819
- end: 6,
820
- virtual: true,
821
- })
822
-
823
- currentMockInput.pressArrow("right")
824
- expect(textarea.cursorOffset).toBe(6)
825
-
826
- extmarks.destroy()
827
-
828
- textarea.cursorOffset = 2
829
- currentMockInput.pressArrow("right")
830
- expect(textarea.cursorOffset).toBe(3)
831
- })
832
-
833
- it("should clear all extmarks on destroy", async () => {
834
- await setup()
835
-
836
- extmarks.create({ start: 0, end: 5 })
837
- extmarks.create({ start: 6, end: 11 })
838
-
839
- expect(extmarks.getAll().length).toBe(2)
840
-
841
- extmarks.destroy()
842
-
843
- expect(extmarks.getAll().length).toBe(0)
844
- })
845
-
846
- it("should throw error when using destroyed controller", async () => {
847
- await setup()
848
-
849
- extmarks.destroy()
850
-
851
- expect(() => {
852
- extmarks.create({ start: 0, end: 5 })
853
- }).toThrow("ExtmarksController is destroyed")
854
- })
855
- })
856
-
857
- describe("Highlight Boundaries", () => {
858
- it("should highlight only virtual marker without extending to end of line", async () => {
859
- await setup("text [VIRTUAL] more text")
860
-
861
- const style = SyntaxStyle.create()
862
- const styleId = style.registerStyle("virtual", {
863
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
864
- bg: RGBA.fromValues(0.1, 0.2, 0.3, 1.0),
865
- })
866
-
867
- textarea.syntaxStyle = style
868
-
869
- const virtualStart = 5
870
- const virtualEnd = 14
871
-
872
- extmarks.create({
873
- start: virtualStart,
874
- end: virtualEnd,
875
- virtual: true,
876
- styleId,
877
- })
878
-
879
- const highlights = textarea.getLineHighlights(0)
880
-
881
- expect(highlights.length).toBe(1)
882
- expect(highlights[0].start).toBe(virtualStart)
883
- expect(highlights[0].end).toBe(virtualEnd)
884
- })
885
-
886
- it("should highlight virtual marker in middle with text after", async () => {
887
- await setup("abc [MARKER] def")
888
-
889
- const style = SyntaxStyle.create()
890
- const styleId = style.registerStyle("virtual", {
891
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
892
- })
893
-
894
- textarea.syntaxStyle = style
895
-
896
- const start = 4
897
- const end = 12
898
-
899
- extmarks.create({
900
- start,
901
- end,
902
- virtual: true,
903
- styleId,
904
- })
905
-
906
- const highlights = textarea.getLineHighlights(0)
907
-
908
- expect(highlights.length).toBe(1)
909
- expect(highlights[0].start).toBe(start)
910
- expect(highlights[0].end).toBe(end)
911
- })
912
-
913
- it("should highlight virtual marker in multiline text correctly", async () => {
914
- const text = `Try moving your cursor through the [VIRTUAL] markers below:
915
- - Use arrow keys to navigate`
916
-
917
- await setup(text)
918
-
919
- const style = SyntaxStyle.create()
920
- const styleId = style.registerStyle("virtual", {
921
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
922
- bg: RGBA.fromValues(0.1, 0.2, 0.3, 1.0),
923
- })
924
-
925
- textarea.syntaxStyle = style
926
-
927
- const pattern = /\[VIRTUAL\]/g
928
- const match = pattern.exec(text)
929
-
930
- if (!match) {
931
- throw new Error("Pattern not found")
932
- }
933
-
934
- const start = match.index
935
- const end = match.index + match[0].length
936
-
937
- extmarks.create({
938
- start,
939
- end,
940
- virtual: true,
941
- styleId,
942
- })
943
-
944
- const hl0 = textarea.getLineHighlights(0)
945
- const hl1 = textarea.getLineHighlights(1)
946
-
947
- expect(hl0.length).toBe(1)
948
- expect(hl0[0].start).toBe(35)
949
- expect(hl0[0].end).toBe(44)
950
- expect(hl1.length).toBe(0)
951
- })
952
-
953
- it("should correctly highlight multiple virtual markers with pattern matching", async () => {
954
- const initialContent = `Welcome to the Extmarks Demo!
955
-
956
- This demo showcases virtual extmarks - text ranges that the cursor jumps over.
957
-
958
- Try moving your cursor through the [VIRTUAL] markers below:
959
- - Use arrow keys to navigate
960
- - Notice how the cursor skips over [VIRTUAL] ranges`
961
-
962
- await setup(initialContent)
963
-
964
- const style = SyntaxStyle.create()
965
- const virtualStyleId = style.registerStyle("virtual", {
966
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
967
- bg: RGBA.fromValues(0.1, 0.2, 0.3, 1.0),
968
- })
969
-
970
- textarea.syntaxStyle = style
971
-
972
- const text = textarea.plainText
973
- const pattern = /\[(VIRTUAL|LINK:[^\]]+|TAG:[^\]]+|MARKER)\]/g
974
- let match: RegExpExecArray | null
975
-
976
- while ((match = pattern.exec(text)) !== null) {
977
- const start = match.index
978
- const end = match.index + match[0].length
979
-
980
- extmarks.create({
981
- start,
982
- end,
983
- virtual: true,
984
- styleId: virtualStyleId,
985
- data: { type: "auto-detected", content: match[0] },
986
- })
987
- }
988
-
989
- const line4Highlights = textarea.getLineHighlights(4)
990
- const line6Highlights = textarea.getLineHighlights(6)
991
- const lines = text.split("\n")
992
-
993
- expect(line4Highlights.length).toBeGreaterThan(0)
994
- expect(line6Highlights.length).toBeGreaterThan(0)
995
-
996
- const line4FirstHighlight = line4Highlights[0]
997
- const line6FirstHighlight = line6Highlights[0]
998
-
999
- expect(line4FirstHighlight.end).toBe(44)
1000
- expect(line4FirstHighlight.end).toBeLessThan(lines[4].length)
1001
-
1002
- expect(line6FirstHighlight.end).toBe(44)
1003
- expect(line6FirstHighlight.end).toBeLessThan(lines[6].length)
1004
- })
1005
- })
1006
-
1007
- describe("Multiple Extmarks", () => {
1008
- it("should maintain correct positions after deleting first extmark", async () => {
1009
- await setup("abc [VIRTUAL] def [VIRTUAL] ghi")
1010
-
1011
- const style = SyntaxStyle.create()
1012
- const styleId = style.registerStyle("virtual", {
1013
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
1014
- })
1015
-
1016
- textarea.syntaxStyle = style
1017
-
1018
- const id1 = extmarks.create({
1019
- start: 4,
1020
- end: 13,
1021
- virtual: true,
1022
- styleId,
1023
- })
1024
-
1025
- const id2 = extmarks.create({
1026
- start: 18,
1027
- end: 27,
1028
- virtual: true,
1029
- styleId,
1030
- })
1031
-
1032
- textarea.focus()
1033
- textarea.cursorOffset = 13
1034
- currentMockInput.pressBackspace()
1035
-
1036
- expect(extmarks.get(id1)).toBeNull()
1037
-
1038
- const em2 = extmarks.get(id2)
1039
- expect(em2).not.toBeNull()
1040
-
1041
- expect(textarea.plainText.substring(em2!.start, em2!.end)).toBe("[VIRTUAL]")
1042
- })
1043
- })
1044
-
1045
- describe("Complex Multiline Scenarios", () => {
1046
- it("should handle multiple marker types across many lines", async () => {
1047
- const initialContent = `Welcome to the Extmarks Demo!
1048
-
1049
- This demo showcases virtual extmarks - text ranges that the cursor jumps over.
1050
-
1051
- Try moving your cursor through the [VIRTUAL] markers below:
1052
- - Use arrow keys to navigate
1053
- - Notice how the cursor skips over [VIRTUAL] ranges
1054
- - Try backspacing at the end of a [VIRTUAL] marker
1055
- - It will delete the entire marker!
1056
-
1057
- Example text with [LINK:https://example.com] embedded links.
1058
- You can also have [TAG:important] tags that act like atoms.
1059
-
1060
- Regular text here can be edited normally.
1061
-
1062
- Press Ctrl+L to add a new [MARKER] at cursor position.
1063
- Press ESC to return to main menu.`
1064
-
1065
- await setup(initialContent)
1066
-
1067
- const style = SyntaxStyle.create()
1068
- const virtualStyleId = style.registerStyle("virtual", {
1069
- fg: RGBA.fromValues(0.3, 0.7, 1.0, 1.0),
1070
- bg: RGBA.fromValues(0.1, 0.2, 0.3, 1.0),
1071
- })
1072
-
1073
- textarea.syntaxStyle = style
1074
-
1075
- const text = textarea.plainText
1076
- const pattern = /\[(VIRTUAL|LINK:[^\]]+|TAG:[^\]]+|MARKER)\]/g
1077
- let match: RegExpExecArray | null
1078
- const markedRanges: Array<{ start: number; end: number; text: string; line: number }> = []
1079
-
1080
- const lines = text.split("\n")
1081
-
1082
- while ((match = pattern.exec(text)) !== null) {
1083
- const start = match.index
1084
- const end = match.index + match[0].length
1085
-
1086
- let lineIdx = 0
1087
- let charCount = 0
1088
- for (let i = 0; i < lines.length; i++) {
1089
- if (charCount + lines[i].length >= start) {
1090
- lineIdx = i
1091
- break
1092
- }
1093
- charCount += lines[i].length + 1
1094
- }
1095
-
1096
- markedRanges.push({ start, end, text: match[0], line: lineIdx })
1097
-
1098
- extmarks.create({
1099
- start,
1100
- end,
1101
- virtual: true,
1102
- styleId: virtualStyleId,
1103
- data: { type: "auto-detected", content: match[0] },
1104
- })
1105
- }
1106
-
1107
- for (const range of markedRanges) {
1108
- const highlights = textarea.getLineHighlights(range.line)
1109
- const lineText = lines[range.line]
1110
-
1111
- expect(highlights.length).toBeGreaterThan(0)
1112
-
1113
- const matchingHighlight = highlights.find((h) => {
1114
- const hlText = lineText.substring(h.start, Math.min(h.end, lineText.length))
1115
- return hlText.includes(range.text.substring(0, Math.min(5, range.text.length)))
1116
- })
1117
-
1118
- expect(matchingHighlight).not.toBeUndefined()
1119
- expect(matchingHighlight!.end).toBeLessThanOrEqual(lineText.length)
1120
- }
1121
- })
1122
- })
1123
-
1124
- describe("Virtual Extmark - Word Boundary Movement", () => {
1125
- it("should not land inside virtual extmark when moving backward by word from after extmark", async () => {
1126
- await setup("bla [VIRTUAL] bla")
1127
-
1128
- textarea.focus()
1129
- textarea.cursorOffset = 13
1130
-
1131
- extmarks.create({
1132
- start: 4,
1133
- end: 13,
1134
- virtual: true,
1135
- })
1136
-
1137
- expect(textarea.cursorOffset).toBe(13)
1138
-
1139
- textarea.moveWordBackward()
1140
- expect(textarea.cursorOffset).toBe(3)
1141
- })
1142
-
1143
- it("should jump cursor over virtual extmark when moving forward by word", async () => {
1144
- await setup("hello [VIRTUAL] world test")
1145
-
1146
- textarea.focus()
1147
- textarea.cursorOffset = 0
1148
-
1149
- const id = extmarks.create({
1150
- start: 6,
1151
- end: 16,
1152
- virtual: true,
1153
- })
1154
-
1155
- expect(textarea.cursorOffset).toBe(0)
1156
-
1157
- textarea.moveWordForward()
1158
- expect(textarea.cursorOffset).toBe(16)
1159
-
1160
- textarea.moveWordForward()
1161
- expect(textarea.cursorOffset).toBe(22)
1162
-
1163
- const extmark = extmarks.get(id)
1164
- expect(extmark).not.toBeNull()
1165
- })
1166
-
1167
- it("should jump cursor over virtual extmark when moving backward by word", async () => {
1168
- await setup("hello [VIRTUAL] world test")
1169
-
1170
- textarea.focus()
1171
- textarea.cursorOffset = 22
1172
-
1173
- const id = extmarks.create({
1174
- start: 6,
1175
- end: 16,
1176
- virtual: true,
1177
- })
1178
-
1179
- expect(textarea.cursorOffset).toBe(22)
1180
-
1181
- textarea.moveWordBackward()
1182
- expect(textarea.cursorOffset).toBe(16)
1183
-
1184
- textarea.moveWordBackward()
1185
- expect(textarea.cursorOffset).toBe(5)
1186
-
1187
- const extmark = extmarks.get(id)
1188
- expect(extmark).not.toBeNull()
1189
- })
1190
-
1191
- it("should jump over multiple virtual extmarks when moving forward by word", async () => {
1192
- await setup("one [V1] two [V2] three")
1193
-
1194
- textarea.focus()
1195
- textarea.cursorOffset = 0
1196
-
1197
- extmarks.create({ start: 4, end: 9, virtual: true })
1198
- extmarks.create({ start: 13, end: 18, virtual: true })
1199
-
1200
- textarea.moveWordForward()
1201
- expect(textarea.cursorOffset).toBe(9)
1202
-
1203
- textarea.moveWordForward()
1204
- expect(textarea.cursorOffset).toBe(18)
1205
-
1206
- textarea.moveWordForward()
1207
- expect(textarea.cursorOffset).toBe(23)
1208
- })
1209
-
1210
- it("should jump over multiple virtual extmarks when moving backward by word", async () => {
1211
- await setup("one [V1] two [V2] three")
1212
-
1213
- textarea.focus()
1214
- textarea.cursorOffset = 23
1215
-
1216
- extmarks.create({ start: 4, end: 9, virtual: true })
1217
- extmarks.create({ start: 13, end: 18, virtual: true })
1218
-
1219
- textarea.moveWordBackward()
1220
- expect(textarea.cursorOffset).toBe(18)
1221
-
1222
- textarea.moveWordBackward()
1223
- expect(textarea.cursorOffset).toBe(12)
1224
-
1225
- textarea.moveWordBackward()
1226
- expect(textarea.cursorOffset).toBe(9)
1227
-
1228
- textarea.moveWordBackward()
1229
- expect(textarea.cursorOffset).toBe(3)
1230
- })
1231
- })
1232
-
1233
- describe("setText() Operations", () => {
1234
- it("should clear all extmarks when setText is called", async () => {
1235
- await setup("Hello World")
1236
-
1237
- const id1 = extmarks.create({ start: 0, end: 5 })
1238
- const id2 = extmarks.create({ start: 6, end: 11, virtual: true })
1239
-
1240
- expect(extmarks.getAll().length).toBe(2)
1241
-
1242
- textarea.setText("New Text")
1243
-
1244
- expect(extmarks.getAll().length).toBe(0)
1245
- expect(extmarks.get(id1)).toBeNull()
1246
- expect(extmarks.get(id2)).toBeNull()
1247
- })
1248
-
1249
- it("should clear all extmarks on setText", async () => {
1250
- await setup("Hello World")
1251
-
1252
- extmarks.create({ start: 0, end: 5 })
1253
- extmarks.create({ start: 6, end: 11 })
1254
-
1255
- expect(extmarks.getAll().length).toBe(2)
1256
-
1257
- textarea.setText("New Text")
1258
-
1259
- expect(extmarks.getAll().length).toBe(0)
1260
- })
1261
-
1262
- it("should allow new extmarks after setText", async () => {
1263
- await setup("Hello World")
1264
-
1265
- extmarks.create({ start: 0, end: 5 })
1266
- textarea.setText("New Text")
1267
-
1268
- const newId = extmarks.create({ start: 0, end: 3 })
1269
- const extmark = extmarks.get(newId)
1270
-
1271
- expect(extmark).not.toBeNull()
1272
- expect(extmark?.start).toBe(0)
1273
- expect(extmark?.end).toBe(3)
1274
- })
1275
- })
1276
-
1277
- describe("deleteWordForward() Operations", () => {
1278
- it("should adjust extmark positions after deleteWordForward before extmark", async () => {
1279
- await setup("hello world test")
1280
-
1281
- const id = extmarks.create({
1282
- start: 12,
1283
- end: 16,
1284
- })
1285
-
1286
- textarea.focus()
1287
- textarea.cursorOffset = 0
1288
-
1289
- textarea.deleteWordForward()
1290
-
1291
- const extmark = extmarks.get(id)
1292
- expect(extmark?.start).toBe(6)
1293
- expect(extmark?.end).toBe(10)
1294
- expect(textarea.plainText).toBe("world test")
1295
- })
1296
-
1297
- it("should remove extmark when deleteWordForward covers it", async () => {
1298
- await setup("hello world test")
1299
-
1300
- const id = extmarks.create({
1301
- start: 0,
1302
- end: 5,
1303
- })
1304
-
1305
- textarea.focus()
1306
- textarea.cursorOffset = 0
1307
-
1308
- textarea.deleteWordForward()
1309
-
1310
- expect(extmarks.get(id)).toBeNull()
1311
- expect(textarea.plainText).toBe("world test")
1312
- })
1313
-
1314
- it("should not adjust extmark when deleteWordForward after", async () => {
1315
- await setup("hello world test")
1316
-
1317
- const id = extmarks.create({
1318
- start: 0,
1319
- end: 5,
1320
- })
1321
-
1322
- textarea.focus()
1323
- textarea.cursorOffset = 6
1324
-
1325
- textarea.deleteWordForward()
1326
-
1327
- const extmark = extmarks.get(id)
1328
- expect(extmark?.start).toBe(0)
1329
- expect(extmark?.end).toBe(5)
1330
- })
1331
- })
1332
-
1333
- describe("deleteWordBackward() Operations", () => {
1334
- it("should adjust extmark positions after deleteWordBackward before extmark", async () => {
1335
- await setup("hello world test")
1336
-
1337
- const id = extmarks.create({
1338
- start: 12,
1339
- end: 16,
1340
- })
1341
-
1342
- textarea.focus()
1343
- textarea.cursorOffset = 11
1344
-
1345
- textarea.deleteWordBackward()
1346
-
1347
- const extmark = extmarks.get(id)
1348
- expect(extmark?.start).toBe(7)
1349
- expect(extmark?.end).toBe(11)
1350
- expect(textarea.plainText).toBe("hello test")
1351
- })
1352
-
1353
- it("should remove extmark when deleteWordBackward covers it", async () => {
1354
- await setup("hello world test")
1355
-
1356
- const id = extmarks.create({
1357
- start: 6,
1358
- end: 11,
1359
- })
1360
-
1361
- textarea.focus()
1362
- textarea.cursorOffset = 11
1363
-
1364
- textarea.deleteWordBackward()
1365
-
1366
- expect(extmarks.get(id)).toBeNull()
1367
- expect(textarea.plainText).toBe("hello test")
1368
- })
1369
-
1370
- it("should not adjust extmark when deleteWordBackward after", async () => {
1371
- await setup("hello world test")
1372
-
1373
- const id = extmarks.create({
1374
- start: 12,
1375
- end: 16,
1376
- })
1377
-
1378
- textarea.focus()
1379
- textarea.cursorOffset = 5
1380
-
1381
- textarea.deleteWordBackward()
1382
-
1383
- const extmark = extmarks.get(id)
1384
- expect(extmark?.start).toBe(7)
1385
- expect(extmark?.end).toBe(11)
1386
- expect(textarea.plainText).toBe(" world test")
1387
- })
1388
- })
1389
-
1390
- describe("deleteToLineEnd() Operations", () => {
1391
- it("should remove extmark when deleteToLineEnd covers it", async () => {
1392
- await setup("Hello World")
1393
-
1394
- const id = extmarks.create({
1395
- start: 6,
1396
- end: 11,
1397
- })
1398
-
1399
- textarea.focus()
1400
- textarea.cursorOffset = 2
1401
-
1402
- textarea.deleteToLineEnd()
1403
-
1404
- expect(extmarks.get(id)).toBeNull()
1405
- expect(textarea.plainText).toBe("He")
1406
- })
1407
-
1408
- it("should partially trim extmark when deleteToLineEnd overlaps end", async () => {
1409
- await setup("Hello World Extra")
1410
-
1411
- const id = extmarks.create({
1412
- start: 3,
1413
- end: 8,
1414
- })
1415
-
1416
- textarea.focus()
1417
- textarea.cursorOffset = 6
1418
-
1419
- textarea.deleteToLineEnd()
1420
-
1421
- const extmark = extmarks.get(id)
1422
- expect(extmark?.start).toBe(3)
1423
- expect(extmark?.end).toBe(6)
1424
- expect(textarea.plainText).toBe("Hello ")
1425
- })
1426
-
1427
- it("should not adjust extmark when deleteToLineEnd after", async () => {
1428
- await setup("Hello World")
1429
-
1430
- const id = extmarks.create({
1431
- start: 0,
1432
- end: 2,
1433
- })
1434
-
1435
- textarea.focus()
1436
- textarea.cursorOffset = 5
1437
-
1438
- textarea.deleteToLineEnd()
1439
-
1440
- const extmark = extmarks.get(id)
1441
- expect(extmark?.start).toBe(0)
1442
- expect(extmark?.end).toBe(2)
1443
- expect(textarea.plainText).toBe("Hello")
1444
- })
1445
- })
1446
-
1447
- describe("deleteLine() Operations", () => {
1448
- it("should adjust extmark positions after deleteLine before extmark", async () => {
1449
- await setup("Line1\nLine2\nLine3")
1450
-
1451
- const id = extmarks.create({
1452
- start: 12,
1453
- end: 17,
1454
- })
1455
-
1456
- textarea.focus()
1457
- textarea.cursorOffset = 3
1458
-
1459
- textarea.deleteLine()
1460
-
1461
- const extmark = extmarks.get(id)
1462
- expect(extmark?.start).toBe(6)
1463
- expect(extmark?.end).toBe(11)
1464
- expect(textarea.plainText).toBe("Line2\nLine3")
1465
- })
1466
-
1467
- it("should remove extmark when deleteLine on line containing it", async () => {
1468
- await setup("Line1\nLine2\nLine3")
1469
-
1470
- const id = extmarks.create({
1471
- start: 6,
1472
- end: 11,
1473
- })
1474
-
1475
- textarea.focus()
1476
- textarea.cursorOffset = 8
1477
-
1478
- textarea.deleteLine()
1479
-
1480
- expect(extmarks.get(id)).toBeNull()
1481
- expect(textarea.plainText).toBe("Line1\nLine3")
1482
- })
1483
-
1484
- it("should not adjust extmark when deleteLine after", async () => {
1485
- await setup("Line1\nLine2\nLine3")
1486
-
1487
- const id = extmarks.create({
1488
- start: 0,
1489
- end: 5,
1490
- })
1491
-
1492
- textarea.focus()
1493
- textarea.cursorOffset = 8
1494
-
1495
- textarea.deleteLine()
1496
-
1497
- const extmark = extmarks.get(id)
1498
- expect(extmark?.start).toBe(0)
1499
- expect(extmark?.end).toBe(5)
1500
- })
1501
- })
1502
-
1503
- describe("newLine() Operations", () => {
1504
- it("should adjust extmark positions after newLine before extmark", async () => {
1505
- await setup("HelloWorld")
1506
-
1507
- const id = extmarks.create({
1508
- start: 5,
1509
- end: 10,
1510
- })
1511
-
1512
- textarea.focus()
1513
- textarea.cursorOffset = 2
1514
-
1515
- textarea.newLine()
1516
-
1517
- const extmark = extmarks.get(id)
1518
- expect(extmark?.start).toBe(6)
1519
- expect(extmark?.end).toBe(11)
1520
- expect(textarea.plainText).toBe("He\nlloWorld")
1521
- })
1522
-
1523
- it("should expand extmark when newLine inside", async () => {
1524
- await setup("HelloWorld")
1525
-
1526
- const id = extmarks.create({
1527
- start: 2,
1528
- end: 8,
1529
- })
1530
-
1531
- textarea.focus()
1532
- textarea.cursorOffset = 5
1533
-
1534
- textarea.newLine()
1535
-
1536
- const extmark = extmarks.get(id)
1537
- expect(extmark?.start).toBe(2)
1538
- expect(extmark?.end).toBe(9)
1539
- })
1540
-
1541
- it("should not adjust extmark when newLine after", async () => {
1542
- await setup("HelloWorld")
1543
-
1544
- const id = extmarks.create({
1545
- start: 0,
1546
- end: 5,
1547
- })
1548
-
1549
- textarea.focus()
1550
- textarea.cursorOffset = 10
1551
-
1552
- textarea.newLine()
1553
-
1554
- const extmark = extmarks.get(id)
1555
- expect(extmark?.start).toBe(0)
1556
- expect(extmark?.end).toBe(5)
1557
- })
1558
- })
1559
-
1560
- describe("clear() Operations", () => {
1561
- it("should clear all extmarks when clear is called", async () => {
1562
- await setup("Hello World")
1563
-
1564
- const id1 = extmarks.create({ start: 0, end: 5 })
1565
- const id2 = extmarks.create({ start: 6, end: 11, virtual: true })
1566
-
1567
- expect(extmarks.getAll().length).toBe(2)
1568
-
1569
- textarea.clear()
1570
-
1571
- expect(extmarks.getAll().length).toBe(0)
1572
- expect(extmarks.get(id1)).toBeNull()
1573
- expect(extmarks.get(id2)).toBeNull()
1574
- expect(textarea.plainText).toBe("")
1575
- })
1576
-
1577
- it("should clear all extmarks on clear", async () => {
1578
- await setup("Hello World")
1579
-
1580
- extmarks.create({ start: 0, end: 5 })
1581
- extmarks.create({ start: 6, end: 11 })
1582
-
1583
- expect(extmarks.getAll().length).toBe(2)
1584
-
1585
- textarea.clear()
1586
-
1587
- expect(extmarks.getAll().length).toBe(0)
1588
- })
1589
-
1590
- it("should allow new extmarks after clear", async () => {
1591
- await setup("Hello World")
1592
-
1593
- extmarks.create({ start: 0, end: 5 })
1594
- textarea.clear()
1595
- textarea.insertText("New")
1596
-
1597
- const newId = extmarks.create({ start: 0, end: 3 })
1598
- const extmark = extmarks.get(newId)
1599
-
1600
- expect(extmark).not.toBeNull()
1601
- expect(extmark?.start).toBe(0)
1602
- expect(extmark?.end).toBe(3)
1603
- })
1604
- })
1605
-
1606
- describe("Selection Deletion", () => {
1607
- it("should adjust extmarks when deleting selection with backspace", async () => {
1608
- await setup("hello world test")
1609
-
1610
- const id = extmarks.create({
1611
- start: 12,
1612
- end: 16,
1613
- })
1614
-
1615
- textarea.focus()
1616
- textarea.cursorOffset = 0
1617
-
1618
- currentMockInput.pressArrow("right", { shift: true })
1619
- currentMockInput.pressArrow("right", { shift: true })
1620
- currentMockInput.pressArrow("right", { shift: true })
1621
- currentMockInput.pressArrow("right", { shift: true })
1622
-
1623
- expect(textarea.hasSelection()).toBe(true)
1624
-
1625
- currentMockInput.pressBackspace()
1626
-
1627
- expect(textarea.plainText).toBe("o world test")
1628
-
1629
- const extmark = extmarks.get(id)
1630
- expect(extmark?.start).toBe(8)
1631
- expect(extmark?.end).toBe(12)
1632
- })
1633
-
1634
- it("should adjust extmarks when deleting selection with delete key", async () => {
1635
- await setup("hello world test")
1636
-
1637
- const id = extmarks.create({
1638
- start: 12,
1639
- end: 16,
1640
- })
1641
-
1642
- textarea.focus()
1643
- textarea.cursorOffset = 0
1644
-
1645
- currentMockInput.pressArrow("right", { shift: true })
1646
- currentMockInput.pressArrow("right", { shift: true })
1647
- currentMockInput.pressArrow("right", { shift: true })
1648
- currentMockInput.pressArrow("right", { shift: true })
1649
-
1650
- expect(textarea.hasSelection()).toBe(true)
1651
-
1652
- currentMockInput.pressKey("DELETE")
1653
-
1654
- expect(textarea.plainText).toBe("o world test")
1655
-
1656
- const extmark = extmarks.get(id)
1657
- expect(extmark?.start).toBe(8)
1658
- expect(extmark?.end).toBe(12)
1659
- })
1660
-
1661
- it("should adjust extmarks when replacing selection with text", async () => {
1662
- await setup("hello world test")
1663
-
1664
- const id = extmarks.create({
1665
- start: 12,
1666
- end: 16,
1667
- })
1668
-
1669
- textarea.focus()
1670
- textarea.cursorOffset = 0
1671
-
1672
- currentMockInput.pressArrow("right", { shift: true })
1673
- currentMockInput.pressArrow("right", { shift: true })
1674
- currentMockInput.pressArrow("right", { shift: true })
1675
- currentMockInput.pressArrow("right", { shift: true })
1676
- currentMockInput.pressArrow("right", { shift: true })
1677
-
1678
- expect(textarea.hasSelection()).toBe(true)
1679
-
1680
- currentMockInput.pressKey("X")
1681
-
1682
- const extmark = extmarks.get(id)
1683
- expect(extmark?.start).toBe(8)
1684
- expect(extmark?.end).toBe(12)
1685
- expect(textarea.plainText).toBe("X world test")
1686
- })
1687
-
1688
- it("should remove extmark when selection covers it", async () => {
1689
- await setup("hello world test")
1690
-
1691
- const id = extmarks.create({
1692
- start: 6,
1693
- end: 11,
1694
- })
1695
-
1696
- textarea.focus()
1697
- textarea.cursorOffset = 0
1698
-
1699
- for (let i = 0; i < 12; i++) {
1700
- currentMockInput.pressArrow("right", { shift: true })
1701
- }
1702
-
1703
- expect(textarea.hasSelection()).toBe(true)
1704
-
1705
- currentMockInput.pressBackspace()
1706
-
1707
- expect(extmarks.get(id)).toBeNull()
1708
- expect(textarea.plainText).toBe("test")
1709
- })
1710
- })
1711
-
1712
- describe("Multiline Selection Deletion", () => {
1713
- it("should adjust extmarks after deleting multiline selection", async () => {
1714
- await setup("Line 1\nLine 2\nLine 3\nLine 4")
1715
-
1716
- const id = extmarks.create({
1717
- start: 21,
1718
- end: 27,
1719
- })
1720
-
1721
- textarea.focus()
1722
- textarea.cursorOffset = 7
1723
-
1724
- for (let i = 0; i < 7; i++) {
1725
- currentMockInput.pressArrow("right", { shift: true })
1726
- }
1727
-
1728
- expect(textarea.hasSelection()).toBe(true)
1729
-
1730
- currentMockInput.pressBackspace()
1731
-
1732
- expect(textarea.plainText).toBe("Line 1\nLine 3\nLine 4")
1733
-
1734
- const extmark = extmarks.get(id)
1735
- expect(extmark).not.toBeNull()
1736
- expect(extmark?.start).toBe(14)
1737
- expect(extmark?.end).toBe(20)
1738
- })
1739
-
1740
- it("should adjust multiple extmarks after deleting multiline selection", async () => {
1741
- await setup("AAA\nBBB\nCCC\nDDD")
1742
-
1743
- const id1 = extmarks.create({
1744
- start: 8,
1745
- end: 11,
1746
- })
1747
-
1748
- const id2 = extmarks.create({
1749
- start: 12,
1750
- end: 15,
1751
- })
1752
-
1753
- textarea.focus()
1754
- textarea.cursorOffset = 0
1755
-
1756
- for (let i = 0; i < 8; i++) {
1757
- currentMockInput.pressArrow("right", { shift: true })
1758
- }
1759
-
1760
- expect(textarea.hasSelection()).toBe(true)
1761
-
1762
- currentMockInput.pressBackspace()
1763
-
1764
- expect(textarea.plainText).toBe("CCC\nDDD")
1765
-
1766
- const extmark1 = extmarks.get(id1)
1767
- expect(extmark1).not.toBeNull()
1768
- expect(extmark1?.start).toBe(0)
1769
- expect(extmark1?.end).toBe(3)
1770
- expect(textarea.plainText.substring(extmark1!.start, extmark1!.end)).toBe("CCC")
1771
-
1772
- const extmark2 = extmarks.get(id2)
1773
- expect(extmark2).not.toBeNull()
1774
- expect(extmark2?.start).toBe(4)
1775
- expect(extmark2?.end).toBe(7)
1776
- expect(textarea.plainText.substring(extmark2!.start, extmark2!.end)).toBe("DDD")
1777
- })
1778
-
1779
- it("should correctly adjust extmark spanning multiple lines after multiline deletion", async () => {
1780
- await setup("AAA\nBBB\nCCC\nDDD\nEEE")
1781
-
1782
- const id = extmarks.create({
1783
- start: 12,
1784
- end: 19,
1785
- })
1786
-
1787
- textarea.focus()
1788
- textarea.cursorOffset = 0
1789
-
1790
- for (let i = 0; i < 8; i++) {
1791
- currentMockInput.pressArrow("right", { shift: true })
1792
- }
1793
-
1794
- expect(textarea.hasSelection()).toBe(true)
1795
-
1796
- currentMockInput.pressBackspace()
1797
-
1798
- expect(textarea.plainText).toBe("CCC\nDDD\nEEE")
1799
-
1800
- const extmark = extmarks.get(id)
1801
- expect(extmark).not.toBeNull()
1802
- expect(extmark?.start).toBe(4)
1803
- expect(extmark?.end).toBe(11)
1804
- expect(textarea.plainText.substring(extmark!.start, extmark!.end)).toBe("DDD\nEEE")
1805
- })
1806
-
1807
- it("should handle deletion of selection that partially overlaps extmark start", async () => {
1808
- await setup("AAA\nBBB\nCCC\nDDD")
1809
-
1810
- const id = extmarks.create({
1811
- start: 6,
1812
- end: 11,
1813
- })
1814
-
1815
- textarea.focus()
1816
- textarea.cursorOffset = 4
1817
-
1818
- for (let i = 0; i < 6; i++) {
1819
- currentMockInput.pressArrow("right", { shift: true })
1820
- }
1821
-
1822
- expect(textarea.hasSelection()).toBe(true)
1823
-
1824
- currentMockInput.pressBackspace()
1825
-
1826
- expect(textarea.plainText).toBe("AAA\nC\nDDD")
1827
-
1828
- const extmark = extmarks.get(id)
1829
- expect(extmark).not.toBeNull()
1830
- expect(extmark?.start).toBe(4)
1831
- expect(extmark?.end).toBe(5)
1832
- })
1833
-
1834
- it("should handle deletion across three lines with extmarks after", async () => {
1835
- await setup("Line1\nLine2\nLine3\nLine4\nLine5")
1836
-
1837
- const id1 = extmarks.create({
1838
- start: 18,
1839
- end: 23,
1840
- })
1841
-
1842
- const id2 = extmarks.create({
1843
- start: 24,
1844
- end: 29,
1845
- })
1846
-
1847
- textarea.focus()
1848
- textarea.cursorOffset = 0
1849
-
1850
- for (let i = 0; i < 18; i++) {
1851
- currentMockInput.pressArrow("right", { shift: true })
1852
- }
1853
-
1854
- expect(textarea.hasSelection()).toBe(true)
1855
-
1856
- currentMockInput.pressBackspace()
1857
-
1858
- expect(textarea.plainText).toBe("Line4\nLine5")
1859
-
1860
- const extmark1 = extmarks.get(id1)
1861
- expect(extmark1).not.toBeNull()
1862
- expect(extmark1?.start).toBe(0)
1863
- expect(extmark1?.end).toBe(5)
1864
- expect(textarea.plainText.substring(extmark1!.start, extmark1!.end)).toBe("Line4")
1865
-
1866
- const extmark2 = extmarks.get(id2)
1867
- expect(extmark2).not.toBeNull()
1868
- expect(extmark2?.start).toBe(6)
1869
- expect(extmark2?.end).toBe(11)
1870
- expect(textarea.plainText.substring(extmark2!.start, extmark2!.end)).toBe("Line5")
1871
- })
1872
- })
1873
-
1874
- describe("Edge Cases", () => {
1875
- it("should handle extmark at start of text", async () => {
1876
- await setup("Hello World")
1877
-
1878
- const id = extmarks.create({
1879
- start: 0,
1880
- end: 5,
1881
- virtual: true,
1882
- })
1883
-
1884
- textarea.focus()
1885
- textarea.cursorOffset = 0
1886
-
1887
- currentMockInput.pressArrow("right")
1888
- expect(textarea.cursorOffset).toBe(5)
1889
-
1890
- const extmark = extmarks.get(id)
1891
- expect(extmark).not.toBeNull()
1892
- })
1893
-
1894
- it("should handle extmark at end of text", async () => {
1895
- await setup("Hello World")
1896
-
1897
- const id = extmarks.create({
1898
- start: 6,
1899
- end: 11,
1900
- virtual: true,
1901
- })
1902
-
1903
- textarea.focus()
1904
- textarea.cursorOffset = 11
1905
-
1906
- currentMockInput.pressArrow("left")
1907
- expect(textarea.cursorOffset).toBe(5)
1908
-
1909
- const extmark = extmarks.get(id)
1910
- expect(extmark).not.toBeNull()
1911
- })
1912
-
1913
- it("should handle zero-width extmark", async () => {
1914
- await setup("Hello World")
1915
-
1916
- const id = extmarks.create({
1917
- start: 5,
1918
- end: 5,
1919
- })
1920
-
1921
- const extmark = extmarks.get(id)
1922
- expect(extmark?.start).toBe(5)
1923
- expect(extmark?.end).toBe(5)
1924
- })
1925
-
1926
- it("should handle overlapping extmarks", async () => {
1927
- await setup("Hello World")
1928
-
1929
- const id1 = extmarks.create({ start: 0, end: 7 })
1930
- const id2 = extmarks.create({ start: 3, end: 9 })
1931
-
1932
- const atOffset5 = extmarks.getAtOffset(5)
1933
- expect(atOffset5.length).toBe(2)
1934
- expect(atOffset5.map((e) => e.id).sort()).toEqual([id1, id2])
1935
- })
1936
-
1937
- it("should handle empty text", async () => {
1938
- await setup("")
1939
-
1940
- const id = extmarks.create({
1941
- start: 0,
1942
- end: 0,
1943
- })
1944
-
1945
- const extmark = extmarks.get(id)
1946
- expect(extmark).not.toBeNull()
1947
- })
1948
- })
1949
-
1950
- describe("Virtual Extmark - Cursor Up/Down Movement", () => {
1951
- it("should not land inside virtual extmark when moving down", async () => {
1952
- await setup("abc\n[VIRTUAL]\ndef")
1953
-
1954
- textarea.focus()
1955
- textarea.cursorOffset = 1
1956
-
1957
- extmarks.create({
1958
- start: 4,
1959
- end: 13,
1960
- virtual: true,
1961
- })
1962
-
1963
- expect(textarea.cursorOffset).toBe(1)
1964
-
1965
- currentMockInput.pressArrow("down")
1966
- const cursorAfterDown = textarea.cursorOffset
1967
-
1968
- const isInsideExtmark = cursorAfterDown >= 4 && cursorAfterDown < 13
1969
- expect(isInsideExtmark).toBe(false)
1970
- })
1971
-
1972
- it("should not land inside virtual extmark when moving up", async () => {
1973
- await setup("abc\n[VIRTUAL]\ndef")
1974
-
1975
- textarea.focus()
1976
- textarea.cursorOffset = 15
1977
-
1978
- extmarks.create({
1979
- start: 4,
1980
- end: 13,
1981
- virtual: true,
1982
- })
1983
-
1984
- expect(textarea.cursorOffset).toBe(15)
1985
-
1986
- currentMockInput.pressArrow("up")
1987
- const cursorAfterUp = textarea.cursorOffset
1988
-
1989
- const isInsideExtmark = cursorAfterUp >= 4 && cursorAfterUp < 13
1990
- expect(isInsideExtmark).toBe(false)
1991
- })
1992
-
1993
- it("should jump to closest boundary when moving down into virtual extmark", async () => {
1994
- await setup("abc\n[VIRTUAL]\ndef")
1995
-
1996
- textarea.focus()
1997
- textarea.cursorOffset = 1
1998
-
1999
- extmarks.create({
2000
- start: 4,
2001
- end: 13,
2002
- virtual: true,
2003
- })
2004
-
2005
- currentMockInput.pressArrow("down")
2006
- const cursorAfterDown = textarea.cursorOffset
2007
-
2008
- expect(cursorAfterDown === 3 || cursorAfterDown === 13).toBe(true)
2009
- })
2010
-
2011
- it("should jump to closest boundary when moving up into virtual extmark", async () => {
2012
- await setup("abc\n[VIRTUAL]\ndef")
2013
-
2014
- textarea.focus()
2015
- textarea.cursorOffset = 15
2016
-
2017
- extmarks.create({
2018
- start: 4,
2019
- end: 13,
2020
- virtual: true,
2021
- })
2022
-
2023
- currentMockInput.pressArrow("up")
2024
- const cursorAfterUp = textarea.cursorOffset
2025
-
2026
- expect(cursorAfterUp === 3 || cursorAfterUp === 13).toBe(true)
2027
- })
2028
-
2029
- it("should handle multiline virtual extmarks when moving up", async () => {
2030
- await setup("line1\n[VIRTUAL\nMULTILINE]\nline4")
2031
-
2032
- textarea.focus()
2033
- textarea.cursorOffset = 28
2034
-
2035
- extmarks.create({
2036
- start: 6,
2037
- end: 25,
2038
- virtual: true,
2039
- })
2040
-
2041
- currentMockInput.pressArrow("up")
2042
- currentMockInput.pressArrow("up")
2043
- const cursorAfterUp = textarea.cursorOffset
2044
-
2045
- const isInsideExtmark = cursorAfterUp >= 6 && cursorAfterUp < 25
2046
- expect(isInsideExtmark).toBe(false)
2047
- })
2048
-
2049
- it("should handle multiline virtual extmarks when moving down", async () => {
2050
- await setup("line1\n[VIRTUAL\nMULTILINE]\nline4")
2051
-
2052
- textarea.focus()
2053
- textarea.cursorOffset = 3
2054
-
2055
- extmarks.create({
2056
- start: 6,
2057
- end: 25,
2058
- virtual: true,
2059
- })
2060
-
2061
- currentMockInput.pressArrow("down")
2062
- currentMockInput.pressArrow("down")
2063
- const cursorAfterDown = textarea.cursorOffset
2064
-
2065
- const isInsideExtmark = cursorAfterDown >= 6 && cursorAfterDown < 25
2066
- expect(isInsideExtmark).toBe(false)
2067
- })
2068
-
2069
- it("should not get stuck when moving down into virtual extmark at start of line", async () => {
2070
- // Regression test for cursor getting stuck when moving down over
2071
- // virtual extmarks at the beginning of lines.
2072
- // Setup:
2073
- // Line 0: "a"
2074
- // Line 1: "" (empty)
2075
- // Line 2: "[EXT]" (virtual extmark starting at column 0)
2076
- // Line 3: "b"
2077
- await setup("a\n\n[EXT]\nb")
2078
-
2079
- textarea.focus()
2080
- textarea.cursorOffset = 2
2081
-
2082
- const virtualStart = 3
2083
- const virtualEnd = 8
2084
-
2085
- extmarks.create({
2086
- start: virtualStart,
2087
- end: virtualEnd,
2088
- virtual: true,
2089
- })
2090
-
2091
- const initialOffset = textarea.cursorOffset
2092
- expect(initialOffset).toBe(2)
2093
-
2094
- currentMockInput.pressArrow("down")
2095
- const cursorAfterDown = textarea.cursorOffset
2096
-
2097
- expect(cursorAfterDown).toBe(virtualEnd)
2098
- })
2099
-
2100
- it("should land at trailing text when moving down into line-start virtual extmark", async () => {
2101
- await setup("a\n\n[EXT]tail\nb")
2102
-
2103
- textarea.focus()
2104
- textarea.cursorOffset = 2
2105
-
2106
- const virtualStart = 3
2107
- const virtualEnd = 8
2108
-
2109
- extmarks.create({
2110
- start: virtualStart,
2111
- end: virtualEnd,
2112
- virtual: true,
2113
- })
2114
-
2115
- currentMockInput.pressArrow("down")
2116
-
2117
- const cursorAfterDown = textarea.cursorOffset
2118
-
2119
- expect(cursorAfterDown).toBe(virtualEnd)
2120
- expect(textarea.plainText.slice(cursorAfterDown, cursorAfterDown + 4)).toBe("tail")
2121
- })
2122
-
2123
- it("should not jump past buffer end when moving down into line-start virtual extmark at EOF", async () => {
2124
- await setup("a\n\n[EXT]")
2125
-
2126
- textarea.focus()
2127
- textarea.cursorOffset = 2
2128
-
2129
- const virtualStart = 3
2130
- const virtualEnd = 8
2131
-
2132
- extmarks.create({
2133
- start: virtualStart,
2134
- end: virtualEnd,
2135
- virtual: true,
2136
- })
2137
-
2138
- currentMockInput.pressArrow("down")
2139
-
2140
- const cursorAfterDown = textarea.cursorOffset
2141
-
2142
- expect(cursorAfterDown).toBe(virtualEnd)
2143
- expect(cursorAfterDown).toBe(textarea.plainText.length)
2144
- })
2145
-
2146
- it("should navigate past virtual extmark at line start with repeated down presses", async () => {
2147
- await setup("abc\n\n[EXTMARK]\n\nxyz")
2148
-
2149
- textarea.focus()
2150
- textarea.cursorOffset = 0
2151
-
2152
- const virtualStart = 5
2153
- const virtualEnd = 14
2154
-
2155
- extmarks.create({
2156
- start: virtualStart,
2157
- end: virtualEnd,
2158
- virtual: true,
2159
- })
2160
-
2161
- currentMockInput.pressArrow("down")
2162
- currentMockInput.pressArrow("down")
2163
- const afterExtmark = textarea.cursorOffset
2164
-
2165
- expect(afterExtmark).toBe(virtualEnd)
2166
-
2167
- currentMockInput.pressArrow("down")
2168
- currentMockInput.pressArrow("down")
2169
- const finalOffset = textarea.cursorOffset
2170
-
2171
- const xyzStart = textarea.plainText.indexOf("xyz")
2172
- expect(finalOffset).toBeGreaterThanOrEqual(xyzStart)
2173
- expect(finalOffset).toBeLessThanOrEqual(textarea.plainText.length)
2174
- })
2175
- })
2176
-
2177
- describe("TypeId Operations", () => {
2178
- it("should create extmark with default typeId 0", async () => {
2179
- await setup()
2180
-
2181
- const id = extmarks.create({
2182
- start: 0,
2183
- end: 5,
2184
- })
2185
-
2186
- const extmark = extmarks.get(id)
2187
- expect(extmark?.typeId).toBe(0)
2188
- })
2189
-
2190
- it("should create extmark with custom typeId", async () => {
2191
- await setup()
2192
-
2193
- const id = extmarks.create({
2194
- start: 0,
2195
- end: 5,
2196
- typeId: 42,
2197
- })
2198
-
2199
- const extmark = extmarks.get(id)
2200
- expect(extmark?.typeId).toBe(42)
2201
- })
2202
-
2203
- it("should retrieve all extmarks for a specific typeId", async () => {
2204
- await setup()
2205
-
2206
- const id1 = extmarks.create({ start: 0, end: 5, typeId: 1 })
2207
- const id2 = extmarks.create({ start: 6, end: 11, typeId: 1 })
2208
- const id3 = extmarks.create({ start: 12, end: 15, typeId: 2 })
2209
-
2210
- const type1Marks = extmarks.getAllForTypeId(1)
2211
- expect(type1Marks.length).toBe(2)
2212
- expect(type1Marks.map((e) => e.id).sort()).toEqual([id1, id2])
2213
-
2214
- const type2Marks = extmarks.getAllForTypeId(2)
2215
- expect(type2Marks.length).toBe(1)
2216
- expect(type2Marks[0].id).toBe(id3)
2217
- })
2218
-
2219
- it("should return empty array for non-existent typeId", async () => {
2220
- await setup()
2221
-
2222
- extmarks.create({ start: 0, end: 5, typeId: 1 })
2223
-
2224
- const noMarks = extmarks.getAllForTypeId(999)
2225
- expect(noMarks.length).toBe(0)
2226
- })
2227
-
2228
- it("should handle multiple extmarks with same typeId", async () => {
2229
- await setup()
2230
-
2231
- const ids = []
2232
- for (let i = 0; i < 10; i++) {
2233
- ids.push(extmarks.create({ start: i, end: i + 1, typeId: 5 }))
2234
- }
2235
-
2236
- const type5Marks = extmarks.getAllForTypeId(5)
2237
- expect(type5Marks.length).toBe(10)
2238
- expect(type5Marks.map((e) => e.id).sort()).toEqual(ids.sort())
2239
- })
2240
-
2241
- it("should remove extmark from typeId index when deleted", async () => {
2242
- await setup()
2243
-
2244
- const id = extmarks.create({ start: 0, end: 5, typeId: 3 })
2245
-
2246
- let type3Marks = extmarks.getAllForTypeId(3)
2247
- expect(type3Marks.length).toBe(1)
2248
-
2249
- extmarks.delete(id)
2250
-
2251
- type3Marks = extmarks.getAllForTypeId(3)
2252
- expect(type3Marks.length).toBe(0)
2253
- })
2254
-
2255
- it("should clear all typeId indexes when clear is called", async () => {
2256
- await setup()
2257
-
2258
- extmarks.create({ start: 0, end: 5, typeId: 1 })
2259
- extmarks.create({ start: 6, end: 11, typeId: 2 })
2260
- extmarks.create({ start: 12, end: 15, typeId: 3 })
2261
-
2262
- extmarks.clear()
2263
-
2264
- expect(extmarks.getAllForTypeId(1).length).toBe(0)
2265
- expect(extmarks.getAllForTypeId(2).length).toBe(0)
2266
- expect(extmarks.getAllForTypeId(3).length).toBe(0)
2267
- })
2268
-
2269
- it("should maintain typeId through text operations", async () => {
2270
- await setup("Hello World")
2271
-
2272
- const id = extmarks.create({
2273
- start: 6,
2274
- end: 11,
2275
- typeId: 7,
2276
- })
2277
-
2278
- textarea.focus()
2279
- textarea.cursorOffset = 0
2280
- currentMockInput.pressKey("X")
2281
- currentMockInput.pressKey("X")
2282
-
2283
- const extmark = extmarks.get(id)
2284
- expect(extmark?.typeId).toBe(7)
2285
-
2286
- const type7Marks = extmarks.getAllForTypeId(7)
2287
- expect(type7Marks.length).toBe(1)
2288
- expect(type7Marks[0].id).toBe(id)
2289
- })
2290
-
2291
- it("should group virtual and non-virtual extmarks by typeId", async () => {
2292
- await setup()
2293
-
2294
- const id1 = extmarks.create({ start: 0, end: 5, typeId: 10, virtual: false })
2295
- const id2 = extmarks.create({ start: 6, end: 11, typeId: 10, virtual: true })
2296
- const id3 = extmarks.create({ start: 12, end: 15, typeId: 10, virtual: false })
2297
-
2298
- const type10Marks = extmarks.getAllForTypeId(10)
2299
- expect(type10Marks.length).toBe(3)
2300
-
2301
- const virtualMarks = type10Marks.filter((e) => e.virtual)
2302
- const nonVirtualMarks = type10Marks.filter((e) => !e.virtual)
2303
-
2304
- expect(virtualMarks.length).toBe(1)
2305
- expect(nonVirtualMarks.length).toBe(2)
2306
- })
2307
-
2308
- it("should handle typeId 0 as default", async () => {
2309
- await setup()
2310
-
2311
- const id1 = extmarks.create({ start: 0, end: 5 })
2312
- const id2 = extmarks.create({ start: 6, end: 11, typeId: 0 })
2313
- const id3 = extmarks.create({ start: 12, end: 15 })
2314
-
2315
- const type0Marks = extmarks.getAllForTypeId(0)
2316
- expect(type0Marks.length).toBe(3)
2317
- expect(type0Marks.map((e) => e.id).sort()).toEqual([id1, id2, id3])
2318
- })
2319
-
2320
- it("should remove extmark from typeId index on deletion during backspace", async () => {
2321
- await setup("abc[LINK]def")
2322
-
2323
- textarea.focus()
2324
- textarea.cursorOffset = 9
2325
-
2326
- const id = extmarks.create({
2327
- start: 3,
2328
- end: 9,
2329
- virtual: true,
2330
- typeId: 15,
2331
- })
2332
-
2333
- let type15Marks = extmarks.getAllForTypeId(15)
2334
- expect(type15Marks.length).toBe(1)
2335
-
2336
- currentMockInput.pressBackspace()
2337
-
2338
- expect(extmarks.get(id)).toBeNull()
2339
-
2340
- type15Marks = extmarks.getAllForTypeId(15)
2341
- expect(type15Marks.length).toBe(0)
2342
- })
2343
-
2344
- it("should remove extmark from typeId index on deletion during delete key", async () => {
2345
- await setup("abc[LINK]def")
2346
-
2347
- textarea.focus()
2348
- textarea.cursorOffset = 3
2349
-
2350
- const id = extmarks.create({
2351
- start: 3,
2352
- end: 9,
2353
- virtual: true,
2354
- typeId: 20,
2355
- })
2356
-
2357
- let type20Marks = extmarks.getAllForTypeId(20)
2358
- expect(type20Marks.length).toBe(1)
2359
-
2360
- currentMockInput.pressKey("DELETE")
2361
-
2362
- expect(extmarks.get(id)).toBeNull()
2363
-
2364
- type20Marks = extmarks.getAllForTypeId(20)
2365
- expect(type20Marks.length).toBe(0)
2366
- })
2367
-
2368
- it("should handle getAllForTypeId on destroyed controller", async () => {
2369
- await setup()
2370
-
2371
- extmarks.create({ start: 0, end: 5, typeId: 1 })
2372
-
2373
- extmarks.destroy()
2374
-
2375
- const type1Marks = extmarks.getAllForTypeId(1)
2376
- expect(type1Marks.length).toBe(0)
2377
- })
2378
-
2379
- it("should support multiple different typeIds simultaneously", async () => {
2380
- await setup("The quick brown fox jumps over the lazy dog")
2381
-
2382
- const linkId1 = extmarks.create({ start: 0, end: 3, typeId: 1 })
2383
- const linkId2 = extmarks.create({ start: 10, end: 15, typeId: 1 })
2384
-
2385
- const tagId1 = extmarks.create({ start: 4, end: 9, typeId: 2 })
2386
- const tagId2 = extmarks.create({ start: 16, end: 19, typeId: 2 })
2387
-
2388
- const markerId = extmarks.create({ start: 20, end: 25, typeId: 3 })
2389
-
2390
- const links = extmarks.getAllForTypeId(1)
2391
- expect(links.length).toBe(2)
2392
- expect(links.map((e) => e.id).sort()).toEqual([linkId1, linkId2])
2393
-
2394
- const tags = extmarks.getAllForTypeId(2)
2395
- expect(tags.length).toBe(2)
2396
- expect(tags.map((e) => e.id).sort()).toEqual([tagId1, tagId2])
2397
-
2398
- const markers = extmarks.getAllForTypeId(3)
2399
- expect(markers.length).toBe(1)
2400
- expect(markers[0].id).toBe(markerId)
2401
-
2402
- const allExtmarks = extmarks.getAll()
2403
- expect(allExtmarks.length).toBe(5)
2404
- })
2405
-
2406
- it("should preserve typeId when extmark is adjusted after insertion", async () => {
2407
- await setup("Hello World")
2408
-
2409
- const id = extmarks.create({
2410
- start: 6,
2411
- end: 11,
2412
- typeId: 50,
2413
- })
2414
-
2415
- textarea.focus()
2416
- textarea.cursorOffset = 0
2417
- currentMockInput.pressKey("Z")
2418
-
2419
- const extmark = extmarks.get(id)
2420
- expect(extmark?.typeId).toBe(50)
2421
- expect(extmark?.start).toBe(7)
2422
- expect(extmark?.end).toBe(12)
2423
-
2424
- const type50Marks = extmarks.getAllForTypeId(50)
2425
- expect(type50Marks.length).toBe(1)
2426
- })
2427
-
2428
- it("should preserve typeId when extmark is adjusted after deletion", async () => {
2429
- await setup("XXHello World")
2430
-
2431
- const id = extmarks.create({
2432
- start: 8,
2433
- end: 13,
2434
- typeId: 60,
2435
- })
2436
-
2437
- textarea.focus()
2438
- textarea.cursorOffset = 2
2439
- currentMockInput.pressBackspace()
2440
- currentMockInput.pressBackspace()
2441
-
2442
- const extmark = extmarks.get(id)
2443
- expect(extmark?.typeId).toBe(60)
2444
- expect(extmark?.start).toBe(6)
2445
- expect(extmark?.end).toBe(11)
2446
-
2447
- const type60Marks = extmarks.getAllForTypeId(60)
2448
- expect(type60Marks.length).toBe(1)
2449
- })
2450
- })
2451
-
2452
- describe("Undo/Redo with Extmarks", () => {
2453
- it("should restore extmark after undo of text insertion", async () => {
2454
- await setup("Hello World")
2455
-
2456
- const id = extmarks.create({
2457
- start: 0,
2458
- end: 5,
2459
- styleId: 1,
2460
- })
2461
-
2462
- textarea.focus()
2463
- textarea.cursorOffset = 3
2464
- currentMockInput.pressKey("X")
2465
-
2466
- const extmarkAfterInsert = extmarks.get(id)
2467
- expect(extmarkAfterInsert?.start).toBe(0)
2468
- expect(extmarkAfterInsert?.end).toBe(6)
2469
-
2470
- textarea.undo()
2471
-
2472
- const extmarkAfterUndo = extmarks.get(id)
2473
- expect(extmarkAfterUndo?.start).toBe(0)
2474
- expect(extmarkAfterUndo?.end).toBe(5)
2475
- })
2476
-
2477
- it("should restore extmark after undo of text deletion", async () => {
2478
- await setup("Hello World")
2479
-
2480
- const id = extmarks.create({
2481
- start: 6,
2482
- end: 11,
2483
- styleId: 1,
2484
- })
2485
-
2486
- textarea.focus()
2487
- textarea.cursorOffset = 0
2488
- currentMockInput.pressKey("DELETE")
2489
-
2490
- const extmarkAfterDelete = extmarks.get(id)
2491
- expect(extmarkAfterDelete?.start).toBe(5)
2492
- expect(extmarkAfterDelete?.end).toBe(10)
2493
-
2494
- textarea.undo()
2495
-
2496
- const extmarkAfterUndo = extmarks.get(id)
2497
- expect(extmarkAfterUndo?.start).toBe(6)
2498
- expect(extmarkAfterUndo?.end).toBe(11)
2499
- })
2500
-
2501
- it("should restore extmark after redo", async () => {
2502
- await setup("Hello World")
2503
-
2504
- const id = extmarks.create({
2505
- start: 0,
2506
- end: 5,
2507
- styleId: 1,
2508
- })
2509
-
2510
- textarea.focus()
2511
- textarea.cursorOffset = 3
2512
- currentMockInput.pressKey("X")
2513
-
2514
- const extmarkAfterInsert = extmarks.get(id)
2515
- expect(extmarkAfterInsert?.start).toBe(0)
2516
- expect(extmarkAfterInsert?.end).toBe(6)
2517
-
2518
- textarea.undo()
2519
-
2520
- const extmarkAfterUndo = extmarks.get(id)
2521
- expect(extmarkAfterUndo?.start).toBe(0)
2522
- expect(extmarkAfterUndo?.end).toBe(5)
2523
-
2524
- textarea.redo()
2525
-
2526
- const extmarkAfterRedo = extmarks.get(id)
2527
- expect(extmarkAfterRedo?.start).toBe(0)
2528
- expect(extmarkAfterRedo?.end).toBe(6)
2529
- })
2530
-
2531
- it("should restore deleted virtual extmark after undo", async () => {
2532
- await setup("abc[LINK]def")
2533
-
2534
- textarea.focus()
2535
- textarea.cursorOffset = 9
2536
-
2537
- const id = extmarks.create({
2538
- start: 3,
2539
- end: 9,
2540
- virtual: true,
2541
- })
2542
-
2543
- currentMockInput.pressBackspace()
2544
-
2545
- expect(textarea.plainText).toBe("abcdef")
2546
- expect(extmarks.get(id)).toBeNull()
2547
-
2548
- textarea.undo()
2549
-
2550
- const extmarkAfterUndo = extmarks.get(id)
2551
- expect(extmarkAfterUndo).not.toBeNull()
2552
- expect(extmarkAfterUndo?.start).toBe(3)
2553
- expect(extmarkAfterUndo?.end).toBe(9)
2554
- expect(extmarkAfterUndo?.virtual).toBe(true)
2555
- expect(textarea.plainText).toBe("abc[LINK]def")
2556
- })
2557
-
2558
- it("should handle multiple undo/redo operations", async () => {
2559
- await setup("Test")
2560
-
2561
- const id = extmarks.create({
2562
- start: 0,
2563
- end: 4,
2564
- })
2565
-
2566
- textarea.focus()
2567
- textarea.cursorOffset = 2
2568
-
2569
- currentMockInput.pressKey("1")
2570
- expect(extmarks.get(id)?.end).toBe(5)
2571
-
2572
- currentMockInput.pressKey("2")
2573
- expect(extmarks.get(id)?.end).toBe(6)
2574
-
2575
- currentMockInput.pressKey("3")
2576
- expect(extmarks.get(id)?.end).toBe(7)
2577
-
2578
- textarea.undo()
2579
- expect(extmarks.get(id)?.end).toBe(6)
2580
-
2581
- textarea.undo()
2582
- expect(extmarks.get(id)?.end).toBe(5)
2583
-
2584
- textarea.undo()
2585
- expect(extmarks.get(id)?.end).toBe(4)
2586
-
2587
- textarea.redo()
2588
- expect(extmarks.get(id)?.end).toBe(5)
2589
-
2590
- textarea.redo()
2591
- expect(extmarks.get(id)?.end).toBe(6)
2592
-
2593
- textarea.redo()
2594
- expect(extmarks.get(id)?.end).toBe(7)
2595
- })
2596
-
2597
- it("should restore multiple extmarks after undo", async () => {
2598
- await setup("Hello World Test")
2599
-
2600
- const id1 = extmarks.create({
2601
- start: 0,
2602
- end: 5,
2603
- })
2604
-
2605
- const id2 = extmarks.create({
2606
- start: 6,
2607
- end: 11,
2608
- })
2609
-
2610
- textarea.focus()
2611
- textarea.cursorOffset = 0
2612
- currentMockInput.pressKey("X")
2613
-
2614
- expect(extmarks.get(id1)?.start).toBe(1)
2615
- expect(extmarks.get(id1)?.end).toBe(6)
2616
- expect(extmarks.get(id2)?.start).toBe(7)
2617
- expect(extmarks.get(id2)?.end).toBe(12)
2618
-
2619
- textarea.undo()
2620
-
2621
- expect(extmarks.get(id1)?.start).toBe(0)
2622
- expect(extmarks.get(id1)?.end).toBe(5)
2623
- expect(extmarks.get(id2)?.start).toBe(6)
2624
- expect(extmarks.get(id2)?.end).toBe(11)
2625
- })
2626
-
2627
- it("should handle undo after backspace that deleted virtual extmark", async () => {
2628
- await setup("text[VIRTUAL]more")
2629
-
2630
- textarea.focus()
2631
- textarea.cursorOffset = 13
2632
-
2633
- const id = extmarks.create({
2634
- start: 4,
2635
- end: 13,
2636
- virtual: true,
2637
- })
2638
-
2639
- currentMockInput.pressBackspace()
2640
-
2641
- expect(textarea.plainText).toBe("textmore")
2642
- expect(extmarks.get(id)).toBeNull()
2643
-
2644
- textarea.undo()
2645
-
2646
- const restoredExtmark = extmarks.get(id)
2647
- expect(restoredExtmark).not.toBeNull()
2648
- expect(restoredExtmark?.start).toBe(4)
2649
- expect(restoredExtmark?.end).toBe(13)
2650
- expect(restoredExtmark?.virtual).toBe(true)
2651
- })
2652
-
2653
- it("should restore extmark IDs correctly after undo", async () => {
2654
- await setup("Test")
2655
-
2656
- const id1 = extmarks.create({
2657
- start: 0,
2658
- end: 2,
2659
- })
2660
-
2661
- const id2 = extmarks.create({
2662
- start: 2,
2663
- end: 4,
2664
- })
2665
-
2666
- textarea.focus()
2667
- textarea.cursorOffset = 0
2668
- currentMockInput.pressKey("X")
2669
-
2670
- textarea.undo()
2671
-
2672
- expect(extmarks.get(id1)).not.toBeNull()
2673
- expect(extmarks.get(id2)).not.toBeNull()
2674
- expect(extmarks.get(id1)?.id).toBe(id1)
2675
- expect(extmarks.get(id2)?.id).toBe(id2)
2676
- })
2677
-
2678
- it("should preserve extmark data after undo/redo", async () => {
2679
- await setup("Hello")
2680
-
2681
- const id = extmarks.create({
2682
- start: 0,
2683
- end: 5,
2684
- data: { type: "link", url: "https://example.com" },
2685
- })
2686
-
2687
- textarea.focus()
2688
- textarea.cursorOffset = 5
2689
- currentMockInput.pressKey("X")
2690
-
2691
- textarea.undo()
2692
-
2693
- const extmark = extmarks.get(id)
2694
- expect(extmark?.data).toEqual({ type: "link", url: "https://example.com" })
2695
-
2696
- textarea.redo()
2697
-
2698
- const extmarkAfterRedo = extmarks.get(id)
2699
- expect(extmarkAfterRedo?.data).toEqual({ type: "link", url: "https://example.com" })
2700
- })
2701
-
2702
- it("should handle undo/redo with multiline extmarks", async () => {
2703
- await setup("Line1\nLine2\nLine3")
2704
-
2705
- const id = extmarks.create({
2706
- start: 6,
2707
- end: 11,
2708
- })
2709
-
2710
- textarea.focus()
2711
- textarea.cursorOffset = 0
2712
- currentMockInput.pressKey("X")
2713
-
2714
- expect(extmarks.get(id)?.start).toBe(7)
2715
- expect(extmarks.get(id)?.end).toBe(12)
2716
-
2717
- textarea.undo()
2718
-
2719
- expect(extmarks.get(id)?.start).toBe(6)
2720
- expect(extmarks.get(id)?.end).toBe(11)
2721
-
2722
- textarea.redo()
2723
-
2724
- expect(extmarks.get(id)?.start).toBe(7)
2725
- expect(extmarks.get(id)?.end).toBe(12)
2726
- })
2727
-
2728
- it("should handle undo after deleteRange", async () => {
2729
- await setup("Hello World Test")
2730
-
2731
- const id = extmarks.create({
2732
- start: 12,
2733
- end: 16,
2734
- })
2735
-
2736
- textarea.focus()
2737
- textarea.deleteRange(0, 0, 0, 6)
2738
-
2739
- expect(extmarks.get(id)?.start).toBe(6)
2740
- expect(extmarks.get(id)?.end).toBe(10)
2741
-
2742
- textarea.undo()
2743
-
2744
- expect(extmarks.get(id)?.start).toBe(12)
2745
- expect(extmarks.get(id)?.end).toBe(16)
2746
- })
2747
-
2748
- it("should maintain correct nextId after undo/redo", async () => {
2749
- await setup("Test")
2750
-
2751
- extmarks.create({ start: 0, end: 2 })
2752
-
2753
- textarea.focus()
2754
- textarea.cursorOffset = 4
2755
- currentMockInput.pressKey("X")
2756
-
2757
- textarea.undo()
2758
-
2759
- const newId = extmarks.create({ start: 2, end: 4 })
2760
-
2761
- expect(newId).toBe(2)
2762
- })
2763
-
2764
- it("should handle undo/redo of selection deletion", async () => {
2765
- await setup("Hello World")
2766
-
2767
- const id = extmarks.create({
2768
- start: 6,
2769
- end: 11,
2770
- })
2771
-
2772
- textarea.focus()
2773
- textarea.cursorOffset = 0
2774
-
2775
- for (let i = 0; i < 5; i++) {
2776
- currentMockInput.pressArrow("right", { shift: true })
2777
- }
2778
-
2779
- currentMockInput.pressBackspace()
2780
-
2781
- expect(textarea.plainText).toBe(" World")
2782
- expect(extmarks.get(id)?.start).toBe(1)
2783
- expect(extmarks.get(id)?.end).toBe(6)
2784
-
2785
- textarea.undo()
2786
-
2787
- expect(textarea.plainText).toBe("Hello World")
2788
- expect(extmarks.get(id)?.start).toBe(6)
2789
- expect(extmarks.get(id)?.end).toBe(11)
2790
- })
2791
- })
2792
-
2793
- describe("Type Registry", () => {
2794
- it("should register a type name and return a unique typeId", async () => {
2795
- await setup()
2796
-
2797
- const linkTypeId = extmarks.registerType("link")
2798
- expect(linkTypeId).toBe(1)
2799
-
2800
- const tagTypeId = extmarks.registerType("tag")
2801
- expect(tagTypeId).toBe(2)
2802
-
2803
- expect(linkTypeId).not.toBe(tagTypeId)
2804
- })
2805
-
2806
- it("should return the same typeId for duplicate type name registration", async () => {
2807
- await setup()
2808
-
2809
- const firstId = extmarks.registerType("link")
2810
- const secondId = extmarks.registerType("link")
2811
-
2812
- expect(firstId).toBe(secondId)
2813
- })
2814
-
2815
- it("should resolve typeName to typeId", async () => {
2816
- await setup()
2817
-
2818
- const linkTypeId = extmarks.registerType("link")
2819
- const resolvedId = extmarks.getTypeId("link")
2820
-
2821
- expect(resolvedId).toBe(linkTypeId)
2822
- })
2823
-
2824
- it("should return null for unregistered typeName", async () => {
2825
- await setup()
2826
-
2827
- const resolvedId = extmarks.getTypeId("nonexistent")
2828
- expect(resolvedId).toBeNull()
2829
- })
2830
-
2831
- it("should resolve typeId to typeName", async () => {
2832
- await setup()
2833
-
2834
- const linkTypeId = extmarks.registerType("link")
2835
- const resolvedName = extmarks.getTypeName(linkTypeId)
2836
-
2837
- expect(resolvedName).toBe("link")
2838
- })
2839
-
2840
- it("should return null for unregistered typeId", async () => {
2841
- await setup()
2842
-
2843
- const resolvedName = extmarks.getTypeName(999)
2844
- expect(resolvedName).toBeNull()
2845
- })
2846
-
2847
- it("should create extmark with registered type", async () => {
2848
- await setup()
2849
-
2850
- const linkTypeId = extmarks.registerType("link")
2851
- const extmarkId = extmarks.create({
2852
- start: 0,
2853
- end: 5,
2854
- typeId: linkTypeId,
2855
- })
2856
-
2857
- const extmark = extmarks.get(extmarkId)
2858
- expect(extmark?.typeId).toBe(linkTypeId)
2859
- })
2860
-
2861
- it("should retrieve extmarks by registered type name", async () => {
2862
- await setup()
2863
-
2864
- const linkTypeId = extmarks.registerType("link")
2865
- const tagTypeId = extmarks.registerType("tag")
2866
-
2867
- const linkId1 = extmarks.create({ start: 0, end: 5, typeId: linkTypeId })
2868
- const linkId2 = extmarks.create({ start: 6, end: 11, typeId: linkTypeId })
2869
- const tagId = extmarks.create({ start: 12, end: 15, typeId: tagTypeId })
2870
-
2871
- const linkExtmarks = extmarks.getAllForTypeId(linkTypeId)
2872
- expect(linkExtmarks.length).toBe(2)
2873
- expect(linkExtmarks.map((e) => e.id).sort()).toEqual([linkId1, linkId2])
2874
-
2875
- const tagExtmarks = extmarks.getAllForTypeId(tagTypeId)
2876
- expect(tagExtmarks.length).toBe(1)
2877
- expect(tagExtmarks[0].id).toBe(tagId)
2878
- })
2879
-
2880
- it("should handle multiple type registrations", async () => {
2881
- await setup()
2882
-
2883
- const types = ["link", "tag", "marker", "highlight", "error"]
2884
- const typeIds = types.map((type) => extmarks.registerType(type))
2885
-
2886
- expect(new Set(typeIds).size).toBe(types.length)
2887
-
2888
- for (let i = 0; i < types.length; i++) {
2889
- expect(extmarks.getTypeId(types[i])).toBe(typeIds[i])
2890
- expect(extmarks.getTypeName(typeIds[i])).toBe(types[i])
2891
- }
2892
- })
2893
-
2894
- it("should preserve type registry across text operations", async () => {
2895
- await setup("Hello World")
2896
-
2897
- const linkTypeId = extmarks.registerType("link")
2898
- const extmarkId = extmarks.create({
2899
- start: 0,
2900
- end: 5,
2901
- typeId: linkTypeId,
2902
- })
2903
-
2904
- textarea.focus()
2905
- textarea.cursorOffset = 0
2906
- currentMockInput.pressKey("X")
2907
-
2908
- expect(extmarks.getTypeId("link")).toBe(linkTypeId)
2909
- expect(extmarks.getTypeName(linkTypeId)).toBe("link")
2910
-
2911
- const extmark = extmarks.get(extmarkId)
2912
- expect(extmark?.typeId).toBe(linkTypeId)
2913
- })
2914
-
2915
- it("should clear type registry on destroy", async () => {
2916
- await setup()
2917
-
2918
- const linkTypeId = extmarks.registerType("link")
2919
- extmarks.registerType("tag")
2920
-
2921
- extmarks.destroy()
2922
-
2923
- expect(extmarks.getTypeId("link")).toBeNull()
2924
- expect(extmarks.getTypeName(linkTypeId)).toBeNull()
2925
- })
2926
-
2927
- it("should throw error when registering type on destroyed controller", async () => {
2928
- await setup()
2929
-
2930
- extmarks.destroy()
2931
-
2932
- expect(() => {
2933
- extmarks.registerType("link")
2934
- }).toThrow("ExtmarksController is destroyed")
2935
- })
2936
-
2937
- it("should support workflow of register then create extmarks", async () => {
2938
- await setup("The quick brown fox")
2939
-
2940
- const linkTypeId = extmarks.registerType("link")
2941
- const emphasisTypeId = extmarks.registerType("emphasis")
2942
-
2943
- const link1 = extmarks.create({ start: 0, end: 3, typeId: linkTypeId, virtual: true })
2944
- const link2 = extmarks.create({ start: 10, end: 15, typeId: linkTypeId, virtual: true })
2945
- const emphasis1 = extmarks.create({ start: 4, end: 9, typeId: emphasisTypeId })
2946
-
2947
- const links = extmarks.getAllForTypeId(linkTypeId)
2948
- expect(links.length).toBe(2)
2949
- expect(links.map((e) => e.id).sort()).toEqual([link1, link2])
2950
-
2951
- const emphases = extmarks.getAllForTypeId(emphasisTypeId)
2952
- expect(emphases.length).toBe(1)
2953
- expect(emphases[0].id).toBe(emphasis1)
2954
-
2955
- expect(extmarks.getTypeName(linkTypeId)).toBe("link")
2956
- expect(extmarks.getTypeName(emphasisTypeId)).toBe("emphasis")
2957
- })
2958
-
2959
- it("should handle type names with special characters", async () => {
2960
- await setup()
2961
-
2962
- const typeId1 = extmarks.registerType("my-type")
2963
- const typeId2 = extmarks.registerType("my_type")
2964
- const typeId3 = extmarks.registerType("my.type")
2965
- const typeId4 = extmarks.registerType("my:type")
2966
-
2967
- expect(extmarks.getTypeId("my-type")).toBe(typeId1)
2968
- expect(extmarks.getTypeId("my_type")).toBe(typeId2)
2969
- expect(extmarks.getTypeId("my.type")).toBe(typeId3)
2970
- expect(extmarks.getTypeId("my:type")).toBe(typeId4)
2971
-
2972
- expect(typeId1).not.toBe(typeId2)
2973
- expect(typeId2).not.toBe(typeId3)
2974
- expect(typeId3).not.toBe(typeId4)
2975
- })
2976
-
2977
- it("should handle empty string as type name", async () => {
2978
- await setup()
2979
-
2980
- const typeId = extmarks.registerType("")
2981
- expect(typeId).toBe(1)
2982
- expect(extmarks.getTypeId("")).toBe(typeId)
2983
- expect(extmarks.getTypeName(typeId)).toBe("")
2984
- })
2985
-
2986
- it("should return null for getTypeId and getTypeName on destroyed controller", async () => {
2987
- await setup()
2988
-
2989
- const linkTypeId = extmarks.registerType("link")
2990
- extmarks.destroy()
2991
-
2992
- expect(extmarks.getTypeId("link")).toBeNull()
2993
- expect(extmarks.getTypeName(linkTypeId)).toBeNull()
2994
- })
2995
-
2996
- it("should allow re-registration after clear", async () => {
2997
- await setup()
2998
-
2999
- const firstLinkId = extmarks.registerType("link")
3000
- extmarks.create({ start: 0, end: 5, typeId: firstLinkId })
3001
-
3002
- extmarks.clear()
3003
-
3004
- expect(extmarks.getTypeId("link")).toBe(firstLinkId)
3005
-
3006
- const newExtmarkId = extmarks.create({ start: 0, end: 3, typeId: firstLinkId })
3007
- expect(extmarks.get(newExtmarkId)?.typeId).toBe(firstLinkId)
3008
- })
3009
-
3010
- it("should support case-sensitive type names", async () => {
3011
- await setup()
3012
-
3013
- const lowerId = extmarks.registerType("link")
3014
- const upperId = extmarks.registerType("Link")
3015
- const upperCaseId = extmarks.registerType("LINK")
3016
-
3017
- expect(lowerId).not.toBe(upperId)
3018
- expect(upperId).not.toBe(upperCaseId)
3019
- expect(lowerId).not.toBe(upperCaseId)
3020
-
3021
- expect(extmarks.getTypeId("link")).toBe(lowerId)
3022
- expect(extmarks.getTypeId("Link")).toBe(upperId)
3023
- expect(extmarks.getTypeId("LINK")).toBe(upperCaseId)
3024
- })
3025
-
3026
- it("should maintain typeId sequence independent of extmark IDs", async () => {
3027
- await setup()
3028
-
3029
- const extmarkId1 = extmarks.create({ start: 0, end: 1 })
3030
- const extmarkId2 = extmarks.create({ start: 1, end: 2 })
3031
-
3032
- const linkTypeId = extmarks.registerType("link")
3033
- const tagTypeId = extmarks.registerType("tag")
3034
-
3035
- expect(linkTypeId).toBe(1)
3036
- expect(tagTypeId).toBe(2)
3037
- expect(extmarkId1).toBeGreaterThanOrEqual(1)
3038
- expect(extmarkId2).toBeGreaterThanOrEqual(2)
3039
- })
3040
-
3041
- it("should handle numeric-like string type names", async () => {
3042
- await setup()
3043
-
3044
- const typeId1 = extmarks.registerType("123")
3045
- const typeId2 = extmarks.registerType("456")
3046
-
3047
- expect(extmarks.getTypeId("123")).toBe(typeId1)
3048
- expect(extmarks.getTypeId("456")).toBe(typeId2)
3049
- expect(typeId1).not.toBe(typeId2)
3050
- })
3051
-
3052
- it("should support long type names", async () => {
3053
- await setup()
3054
-
3055
- const longName = "a".repeat(1000)
3056
- const typeId = extmarks.registerType(longName)
3057
-
3058
- expect(extmarks.getTypeId(longName)).toBe(typeId)
3059
- expect(extmarks.getTypeName(typeId)).toBe(longName)
3060
- })
3061
- })
3062
-
3063
- describe("Metadata Operations", () => {
3064
- it("should store and retrieve metadata for extmark", async () => {
3065
- await setup()
3066
-
3067
- const metadata = { url: "https://example.com", title: "Example" }
3068
- const id = extmarks.create({
3069
- start: 0,
3070
- end: 5,
3071
- metadata,
3072
- })
3073
-
3074
- const retrieved = extmarks.getMetadataFor(id)
3075
- expect(retrieved).toEqual(metadata)
3076
- })
3077
-
3078
- it("should return undefined for extmark without metadata", async () => {
3079
- await setup()
3080
-
3081
- const id = extmarks.create({
3082
- start: 0,
3083
- end: 5,
3084
- })
3085
-
3086
- const retrieved = extmarks.getMetadataFor(id)
3087
- expect(retrieved).toBeUndefined()
3088
- })
3089
-
3090
- it("should return undefined for non-existent extmark", async () => {
3091
- await setup()
3092
-
3093
- const retrieved = extmarks.getMetadataFor(999)
3094
- expect(retrieved).toBeUndefined()
3095
- })
3096
-
3097
- it("should handle different metadata types", async () => {
3098
- await setup()
3099
-
3100
- const id1 = extmarks.create({
3101
- start: 0,
3102
- end: 5,
3103
- metadata: { type: "object", value: 42 },
3104
- })
3105
-
3106
- const id2 = extmarks.create({
3107
- start: 6,
3108
- end: 11,
3109
- metadata: "string metadata",
3110
- })
3111
-
3112
- const id3 = extmarks.create({
3113
- start: 12,
3114
- end: 15,
3115
- metadata: 123,
3116
- })
3117
-
3118
- const id4 = extmarks.create({
3119
- start: 16,
3120
- end: 20,
3121
- metadata: true,
3122
- })
3123
-
3124
- const id5 = extmarks.create({
3125
- start: 21,
3126
- end: 25,
3127
- metadata: ["array", "metadata"],
3128
- })
3129
-
3130
- expect(extmarks.getMetadataFor(id1)).toEqual({ type: "object", value: 42 })
3131
- expect(extmarks.getMetadataFor(id2)).toBe("string metadata")
3132
- expect(extmarks.getMetadataFor(id3)).toBe(123)
3133
- expect(extmarks.getMetadataFor(id4)).toBe(true)
3134
- expect(extmarks.getMetadataFor(id5)).toEqual(["array", "metadata"])
3135
- })
3136
-
3137
- it("should handle null metadata", async () => {
3138
- await setup()
3139
-
3140
- const id = extmarks.create({
3141
- start: 0,
3142
- end: 5,
3143
- metadata: null,
3144
- })
3145
-
3146
- const retrieved = extmarks.getMetadataFor(id)
3147
- expect(retrieved).toBeNull()
3148
- })
3149
-
3150
- it("should preserve metadata when extmark is adjusted", async () => {
3151
- await setup("Hello World")
3152
-
3153
- const metadata = { label: "important" }
3154
- const id = extmarks.create({
3155
- start: 6,
3156
- end: 11,
3157
- metadata,
3158
- })
3159
-
3160
- textarea.focus()
3161
- textarea.cursorOffset = 0
3162
- currentMockInput.pressKey("X")
3163
- currentMockInput.pressKey("X")
3164
-
3165
- const extmark = extmarks.get(id)
3166
- expect(extmark?.start).toBe(8)
3167
- expect(extmark?.end).toBe(13)
3168
-
3169
- const retrieved = extmarks.getMetadataFor(id)
3170
- expect(retrieved).toEqual(metadata)
3171
- })
3172
-
3173
- it("should remove metadata when extmark is deleted", async () => {
3174
- await setup()
3175
-
3176
- const metadata = { data: "test" }
3177
- const id = extmarks.create({
3178
- start: 0,
3179
- end: 5,
3180
- metadata,
3181
- })
3182
-
3183
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3184
-
3185
- extmarks.delete(id)
3186
-
3187
- expect(extmarks.getMetadataFor(id)).toBeUndefined()
3188
- })
3189
-
3190
- it("should clear all metadata when clear is called", async () => {
3191
- await setup()
3192
-
3193
- const id1 = extmarks.create({
3194
- start: 0,
3195
- end: 5,
3196
- metadata: { key: "value1" },
3197
- })
3198
-
3199
- const id2 = extmarks.create({
3200
- start: 6,
3201
- end: 11,
3202
- metadata: { key: "value2" },
3203
- })
3204
-
3205
- extmarks.clear()
3206
-
3207
- expect(extmarks.getMetadataFor(id1)).toBeUndefined()
3208
- expect(extmarks.getMetadataFor(id2)).toBeUndefined()
3209
- })
3210
-
3211
- it("should remove metadata when virtual extmark is deleted via backspace", async () => {
3212
- await setup("abc[LINK]def")
3213
-
3214
- textarea.focus()
3215
- textarea.cursorOffset = 9
3216
-
3217
- const metadata = { url: "https://test.com" }
3218
- const id = extmarks.create({
3219
- start: 3,
3220
- end: 9,
3221
- virtual: true,
3222
- metadata,
3223
- })
3224
-
3225
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3226
-
3227
- currentMockInput.pressBackspace()
3228
-
3229
- expect(extmarks.get(id)).toBeNull()
3230
- expect(extmarks.getMetadataFor(id)).toBeUndefined()
3231
- })
3232
-
3233
- it("should handle metadata with nested objects", async () => {
3234
- await setup()
3235
-
3236
- const metadata = {
3237
- user: {
3238
- id: 123,
3239
- name: "John Doe",
3240
- settings: {
3241
- theme: "dark",
3242
- notifications: true,
3243
- },
3244
- },
3245
- timestamp: Date.now(),
3246
- }
3247
-
3248
- const id = extmarks.create({
3249
- start: 0,
3250
- end: 5,
3251
- metadata,
3252
- })
3253
-
3254
- const retrieved = extmarks.getMetadataFor(id)
3255
- expect(retrieved).toEqual(metadata)
3256
- })
3257
-
3258
- it("should store independent metadata for multiple extmarks", async () => {
3259
- await setup()
3260
-
3261
- const id1 = extmarks.create({
3262
- start: 0,
3263
- end: 5,
3264
- metadata: { id: 1, color: "red" },
3265
- })
3266
-
3267
- const id2 = extmarks.create({
3268
- start: 6,
3269
- end: 11,
3270
- metadata: { id: 2, color: "blue" },
3271
- })
3272
-
3273
- const id3 = extmarks.create({
3274
- start: 12,
3275
- end: 15,
3276
- metadata: { id: 3, color: "green" },
3277
- })
3278
-
3279
- expect(extmarks.getMetadataFor(id1)).toEqual({ id: 1, color: "red" })
3280
- expect(extmarks.getMetadataFor(id2)).toEqual({ id: 2, color: "blue" })
3281
- expect(extmarks.getMetadataFor(id3)).toEqual({ id: 3, color: "green" })
3282
- })
3283
-
3284
- it("should handle metadata with both metadata and data fields", async () => {
3285
- await setup()
3286
-
3287
- const data = { oldField: "data" }
3288
- const metadata = { newField: "metadata" }
3289
-
3290
- const id = extmarks.create({
3291
- start: 0,
3292
- end: 5,
3293
- data,
3294
- metadata,
3295
- })
3296
-
3297
- const extmark = extmarks.get(id)
3298
- expect(extmark?.data).toEqual(data)
3299
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3300
- })
3301
-
3302
- it("should return undefined when getting metadata on destroyed controller", async () => {
3303
- await setup()
3304
-
3305
- const id = extmarks.create({
3306
- start: 0,
3307
- end: 5,
3308
- metadata: { test: "data" },
3309
- })
3310
-
3311
- extmarks.destroy()
3312
-
3313
- expect(extmarks.getMetadataFor(id)).toBeUndefined()
3314
- })
3315
-
3316
- it("should handle metadata with special values", async () => {
3317
- await setup()
3318
-
3319
- const id1 = extmarks.create({
3320
- start: 0,
3321
- end: 5,
3322
- metadata: undefined,
3323
- })
3324
-
3325
- const id2 = extmarks.create({
3326
- start: 6,
3327
- end: 11,
3328
- metadata: 0,
3329
- })
3330
-
3331
- const id3 = extmarks.create({
3332
- start: 12,
3333
- end: 15,
3334
- metadata: "",
3335
- })
3336
-
3337
- const id4 = extmarks.create({
3338
- start: 16,
3339
- end: 20,
3340
- metadata: false,
3341
- })
3342
-
3343
- expect(extmarks.getMetadataFor(id1)).toBeUndefined()
3344
- expect(extmarks.getMetadataFor(id2)).toBe(0)
3345
- expect(extmarks.getMetadataFor(id3)).toBe("")
3346
- expect(extmarks.getMetadataFor(id4)).toBe(false)
3347
- })
3348
-
3349
- it("should handle metadata for extmarks with same range", async () => {
3350
- await setup()
3351
-
3352
- const id1 = extmarks.create({
3353
- start: 0,
3354
- end: 5,
3355
- metadata: { layer: 1 },
3356
- })
3357
-
3358
- const id2 = extmarks.create({
3359
- start: 0,
3360
- end: 5,
3361
- metadata: { layer: 2 },
3362
- })
3363
-
3364
- expect(extmarks.getMetadataFor(id1)).toEqual({ layer: 1 })
3365
- expect(extmarks.getMetadataFor(id2)).toEqual({ layer: 2 })
3366
- })
3367
-
3368
- it("should preserve metadata through text insertion", async () => {
3369
- await setup("Hello World")
3370
-
3371
- const metadata = { type: "highlight", priority: 10 }
3372
- const id = extmarks.create({
3373
- start: 0,
3374
- end: 5,
3375
- metadata,
3376
- })
3377
-
3378
- textarea.focus()
3379
- textarea.cursorOffset = 2
3380
- currentMockInput.pressKey("Z")
3381
-
3382
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3383
- })
3384
-
3385
- it("should preserve metadata through text deletion", async () => {
3386
- await setup("XXHello World")
3387
-
3388
- const metadata = { category: "text" }
3389
- const id = extmarks.create({
3390
- start: 8,
3391
- end: 13,
3392
- metadata,
3393
- })
3394
-
3395
- textarea.focus()
3396
- textarea.cursorOffset = 2
3397
- currentMockInput.pressBackspace()
3398
- currentMockInput.pressBackspace()
3399
-
3400
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3401
- })
3402
-
3403
- it("should remove metadata when extmark range is deleted", async () => {
3404
- await setup("Hello World")
3405
-
3406
- const metadata = { info: "will be deleted" }
3407
- const id = extmarks.create({
3408
- start: 6,
3409
- end: 11,
3410
- metadata,
3411
- })
3412
-
3413
- textarea.deleteRange(0, 6, 0, 11)
3414
-
3415
- expect(extmarks.get(id)).toBeNull()
3416
- expect(extmarks.getMetadataFor(id)).toBeUndefined()
3417
- })
3418
-
3419
- it("should handle metadata for virtual extmarks", async () => {
3420
- await setup("abcdefgh")
3421
-
3422
- const metadata = { virtual: true, link: "https://example.com" }
3423
- const id = extmarks.create({
3424
- start: 3,
3425
- end: 6,
3426
- virtual: true,
3427
- metadata,
3428
- })
3429
-
3430
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3431
-
3432
- textarea.focus()
3433
- textarea.cursorOffset = 2
3434
- currentMockInput.pressArrow("right")
3435
-
3436
- expect(textarea.cursorOffset).toBe(6)
3437
- expect(extmarks.getMetadataFor(id)).toEqual(metadata)
3438
- })
3439
-
3440
- it("should handle large metadata objects", async () => {
3441
- await setup()
3442
-
3443
- const largeMetadata = {
3444
- items: Array.from({ length: 1000 }, (_, i) => ({ id: i, value: `item-${i}` })),
3445
- description: "A".repeat(10000),
3446
- }
3447
-
3448
- const id = extmarks.create({
3449
- start: 0,
3450
- end: 5,
3451
- metadata: largeMetadata,
3452
- })
3453
-
3454
- const retrieved = extmarks.getMetadataFor(id)
3455
- expect(retrieved).toEqual(largeMetadata)
3456
- expect(retrieved.items.length).toBe(1000)
3457
- expect(retrieved.description.length).toBe(10000)
3458
- })
3459
-
3460
- it("should handle metadata with functions", async () => {
3461
- await setup()
3462
-
3463
- const metadata = {
3464
- onClick: () => "clicked",
3465
- onHover: (x: number) => x * 2,
3466
- }
3467
-
3468
- const id = extmarks.create({
3469
- start: 0,
3470
- end: 5,
3471
- metadata,
3472
- })
3473
-
3474
- const retrieved = extmarks.getMetadataFor(id)
3475
- expect(typeof retrieved.onClick).toBe("function")
3476
- expect(typeof retrieved.onHover).toBe("function")
3477
- expect(retrieved.onClick()).toBe("clicked")
3478
- expect(retrieved.onHover(5)).toBe(10)
3479
- })
3480
-
3481
- it("should store metadata by reference", async () => {
3482
- await setup()
3483
-
3484
- const original = { value: 1, nested: { count: 0 } }
3485
- const id = extmarks.create({
3486
- start: 0,
3487
- end: 5,
3488
- metadata: original,
3489
- })
3490
-
3491
- const retrieved = extmarks.getMetadataFor(id)
3492
- retrieved.value = 999
3493
- retrieved.nested.count = 100
3494
-
3495
- expect(original.value).toBe(999)
3496
- expect(original.nested.count).toBe(100)
3497
- expect(extmarks.getMetadataFor(id).value).toBe(999)
3498
- })
3499
-
3500
- it("should handle metadata for extmarks with typeId", async () => {
3501
- await setup()
3502
-
3503
- const linkTypeId = extmarks.registerType("link")
3504
-
3505
- const id1 = extmarks.create({
3506
- start: 0,
3507
- end: 5,
3508
- typeId: linkTypeId,
3509
- metadata: { url: "https://first.com" },
3510
- })
3511
-
3512
- const id2 = extmarks.create({
3513
- start: 6,
3514
- end: 11,
3515
- typeId: linkTypeId,
3516
- metadata: { url: "https://second.com" },
3517
- })
3518
-
3519
- expect(extmarks.getMetadataFor(id1)).toEqual({ url: "https://first.com" })
3520
- expect(extmarks.getMetadataFor(id2)).toEqual({ url: "https://second.com" })
3521
-
3522
- const links = extmarks.getAllForTypeId(linkTypeId)
3523
- expect(links.length).toBe(2)
3524
-
3525
- for (const link of links) {
3526
- const meta = extmarks.getMetadataFor(link.id)
3527
- expect(meta).toHaveProperty("url")
3528
- expect(meta.url).toMatch(/^https:\/\//)
3529
- }
3530
- })
3531
-
3532
- it("should preserve metadata after setText clears extmarks", async () => {
3533
- await setup("Hello World")
3534
-
3535
- const id = extmarks.create({
3536
- start: 0,
3537
- end: 5,
3538
- metadata: { persisted: false },
3539
- })
3540
-
3541
- textarea.setText("New Text")
3542
-
3543
- expect(extmarks.get(id)).toBeNull()
3544
- expect(extmarks.getMetadataFor(id)).toBeUndefined()
3545
- })
3546
- })
3547
- })