@fairyhunter13/opentui-core 0.1.91 → 0.1.94

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