@fairyhunter13/opentui-core 0.1.91 → 0.1.92

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,3649 +0,0 @@
1
- const std = @import("std");
2
- const text_buffer = @import("../text-buffer.zig");
3
- const iter_mod = @import("../text-buffer-iterators.zig");
4
- const text_buffer_view = @import("../text-buffer-view.zig");
5
- const gp = @import("../grapheme.zig");
6
- const link = @import("../link.zig");
7
-
8
- const TextBuffer = text_buffer.UnifiedTextBuffer;
9
- const TextBufferView = text_buffer_view.UnifiedTextBufferView;
10
- const RGBA = text_buffer.RGBA;
11
-
12
- test "TextBufferView wrapping - no wrap returns same line count" {
13
- const pool = gp.initGlobalPool(std.testing.allocator);
14
- defer gp.deinitGlobalPool();
15
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
16
- defer link.deinitGlobalLinkPool();
17
-
18
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
19
- defer tb.deinit();
20
-
21
- var view = try TextBufferView.init(std.testing.allocator, tb);
22
- defer view.deinit();
23
-
24
- try tb.setText("Hello World");
25
-
26
- const no_wrap_count = view.getVirtualLineCount();
27
- try std.testing.expectEqual(@as(u32, 1), no_wrap_count);
28
-
29
- view.setWrapWidth(null);
30
- const still_no_wrap = view.getVirtualLineCount();
31
- try std.testing.expectEqual(@as(u32, 1), still_no_wrap);
32
- }
33
-
34
- test "TextBufferView wrapping - simple wrap splits line" {
35
- const pool = gp.initGlobalPool(std.testing.allocator);
36
- defer gp.deinitGlobalPool();
37
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
38
- defer link.deinitGlobalLinkPool();
39
-
40
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
41
- defer tb.deinit();
42
-
43
- var view = try TextBufferView.init(std.testing.allocator, tb);
44
- defer view.deinit();
45
-
46
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
47
-
48
- const no_wrap_count = view.getVirtualLineCount();
49
- try std.testing.expectEqual(@as(u32, 1), no_wrap_count);
50
-
51
- view.setWrapMode(.char);
52
- view.setWrapWidth(10);
53
- const wrapped_count = view.getVirtualLineCount();
54
-
55
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
56
- }
57
-
58
- test "TextBufferView wrapping - wrap at exact boundary" {
59
- const pool = gp.initGlobalPool(std.testing.allocator);
60
- defer gp.deinitGlobalPool();
61
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
62
- defer link.deinitGlobalLinkPool();
63
-
64
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
65
- defer tb.deinit();
66
-
67
- var view = try TextBufferView.init(std.testing.allocator, tb);
68
- defer view.deinit();
69
-
70
- try tb.setText("0123456789");
71
-
72
- view.setWrapMode(.char);
73
- view.setWrapWidth(10);
74
- const wrapped_count = view.getVirtualLineCount();
75
-
76
- try std.testing.expectEqual(@as(u32, 1), wrapped_count);
77
- }
78
-
79
- test "TextBufferView wrapping - preserves newlines" {
80
- const pool = gp.initGlobalPool(std.testing.allocator);
81
- defer gp.deinitGlobalPool();
82
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
83
- defer link.deinitGlobalLinkPool();
84
-
85
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
86
- defer tb.deinit();
87
-
88
- var view = try TextBufferView.init(std.testing.allocator, tb);
89
- defer view.deinit();
90
-
91
- try tb.setText("Short\nAnother short line\nLast");
92
-
93
- const no_wrap_count = view.getVirtualLineCount();
94
- try std.testing.expectEqual(@as(u32, 3), no_wrap_count);
95
-
96
- view.setWrapMode(.char);
97
- view.setWrapWidth(50);
98
- const wrapped_count = view.getVirtualLineCount();
99
-
100
- try std.testing.expectEqual(@as(u32, 3), wrapped_count);
101
- }
102
-
103
- test "TextBufferView selection - basic selection without wrap" {
104
- const pool = gp.initGlobalPool(std.testing.allocator);
105
- defer gp.deinitGlobalPool();
106
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
107
- defer link.deinitGlobalLinkPool();
108
-
109
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
110
- defer tb.deinit();
111
-
112
- var view = try TextBufferView.init(std.testing.allocator, tb);
113
- defer view.deinit();
114
-
115
- try tb.setText("Hello World");
116
-
117
- _ = view.setLocalSelection(2, 0, 7, 0, null, null);
118
-
119
- const packed_info = view.packSelectionInfo();
120
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
121
-
122
- const start = @as(u32, @intCast(packed_info >> 32));
123
- const end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
124
- try std.testing.expectEqual(@as(u32, 2), start);
125
- try std.testing.expectEqual(@as(u32, 7), end);
126
- }
127
-
128
- test "TextBufferView selection - with wrapped lines" {
129
- const pool = gp.initGlobalPool(std.testing.allocator);
130
- defer gp.deinitGlobalPool();
131
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
132
- defer link.deinitGlobalLinkPool();
133
-
134
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
135
- defer tb.deinit();
136
-
137
- var view = try TextBufferView.init(std.testing.allocator, tb);
138
- defer view.deinit();
139
-
140
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
141
-
142
- view.setWrapMode(.char);
143
- view.setWrapWidth(10);
144
-
145
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
146
-
147
- _ = view.setLocalSelection(5, 0, 5, 1, null, null);
148
-
149
- const packed_info = view.packSelectionInfo();
150
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
151
-
152
- const start = @as(u32, @intCast(packed_info >> 32));
153
- const end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
154
- try std.testing.expectEqual(@as(u32, 5), start);
155
- try std.testing.expectEqual(@as(u32, 15), end);
156
- }
157
-
158
- test "TextBufferView selection - no selection returns all bits set" {
159
- const pool = gp.initGlobalPool(std.testing.allocator);
160
- defer gp.deinitGlobalPool();
161
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
162
- defer link.deinitGlobalLinkPool();
163
-
164
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
165
- defer tb.deinit();
166
-
167
- var view = try TextBufferView.init(std.testing.allocator, tb);
168
- defer view.deinit();
169
-
170
- try tb.setText("Hello World");
171
-
172
- const packed_info = view.packSelectionInfo();
173
- try std.testing.expectEqual(@as(u64, 0xFFFFFFFF_FFFFFFFF), packed_info);
174
- }
175
-
176
- test "TextBufferView word wrapping - basic word wrap at space" {
177
- const pool = gp.initGlobalPool(std.testing.allocator);
178
- defer gp.deinitGlobalPool();
179
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
180
- defer link.deinitGlobalLinkPool();
181
-
182
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
183
- defer tb.deinit();
184
-
185
- var view = try TextBufferView.init(std.testing.allocator, tb);
186
- defer view.deinit();
187
-
188
- try tb.setText("Hello World");
189
-
190
- view.setWrapMode(.word);
191
- view.setWrapWidth(8);
192
- const wrapped_count = view.getVirtualLineCount();
193
-
194
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
195
- }
196
-
197
- test "TextBufferView word wrapping - long word exceeds width" {
198
- const pool = gp.initGlobalPool(std.testing.allocator);
199
- defer gp.deinitGlobalPool();
200
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
201
- defer link.deinitGlobalLinkPool();
202
-
203
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
204
- defer tb.deinit();
205
-
206
- var view = try TextBufferView.init(std.testing.allocator, tb);
207
- defer view.deinit();
208
-
209
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
210
-
211
- view.setWrapMode(.word);
212
- view.setWrapWidth(10);
213
- const wrapped_count = view.getVirtualLineCount();
214
-
215
- try std.testing.expectEqual(@as(u32, 3), wrapped_count);
216
- }
217
-
218
- test "TextBufferView getSelectedTextIntoBuffer - simple selection" {
219
- const pool = gp.initGlobalPool(std.testing.allocator);
220
- defer gp.deinitGlobalPool();
221
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
222
- defer link.deinitGlobalLinkPool();
223
-
224
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
225
- defer tb.deinit();
226
-
227
- var view = try TextBufferView.init(std.testing.allocator, tb);
228
- defer view.deinit();
229
-
230
- try tb.setText("Hello World");
231
- view.setSelection(6, 11, null, null);
232
-
233
- var buffer: [100]u8 = undefined;
234
- const len = view.getSelectedTextIntoBuffer(&buffer);
235
- const text = buffer[0..len];
236
-
237
- try std.testing.expectEqualStrings("World", text);
238
- }
239
-
240
- test "TextBufferView getSelectedTextIntoBuffer - with newlines" {
241
- const pool = gp.initGlobalPool(std.testing.allocator);
242
- defer gp.deinitGlobalPool();
243
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
244
- defer link.deinitGlobalLinkPool();
245
-
246
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
247
- defer tb.deinit();
248
-
249
- var view = try TextBufferView.init(std.testing.allocator, tb);
250
- defer view.deinit();
251
-
252
- try tb.setText("Line 1\nLine 2\nLine 3");
253
-
254
- view.setSelection(0, 9, null, null);
255
-
256
- var buffer: [100]u8 = undefined;
257
- const len = view.getSelectedTextIntoBuffer(&buffer);
258
- const text = buffer[0..len];
259
-
260
- try std.testing.expectEqualStrings("Line 1\nLi", text);
261
- }
262
-
263
- test "TextBufferView getCachedLineInfo - with wrapping" {
264
- const pool = gp.initGlobalPool(std.testing.allocator);
265
- defer gp.deinitGlobalPool();
266
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
267
- defer link.deinitGlobalLinkPool();
268
-
269
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
270
- defer tb.deinit();
271
-
272
- var view = try TextBufferView.init(std.testing.allocator, tb);
273
- defer view.deinit();
274
-
275
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
276
-
277
- view.setWrapMode(.char);
278
- view.setWrapWidth(7);
279
- const line_count = view.getVirtualLineCount();
280
- const line_info = view.getCachedLineInfo();
281
-
282
- try std.testing.expectEqual(@as(usize, line_count), line_info.line_start_cols.len);
283
- try std.testing.expectEqual(@as(usize, line_count), line_info.line_width_cols.len);
284
-
285
- for (line_info.line_width_cols, 0..) |width, i| {
286
- if (i < line_info.line_width_cols.len - 1) {
287
- try std.testing.expect(width <= 7);
288
- }
289
- }
290
- }
291
-
292
- test "TextBufferView virtual line spans - with highlights" {
293
- const pool = gp.initGlobalPool(std.testing.allocator);
294
- defer gp.deinitGlobalPool();
295
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
296
- defer link.deinitGlobalLinkPool();
297
-
298
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
299
- defer tb.deinit();
300
-
301
- var view = try TextBufferView.init(std.testing.allocator, tb);
302
- defer view.deinit();
303
-
304
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
305
-
306
- try tb.addHighlight(0, 5, 15, 1, 1, 0);
307
-
308
- view.setWrapMode(.char);
309
- view.setWrapWidth(10);
310
-
311
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
312
-
313
- const vline0_info = view.getVirtualLineSpans(0);
314
- const vline1_info = view.getVirtualLineSpans(1);
315
-
316
- try std.testing.expectEqual(@as(usize, 0), vline0_info.source_line);
317
- try std.testing.expectEqual(@as(usize, 0), vline1_info.source_line);
318
-
319
- try std.testing.expectEqual(@as(u32, 0), vline0_info.col_offset);
320
- try std.testing.expectEqual(@as(u32, 10), vline1_info.col_offset);
321
-
322
- try std.testing.expect(vline0_info.spans.len > 0);
323
- try std.testing.expect(vline1_info.spans.len > 0);
324
- }
325
-
326
- test "TextBufferView updates after buffer setText" {
327
- const pool = gp.initGlobalPool(std.testing.allocator);
328
- defer gp.deinitGlobalPool();
329
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
330
- defer link.deinitGlobalLinkPool();
331
-
332
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
333
- defer tb.deinit();
334
-
335
- var view = try TextBufferView.init(std.testing.allocator, tb);
336
- defer view.deinit();
337
-
338
- try tb.setText("First text");
339
- view.setWrapMode(.char);
340
- view.setWrapWidth(5);
341
- const count1 = view.getVirtualLineCount();
342
-
343
- try tb.setText("New text that is much longer");
344
-
345
- const count2 = view.getVirtualLineCount();
346
-
347
- try std.testing.expect(count2 > count1);
348
- }
349
-
350
- test "TextBufferView wrapping - multiple wrap lines" {
351
- const pool = gp.initGlobalPool(std.testing.allocator);
352
- defer gp.deinitGlobalPool();
353
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
354
- defer link.deinitGlobalLinkPool();
355
-
356
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
357
- defer tb.deinit();
358
-
359
- var view = try TextBufferView.init(std.testing.allocator, tb);
360
- defer view.deinit();
361
-
362
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123");
363
-
364
- view.setWrapMode(.char);
365
- view.setWrapWidth(10);
366
- const wrapped_count = view.getVirtualLineCount();
367
-
368
- try std.testing.expectEqual(@as(u32, 3), wrapped_count);
369
- }
370
-
371
- test "TextBufferView wrapping - long line with newlines" {
372
- const pool = gp.initGlobalPool(std.testing.allocator);
373
- defer gp.deinitGlobalPool();
374
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
375
- defer link.deinitGlobalLinkPool();
376
-
377
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
378
- defer tb.deinit();
379
-
380
- var view = try TextBufferView.init(std.testing.allocator, tb);
381
- defer view.deinit();
382
-
383
- try tb.setText("ABCDEFGHIJKLMNOPQRST\nShort");
384
-
385
- const no_wrap_count = view.getVirtualLineCount();
386
- try std.testing.expectEqual(@as(u32, 2), no_wrap_count);
387
-
388
- view.setWrapMode(.char);
389
- view.setWrapWidth(10);
390
- const wrapped_count = view.getVirtualLineCount();
391
-
392
- try std.testing.expectEqual(@as(u32, 3), wrapped_count);
393
- }
394
-
395
- test "TextBufferView wrapping - change wrap width" {
396
- const pool = gp.initGlobalPool(std.testing.allocator);
397
- defer gp.deinitGlobalPool();
398
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
399
- defer link.deinitGlobalLinkPool();
400
-
401
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
402
- defer tb.deinit();
403
-
404
- var view = try TextBufferView.init(std.testing.allocator, tb);
405
- defer view.deinit();
406
-
407
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
408
-
409
- view.setWrapMode(.char);
410
- view.setWrapWidth(10);
411
- var wrapped_count = view.getVirtualLineCount();
412
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
413
-
414
- view.setWrapMode(.char);
415
- view.setWrapWidth(5);
416
- wrapped_count = view.getVirtualLineCount();
417
- try std.testing.expectEqual(@as(u32, 4), wrapped_count);
418
-
419
- view.setWrapMode(.char);
420
- view.setWrapWidth(20);
421
- wrapped_count = view.getVirtualLineCount();
422
- try std.testing.expectEqual(@as(u32, 1), wrapped_count);
423
-
424
- view.setWrapWidth(null);
425
- wrapped_count = view.getVirtualLineCount();
426
- try std.testing.expectEqual(@as(u32, 1), wrapped_count);
427
- }
428
-
429
- test "TextBufferView wrapping - grapheme at exact boundary" {
430
- const pool = gp.initGlobalPool(std.testing.allocator);
431
- defer gp.deinitGlobalPool();
432
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
433
- defer link.deinitGlobalLinkPool();
434
-
435
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
436
- defer tb.deinit();
437
-
438
- var view = try TextBufferView.init(std.testing.allocator, tb);
439
- defer view.deinit();
440
-
441
- try tb.setText("12345678🌟");
442
-
443
- view.setWrapMode(.char);
444
- view.setWrapWidth(10);
445
- const wrapped_count = view.getVirtualLineCount();
446
-
447
- try std.testing.expectEqual(@as(u32, 1), wrapped_count);
448
- }
449
-
450
- test "TextBufferView wrapping - grapheme split across boundary" {
451
- const pool = gp.initGlobalPool(std.testing.allocator);
452
- defer gp.deinitGlobalPool();
453
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
454
- defer link.deinitGlobalLinkPool();
455
-
456
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
457
- defer tb.deinit();
458
-
459
- var view = try TextBufferView.init(std.testing.allocator, tb);
460
- defer view.deinit();
461
-
462
- try tb.setText("123456789🌟ABC");
463
-
464
- view.setWrapMode(.char);
465
- view.setWrapWidth(10);
466
- const wrapped_count = view.getVirtualLineCount();
467
-
468
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
469
- }
470
-
471
- test "TextBufferView wrapping - CJK characters at boundaries" {
472
- const pool = gp.initGlobalPool(std.testing.allocator);
473
- defer gp.deinitGlobalPool();
474
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
475
- defer link.deinitGlobalLinkPool();
476
-
477
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
478
- defer tb.deinit();
479
-
480
- var view = try TextBufferView.init(std.testing.allocator, tb);
481
- defer view.deinit();
482
-
483
- try tb.setText("测试文字处理");
484
-
485
- view.setWrapMode(.char);
486
- view.setWrapWidth(10);
487
- const wrapped_count = view.getVirtualLineCount();
488
-
489
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
490
- }
491
-
492
- test "TextBufferView wrapping - mixed width characters" {
493
- const pool = gp.initGlobalPool(std.testing.allocator);
494
- defer gp.deinitGlobalPool();
495
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
496
- defer link.deinitGlobalLinkPool();
497
-
498
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
499
- defer tb.deinit();
500
-
501
- var view = try TextBufferView.init(std.testing.allocator, tb);
502
- defer view.deinit();
503
-
504
- try tb.setText("AB测试CD");
505
-
506
- view.setWrapMode(.char);
507
- view.setWrapWidth(6);
508
- const wrapped_count = view.getVirtualLineCount();
509
-
510
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
511
- }
512
-
513
- test "TextBufferView wrapping - single wide character exceeds width" {
514
- const pool = gp.initGlobalPool(std.testing.allocator);
515
- defer gp.deinitGlobalPool();
516
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
517
- defer link.deinitGlobalLinkPool();
518
-
519
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
520
- defer tb.deinit();
521
-
522
- var view = try TextBufferView.init(std.testing.allocator, tb);
523
- defer view.deinit();
524
-
525
- try tb.setText("🌟");
526
-
527
- view.setWrapMode(.char);
528
- view.setWrapWidth(1);
529
- const wrapped_count = view.getVirtualLineCount();
530
-
531
- try std.testing.expectEqual(@as(u32, 1), wrapped_count);
532
- }
533
-
534
- test "TextBufferView wrapping - multiple consecutive wide characters" {
535
- const pool = gp.initGlobalPool(std.testing.allocator);
536
- defer gp.deinitGlobalPool();
537
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
538
- defer link.deinitGlobalLinkPool();
539
-
540
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
541
- defer tb.deinit();
542
-
543
- var view = try TextBufferView.init(std.testing.allocator, tb);
544
- defer view.deinit();
545
-
546
- try tb.setText("🌟🌟🌟🌟🌟");
547
-
548
- view.setWrapMode(.char);
549
- view.setWrapWidth(6);
550
- const wrapped_count = view.getVirtualLineCount();
551
-
552
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
553
- }
554
-
555
- test "TextBufferView wrapping - zero width characters" {
556
- const pool = gp.initGlobalPool(std.testing.allocator);
557
- defer gp.deinitGlobalPool();
558
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
559
- defer link.deinitGlobalLinkPool();
560
-
561
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
562
- defer tb.deinit();
563
-
564
- var view = try TextBufferView.init(std.testing.allocator, tb);
565
- defer view.deinit();
566
-
567
- try tb.setText("e\u{0301}e\u{0301}e\u{0301}"); // é é é using combining acute
568
-
569
- view.setWrapMode(.char);
570
- view.setWrapWidth(2);
571
- const wrapped_count = view.getVirtualLineCount();
572
-
573
- try std.testing.expect(wrapped_count >= 1);
574
- }
575
-
576
- test "TextBufferView word wrapping - multiple words" {
577
- const pool = gp.initGlobalPool(std.testing.allocator);
578
- defer gp.deinitGlobalPool();
579
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
580
- defer link.deinitGlobalLinkPool();
581
-
582
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
583
- defer tb.deinit();
584
-
585
- var view = try TextBufferView.init(std.testing.allocator, tb);
586
- defer view.deinit();
587
-
588
- try tb.setText("The quick brown fox jumps");
589
-
590
- view.setWrapMode(.word);
591
- view.setWrapWidth(15);
592
- const wrapped_count = view.getVirtualLineCount();
593
-
594
- try std.testing.expect(wrapped_count >= 2);
595
- }
596
-
597
- test "TextBufferView word wrapping - hyphenated words" {
598
- const pool = gp.initGlobalPool(std.testing.allocator);
599
- defer gp.deinitGlobalPool();
600
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
601
- defer link.deinitGlobalLinkPool();
602
-
603
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
604
- defer tb.deinit();
605
-
606
- var view = try TextBufferView.init(std.testing.allocator, tb);
607
- defer view.deinit();
608
-
609
- try tb.setText("self-contained multi-line");
610
-
611
- view.setWrapMode(.word);
612
- view.setWrapWidth(12);
613
- const wrapped_count = view.getVirtualLineCount();
614
-
615
- try std.testing.expect(wrapped_count >= 2);
616
- }
617
-
618
- test "TextBufferView word wrapping - punctuation boundaries" {
619
- const pool = gp.initGlobalPool(std.testing.allocator);
620
- defer gp.deinitGlobalPool();
621
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
622
- defer link.deinitGlobalLinkPool();
623
-
624
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
625
- defer tb.deinit();
626
-
627
- var view = try TextBufferView.init(std.testing.allocator, tb);
628
- defer view.deinit();
629
-
630
- try tb.setText("Hello,World.Test");
631
-
632
- view.setWrapMode(.word);
633
- view.setWrapWidth(8);
634
- const wrapped_count = view.getVirtualLineCount();
635
-
636
- try std.testing.expect(wrapped_count >= 2);
637
- }
638
-
639
- test "TextBufferView word wrapping - tab boundary width" {
640
- const pool = gp.initGlobalPool(std.testing.allocator);
641
- defer gp.deinitGlobalPool();
642
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
643
- defer link.deinitGlobalLinkPool();
644
-
645
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
646
- defer tb.deinit();
647
-
648
- var view = try TextBufferView.init(std.testing.allocator, tb);
649
- defer view.deinit();
650
-
651
- // "AB" = 2 cols, tab = 2 cols, "CD" = 2 cols
652
- try tb.setText("AB\tCD");
653
-
654
- view.setWrapMode(.word);
655
- view.setWrapWidth(4);
656
- const vlines = view.getVirtualLines();
657
-
658
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
659
- try std.testing.expectEqual(@as(u32, 4), vlines[0].width_cols);
660
- try std.testing.expectEqual(@as(u32, 2), vlines[1].width_cols);
661
- }
662
-
663
- test "TextBufferView word wrapping - emoji boundary width" {
664
- const pool = gp.initGlobalPool(std.testing.allocator);
665
- defer gp.deinitGlobalPool();
666
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
667
- defer link.deinitGlobalLinkPool();
668
-
669
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
670
- defer tb.deinit();
671
-
672
- var view = try TextBufferView.init(std.testing.allocator, tb);
673
- defer view.deinit();
674
-
675
- // "AB" = 2 cols, "🌟" = 2 cols, space = 1 col, "CD" = 2 cols
676
- try tb.setText("AB🌟 CD");
677
-
678
- view.setWrapMode(.word);
679
- view.setWrapWidth(5);
680
- const vlines = view.getVirtualLines();
681
-
682
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
683
- try std.testing.expectEqual(@as(u32, 5), vlines[0].width_cols);
684
- try std.testing.expectEqual(@as(u32, 2), vlines[1].width_cols);
685
- }
686
-
687
- test "TextBufferView word wrapping - CJK boundary width" {
688
- const pool = gp.initGlobalPool(std.testing.allocator);
689
- defer gp.deinitGlobalPool();
690
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
691
- defer link.deinitGlobalLinkPool();
692
-
693
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
694
- defer tb.deinit();
695
-
696
- var view = try TextBufferView.init(std.testing.allocator, tb);
697
- defer view.deinit();
698
-
699
- // "AB" = 2 cols, "好" = 2 cols, space = 1 col, "CD" = 2 cols
700
- try tb.setText("AB好 CD");
701
-
702
- view.setWrapMode(.word);
703
- view.setWrapWidth(5);
704
- const vlines = view.getVirtualLines();
705
-
706
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
707
- try std.testing.expectEqual(@as(u32, 5), vlines[0].width_cols);
708
- try std.testing.expectEqual(@as(u32, 2), vlines[1].width_cols);
709
- }
710
-
711
-
712
- test "TextBufferView word wrapping - compare char vs word mode" {
713
- const pool = gp.initGlobalPool(std.testing.allocator);
714
- defer gp.deinitGlobalPool();
715
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
716
- defer link.deinitGlobalLinkPool();
717
-
718
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
719
- defer tb.deinit();
720
-
721
- var view = try TextBufferView.init(std.testing.allocator, tb);
722
- defer view.deinit();
723
-
724
- try tb.setText("Hello wonderful world");
725
-
726
- view.setWrapMode(.char);
727
- view.setWrapWidth(10);
728
- const char_wrapped_count = view.getVirtualLineCount();
729
-
730
- view.setWrapMode(.word);
731
- const word_wrapped_count = view.getVirtualLineCount();
732
-
733
- try std.testing.expect(char_wrapped_count >= 2);
734
- try std.testing.expect(word_wrapped_count >= 2);
735
- }
736
-
737
- test "TextBufferView word wrapping - empty lines preserved" {
738
- const pool = gp.initGlobalPool(std.testing.allocator);
739
- defer gp.deinitGlobalPool();
740
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
741
- defer link.deinitGlobalLinkPool();
742
-
743
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
744
- defer tb.deinit();
745
-
746
- var view = try TextBufferView.init(std.testing.allocator, tb);
747
- defer view.deinit();
748
-
749
- try tb.setText("First line\n\nSecond line");
750
-
751
- view.setWrapMode(.word);
752
- view.setWrapWidth(8);
753
- const wrapped_count = view.getVirtualLineCount();
754
-
755
- try std.testing.expect(wrapped_count >= 3);
756
- }
757
-
758
- test "TextBufferView word wrapping - slash as boundary" {
759
- const pool = gp.initGlobalPool(std.testing.allocator);
760
- defer gp.deinitGlobalPool();
761
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
762
- defer link.deinitGlobalLinkPool();
763
-
764
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
765
- defer tb.deinit();
766
-
767
- var view = try TextBufferView.init(std.testing.allocator, tb);
768
- defer view.deinit();
769
-
770
- try tb.setText("path/to/file");
771
-
772
- view.setWrapMode(.word);
773
- view.setWrapWidth(8);
774
- const wrapped_count = view.getVirtualLineCount();
775
-
776
- try std.testing.expect(wrapped_count >= 2);
777
- }
778
-
779
- test "TextBufferView word wrapping - brackets as boundaries" {
780
- const pool = gp.initGlobalPool(std.testing.allocator);
781
- defer gp.deinitGlobalPool();
782
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
783
- defer link.deinitGlobalLinkPool();
784
-
785
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
786
- defer tb.deinit();
787
-
788
- var view = try TextBufferView.init(std.testing.allocator, tb);
789
- defer view.deinit();
790
-
791
- try tb.setText("array[index]value");
792
-
793
- view.setWrapMode(.word);
794
- view.setWrapWidth(10);
795
- const wrapped_count = view.getVirtualLineCount();
796
-
797
- try std.testing.expect(wrapped_count >= 2);
798
- }
799
-
800
- test "TextBufferView word wrapping - single character at boundary" {
801
- const pool = gp.initGlobalPool(std.testing.allocator);
802
- defer gp.deinitGlobalPool();
803
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
804
- defer link.deinitGlobalLinkPool();
805
-
806
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
807
- defer tb.deinit();
808
-
809
- var view = try TextBufferView.init(std.testing.allocator, tb);
810
- defer view.deinit();
811
-
812
- try tb.setText("a b c d e f");
813
-
814
- view.setWrapMode(.word);
815
- view.setWrapWidth(4);
816
- const wrapped_count = view.getVirtualLineCount();
817
-
818
- try std.testing.expect(wrapped_count >= 3);
819
- }
820
-
821
- test "TextBufferView word wrapping - fragmented rope with word boundary" {
822
- const pool = gp.initGlobalPool(std.testing.allocator);
823
- defer gp.deinitGlobalPool();
824
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
825
- defer link.deinitGlobalLinkPool();
826
-
827
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
828
- defer tb.deinit();
829
-
830
- var view = try TextBufferView.init(std.testing.allocator, tb);
831
- defer view.deinit();
832
-
833
- const text = "hello my good friend";
834
- const mem_id = try tb.registerMemBuffer(text, false);
835
-
836
- const seg_mod = @import("../text-buffer-segment.zig");
837
- const Segment = seg_mod.Segment;
838
-
839
- const chunk1 = tb.createChunk(mem_id, 0, 14); // "hello my good "
840
- const chunk2 = tb.createChunk(mem_id, 14, 15); // "f"
841
- const chunk3 = tb.createChunk(mem_id, 15, 20); // "riend"
842
-
843
- var segments: std.ArrayListUnmanaged(Segment) = .{};
844
- defer segments.deinit(std.testing.allocator);
845
-
846
- try segments.append(std.testing.allocator, Segment{ .linestart = {} });
847
- try segments.append(std.testing.allocator, Segment{ .text = chunk1 });
848
- try segments.append(std.testing.allocator, Segment{ .text = chunk2 });
849
- try segments.append(std.testing.allocator, Segment{ .text = chunk3 });
850
-
851
- try tb.rope().setSegments(segments.items);
852
-
853
- view.virtual_lines_dirty = true;
854
-
855
- view.setWrapMode(.word);
856
- view.setWrapWidth(18);
857
-
858
- const vlines = view.getVirtualLines();
859
-
860
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
861
-
862
- try std.testing.expectEqual(@as(u32, 14), vlines[0].width_cols);
863
-
864
- try std.testing.expectEqual(@as(u32, 6), vlines[1].width_cols);
865
- }
866
-
867
- test "TextBufferView wrapping - very narrow width (1 char)" {
868
- const pool = gp.initGlobalPool(std.testing.allocator);
869
- defer gp.deinitGlobalPool();
870
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
871
- defer link.deinitGlobalLinkPool();
872
-
873
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
874
- defer tb.deinit();
875
-
876
- var view = try TextBufferView.init(std.testing.allocator, tb);
877
- defer view.deinit();
878
-
879
- try tb.setText("ABCDE");
880
-
881
- view.setWrapMode(.char);
882
- view.setWrapWidth(1);
883
- const wrapped_count = view.getVirtualLineCount();
884
-
885
- try std.testing.expectEqual(@as(u32, 5), wrapped_count);
886
- }
887
-
888
- test "TextBufferView wrapping - very narrow width (2 chars)" {
889
- const pool = gp.initGlobalPool(std.testing.allocator);
890
- defer gp.deinitGlobalPool();
891
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
892
- defer link.deinitGlobalLinkPool();
893
-
894
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
895
- defer tb.deinit();
896
-
897
- var view = try TextBufferView.init(std.testing.allocator, tb);
898
- defer view.deinit();
899
-
900
- try tb.setText("ABCDEF");
901
-
902
- view.setWrapMode(.char);
903
- view.setWrapWidth(2);
904
- const wrapped_count = view.getVirtualLineCount();
905
-
906
- try std.testing.expectEqual(@as(u32, 3), wrapped_count);
907
- }
908
-
909
- test "TextBufferView wrapping - switch between char and word mode" {
910
- const pool = gp.initGlobalPool(std.testing.allocator);
911
- defer gp.deinitGlobalPool();
912
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
913
- defer link.deinitGlobalLinkPool();
914
-
915
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
916
- defer tb.deinit();
917
-
918
- var view = try TextBufferView.init(std.testing.allocator, tb);
919
- defer view.deinit();
920
-
921
- try tb.setText("Hello world test");
922
-
923
- view.setWrapMode(.char);
924
- view.setWrapWidth(8);
925
-
926
- view.setWrapMode(.char);
927
- const char_count = view.getVirtualLineCount();
928
-
929
- view.setWrapMode(.word);
930
- const word_count = view.getVirtualLineCount();
931
-
932
- try std.testing.expect(char_count >= 2);
933
- try std.testing.expect(word_count >= 2);
934
- }
935
-
936
- test "TextBufferView wrapping - multiple consecutive newlines with wrapping" {
937
- const pool = gp.initGlobalPool(std.testing.allocator);
938
- defer gp.deinitGlobalPool();
939
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
940
- defer link.deinitGlobalLinkPool();
941
-
942
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
943
- defer tb.deinit();
944
-
945
- var view = try TextBufferView.init(std.testing.allocator, tb);
946
- defer view.deinit();
947
-
948
- try tb.setText("ABCDEFGHIJ\n\n\nKLMNOPQRST");
949
-
950
- view.setWrapMode(.char);
951
- view.setWrapWidth(5);
952
- const wrapped_count = view.getVirtualLineCount();
953
-
954
- try std.testing.expect(wrapped_count >= 6);
955
- }
956
-
957
- test "TextBufferView wrapping - only spaces should not create extra lines" {
958
- const pool = gp.initGlobalPool(std.testing.allocator);
959
- defer gp.deinitGlobalPool();
960
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
961
- defer link.deinitGlobalLinkPool();
962
-
963
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
964
- defer tb.deinit();
965
-
966
- var view = try TextBufferView.init(std.testing.allocator, tb);
967
- defer view.deinit();
968
-
969
- try tb.setText(" "); // 10 spaces
970
-
971
- view.setWrapMode(.char);
972
- view.setWrapWidth(5);
973
- const wrapped_count = view.getVirtualLineCount();
974
-
975
- try std.testing.expectEqual(@as(u32, 2), wrapped_count);
976
- }
977
-
978
- test "TextBufferView wrapping - mixed tabs and spaces" {
979
- const pool = gp.initGlobalPool(std.testing.allocator);
980
- defer gp.deinitGlobalPool();
981
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
982
- defer link.deinitGlobalLinkPool();
983
-
984
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
985
- defer tb.deinit();
986
-
987
- var view = try TextBufferView.init(std.testing.allocator, tb);
988
- defer view.deinit();
989
-
990
- try tb.setText("AB\tCD\tEF");
991
-
992
- view.setWrapMode(.char);
993
- view.setWrapWidth(5);
994
- const wrapped_count = view.getVirtualLineCount();
995
-
996
- try std.testing.expect(wrapped_count >= 1);
997
- }
998
-
999
- test "TextBufferView wrapping - unicode emoji with varying widths" {
1000
- const pool = gp.initGlobalPool(std.testing.allocator);
1001
- defer gp.deinitGlobalPool();
1002
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1003
- defer link.deinitGlobalLinkPool();
1004
-
1005
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1006
- defer tb.deinit();
1007
-
1008
- var view = try TextBufferView.init(std.testing.allocator, tb);
1009
- defer view.deinit();
1010
-
1011
- try tb.setText("A🌟B🎨C🚀D");
1012
-
1013
- view.setWrapMode(.char);
1014
- view.setWrapWidth(5);
1015
- const wrapped_count = view.getVirtualLineCount();
1016
-
1017
- try std.testing.expect(wrapped_count >= 2);
1018
- }
1019
-
1020
- test "TextBufferView wrapping - getVirtualLines reflects current wrap state" {
1021
- const pool = gp.initGlobalPool(std.testing.allocator);
1022
- defer gp.deinitGlobalPool();
1023
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1024
- defer link.deinitGlobalLinkPool();
1025
-
1026
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1027
- defer tb.deinit();
1028
-
1029
- var view = try TextBufferView.init(std.testing.allocator, tb);
1030
- defer view.deinit();
1031
-
1032
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
1033
-
1034
- var vlines = view.getVirtualLines();
1035
- try std.testing.expectEqual(@as(usize, 1), vlines.len);
1036
-
1037
- view.setWrapMode(.char);
1038
- view.setWrapWidth(10);
1039
- vlines = view.getVirtualLines();
1040
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
1041
-
1042
- view.setWrapMode(.char);
1043
- view.setWrapWidth(5);
1044
- vlines = view.getVirtualLines();
1045
- try std.testing.expectEqual(@as(usize, 4), vlines.len);
1046
-
1047
- view.setWrapWidth(null);
1048
- vlines = view.getVirtualLines();
1049
- try std.testing.expectEqual(@as(usize, 1), vlines.len);
1050
- }
1051
-
1052
- test "TextBufferView selection - multi-line selection without wrap" {
1053
- const pool = gp.initGlobalPool(std.testing.allocator);
1054
- defer gp.deinitGlobalPool();
1055
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1056
- defer link.deinitGlobalLinkPool();
1057
-
1058
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1059
- defer tb.deinit();
1060
-
1061
- var view = try TextBufferView.init(std.testing.allocator, tb);
1062
- defer view.deinit();
1063
-
1064
- try tb.setText("Line 1\nLine 2\nLine 3");
1065
-
1066
- _ = view.setLocalSelection(2, 0, 4, 1, null, null);
1067
-
1068
- const packed_info = view.packSelectionInfo();
1069
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1070
- }
1071
-
1072
- test "TextBufferView selection - selection at wrap boundary" {
1073
- const pool = gp.initGlobalPool(std.testing.allocator);
1074
- defer gp.deinitGlobalPool();
1075
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1076
- defer link.deinitGlobalLinkPool();
1077
-
1078
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1079
- defer tb.deinit();
1080
-
1081
- var view = try TextBufferView.init(std.testing.allocator, tb);
1082
- defer view.deinit();
1083
-
1084
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
1085
-
1086
- view.setWrapMode(.char);
1087
- view.setWrapWidth(10);
1088
-
1089
- _ = view.setLocalSelection(9, 0, 1, 1, null, null);
1090
-
1091
- const packed_info = view.packSelectionInfo();
1092
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1093
-
1094
- const start = @as(u32, @intCast(packed_info >> 32));
1095
- const end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
1096
- try std.testing.expectEqual(@as(u32, 9), start);
1097
- try std.testing.expectEqual(@as(u32, 11), end);
1098
- }
1099
-
1100
- test "TextBufferView selection - spanning multiple wrapped lines" {
1101
- const pool = gp.initGlobalPool(std.testing.allocator);
1102
- defer gp.deinitGlobalPool();
1103
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1104
- defer link.deinitGlobalLinkPool();
1105
-
1106
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1107
- defer tb.deinit();
1108
-
1109
- var view = try TextBufferView.init(std.testing.allocator, tb);
1110
- defer view.deinit();
1111
-
1112
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123");
1113
-
1114
- view.setWrapMode(.char);
1115
- view.setWrapWidth(10);
1116
- try std.testing.expectEqual(@as(u32, 3), view.getVirtualLineCount());
1117
-
1118
- _ = view.setLocalSelection(2, 0, 8, 2, null, null);
1119
-
1120
- const packed_info = view.packSelectionInfo();
1121
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1122
-
1123
- const start = @as(u32, @intCast(packed_info >> 32));
1124
- const end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
1125
- try std.testing.expectEqual(@as(u32, 2), start);
1126
- try std.testing.expectEqual(@as(u32, 28), end);
1127
- }
1128
-
1129
- test "TextBufferView selection - changes when wrap width changes" {
1130
- const pool = gp.initGlobalPool(std.testing.allocator);
1131
- defer gp.deinitGlobalPool();
1132
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1133
- defer link.deinitGlobalLinkPool();
1134
-
1135
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1136
- defer tb.deinit();
1137
-
1138
- var view = try TextBufferView.init(std.testing.allocator, tb);
1139
- defer view.deinit();
1140
-
1141
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
1142
-
1143
- view.setWrapMode(.char);
1144
- view.setWrapWidth(10);
1145
- _ = view.setLocalSelection(5, 0, 5, 1, null, null);
1146
-
1147
- var packed_info = view.packSelectionInfo();
1148
- var start = @as(u32, @intCast(packed_info >> 32));
1149
- var end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
1150
- try std.testing.expectEqual(@as(u32, 5), start);
1151
- try std.testing.expectEqual(@as(u32, 15), end);
1152
-
1153
- view.setWrapMode(.char);
1154
- view.setWrapWidth(5);
1155
- _ = view.setLocalSelection(5, 0, 5, 1, null, null);
1156
-
1157
- packed_info = view.packSelectionInfo();
1158
- start = @as(u32, @intCast(packed_info >> 32));
1159
- end = @as(u32, @intCast(packed_info & 0xFFFFFFFF));
1160
-
1161
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1162
- }
1163
-
1164
- test "TextBufferView selection - empty selection with wrapping" {
1165
- const pool = gp.initGlobalPool(std.testing.allocator);
1166
- defer gp.deinitGlobalPool();
1167
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1168
- defer link.deinitGlobalLinkPool();
1169
-
1170
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1171
- defer tb.deinit();
1172
-
1173
- var view = try TextBufferView.init(std.testing.allocator, tb);
1174
- defer view.deinit();
1175
-
1176
- try tb.setText("ABCDEFGHIJ");
1177
-
1178
- view.setWrapMode(.char);
1179
- view.setWrapWidth(5);
1180
-
1181
- _ = view.setLocalSelection(2, 0, 2, 0, null, null);
1182
-
1183
- const packed_info = view.packSelectionInfo();
1184
-
1185
- try std.testing.expectEqual(@as(u64, 0xFFFFFFFF_FFFFFFFF), packed_info);
1186
- }
1187
-
1188
- test "TextBufferView selection - with newlines and wrapping" {
1189
- const pool = gp.initGlobalPool(std.testing.allocator);
1190
- defer gp.deinitGlobalPool();
1191
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1192
- defer link.deinitGlobalLinkPool();
1193
-
1194
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1195
- defer tb.deinit();
1196
-
1197
- var view = try TextBufferView.init(std.testing.allocator, tb);
1198
- defer view.deinit();
1199
-
1200
- try tb.setText("ABCDEFGHIJKLMNO\nPQRSTUVWXYZ");
1201
-
1202
- view.setWrapMode(.char);
1203
- view.setWrapWidth(10);
1204
-
1205
- const vline_count = view.getVirtualLineCount();
1206
- try std.testing.expect(vline_count >= 3);
1207
-
1208
- _ = view.setLocalSelection(5, 0, 5, 2, null, null);
1209
-
1210
- const packed_info = view.packSelectionInfo();
1211
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1212
- }
1213
-
1214
- test "TextBufferView selection - reset clears selection" {
1215
- const pool = gp.initGlobalPool(std.testing.allocator);
1216
- defer gp.deinitGlobalPool();
1217
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1218
- defer link.deinitGlobalLinkPool();
1219
-
1220
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1221
- defer tb.deinit();
1222
-
1223
- var view = try TextBufferView.init(std.testing.allocator, tb);
1224
- defer view.deinit();
1225
-
1226
- try tb.setText("Hello World");
1227
-
1228
- _ = view.setLocalSelection(0, 0, 5, 0, null, null);
1229
- var packed_info = view.packSelectionInfo();
1230
- try std.testing.expect(packed_info != 0xFFFFFFFF_FFFFFFFF);
1231
-
1232
- view.resetLocalSelection();
1233
- packed_info = view.packSelectionInfo();
1234
- try std.testing.expectEqual(@as(u64, 0xFFFFFFFF_FFFFFFFF), packed_info);
1235
- }
1236
-
1237
- test "TextBufferView selection - spanning multiple lines" {
1238
- const pool = gp.initGlobalPool(std.testing.allocator);
1239
- defer gp.deinitGlobalPool();
1240
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1241
- defer link.deinitGlobalLinkPool();
1242
-
1243
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1244
- defer tb.deinit();
1245
-
1246
- var view = try TextBufferView.init(std.testing.allocator, tb);
1247
- defer view.deinit();
1248
-
1249
- try tb.setText("Red\nBlue");
1250
-
1251
- view.setSelection(2, 5, null, null);
1252
-
1253
- var buffer: [100]u8 = undefined;
1254
- const len = view.getSelectedTextIntoBuffer(&buffer);
1255
- const text = buffer[0..len];
1256
-
1257
- try std.testing.expectEqualStrings("d\nB", text);
1258
- }
1259
-
1260
- test "TextBufferView line info - empty buffer" {
1261
- const pool = gp.initGlobalPool(std.testing.allocator);
1262
- defer gp.deinitGlobalPool();
1263
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1264
- defer link.deinitGlobalLinkPool();
1265
-
1266
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1267
- defer tb.deinit();
1268
-
1269
- var view = try TextBufferView.init(std.testing.allocator, tb);
1270
- defer view.deinit();
1271
-
1272
- try tb.setText("");
1273
-
1274
- const line_count = view.getVirtualLineCount();
1275
- try std.testing.expectEqual(@as(u32, 1), line_count);
1276
-
1277
- const line_info = view.getCachedLineInfo();
1278
- try std.testing.expectEqual(@as(usize, 1), line_info.line_start_cols.len);
1279
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1280
- try std.testing.expectEqual(@as(u32, 0), line_info.line_width_cols[0]);
1281
- }
1282
-
1283
- test "TextBufferView line info - simple text without newlines" {
1284
- const pool = gp.initGlobalPool(std.testing.allocator);
1285
- defer gp.deinitGlobalPool();
1286
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1287
- defer link.deinitGlobalLinkPool();
1288
-
1289
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1290
- defer tb.deinit();
1291
-
1292
- var view = try TextBufferView.init(std.testing.allocator, tb);
1293
- defer view.deinit();
1294
-
1295
- try tb.setText("Hello World");
1296
-
1297
- const line_count = view.getVirtualLineCount();
1298
- try std.testing.expectEqual(@as(u32, 1), line_count);
1299
-
1300
- const line_info = view.getCachedLineInfo();
1301
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1302
- try std.testing.expect(line_info.line_width_cols[0] > 0);
1303
- }
1304
-
1305
- test "TextBufferView line info - text ending with newline" {
1306
- const pool = gp.initGlobalPool(std.testing.allocator);
1307
- defer gp.deinitGlobalPool();
1308
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1309
- defer link.deinitGlobalLinkPool();
1310
-
1311
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1312
- defer tb.deinit();
1313
-
1314
- var view = try TextBufferView.init(std.testing.allocator, tb);
1315
- defer view.deinit();
1316
-
1317
- try tb.setText("Hello World\n");
1318
-
1319
- const line_count = view.getVirtualLineCount();
1320
- try std.testing.expectEqual(@as(u32, 2), line_count);
1321
-
1322
- const line_info = view.getCachedLineInfo();
1323
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1324
- try std.testing.expect(line_info.line_width_cols[0] > 0);
1325
- try std.testing.expect(line_info.line_width_cols[1] >= 0);
1326
- }
1327
-
1328
- test "TextBufferView line info - consecutive newlines" {
1329
- const pool = gp.initGlobalPool(std.testing.allocator);
1330
- defer gp.deinitGlobalPool();
1331
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1332
- defer link.deinitGlobalLinkPool();
1333
-
1334
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1335
- defer tb.deinit();
1336
-
1337
- var view = try TextBufferView.init(std.testing.allocator, tb);
1338
- defer view.deinit();
1339
-
1340
- try tb.setText("Line 1\n\nLine 3");
1341
-
1342
- const line_count = view.getVirtualLineCount();
1343
- try std.testing.expectEqual(@as(u32, 3), line_count);
1344
-
1345
- const line_info = view.getCachedLineInfo();
1346
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1347
- }
1348
-
1349
- test "TextBufferView line info - only newlines" {
1350
- const pool = gp.initGlobalPool(std.testing.allocator);
1351
- defer gp.deinitGlobalPool();
1352
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1353
- defer link.deinitGlobalLinkPool();
1354
-
1355
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1356
- defer tb.deinit();
1357
-
1358
- var view = try TextBufferView.init(std.testing.allocator, tb);
1359
- defer view.deinit();
1360
-
1361
- try tb.setText("\n\n\n");
1362
-
1363
- const line_count = view.getVirtualLineCount();
1364
- try std.testing.expectEqual(@as(u32, 4), line_count);
1365
-
1366
- const line_info = view.getCachedLineInfo();
1367
- for (line_info.line_width_cols) |width| {
1368
- try std.testing.expect(width >= 0);
1369
- }
1370
- }
1371
-
1372
- test "TextBufferView line info - wide characters (Unicode)" {
1373
- const pool = gp.initGlobalPool(std.testing.allocator);
1374
- defer gp.deinitGlobalPool();
1375
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1376
- defer link.deinitGlobalLinkPool();
1377
-
1378
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1379
- defer tb.deinit();
1380
-
1381
- var view = try TextBufferView.init(std.testing.allocator, tb);
1382
- defer view.deinit();
1383
-
1384
- try tb.setText("Hello 世界 🌟");
1385
-
1386
- const line_count = view.getVirtualLineCount();
1387
- try std.testing.expectEqual(@as(u32, 1), line_count);
1388
-
1389
- const line_info = view.getCachedLineInfo();
1390
- try std.testing.expect(line_info.line_width_cols[0] > 0);
1391
- }
1392
-
1393
- test "TextBufferView line info - very long lines" {
1394
- const pool = gp.initGlobalPool(std.testing.allocator);
1395
- defer gp.deinitGlobalPool();
1396
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1397
- defer link.deinitGlobalLinkPool();
1398
-
1399
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1400
- defer tb.deinit();
1401
-
1402
- var view = try TextBufferView.init(std.testing.allocator, tb);
1403
- defer view.deinit();
1404
-
1405
- const longText = [_]u8{'A'} ** 1000;
1406
- try tb.setText(&longText);
1407
-
1408
- const line_count = view.getVirtualLineCount();
1409
- try std.testing.expectEqual(@as(u32, 1), line_count);
1410
-
1411
- const line_info = view.getCachedLineInfo();
1412
- try std.testing.expect(line_info.line_width_cols[0] > 0);
1413
- }
1414
-
1415
- test "TextBufferView line info - buffer with only whitespace" {
1416
- const pool = gp.initGlobalPool(std.testing.allocator);
1417
- defer gp.deinitGlobalPool();
1418
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1419
- defer link.deinitGlobalLinkPool();
1420
-
1421
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1422
- defer tb.deinit();
1423
-
1424
- var view = try TextBufferView.init(std.testing.allocator, tb);
1425
- defer view.deinit();
1426
-
1427
- try tb.setText(" \n \n ");
1428
-
1429
- const line_count = view.getVirtualLineCount();
1430
- try std.testing.expectEqual(@as(u32, 3), line_count);
1431
-
1432
- const line_info = view.getCachedLineInfo();
1433
- for (line_info.line_width_cols) |width| {
1434
- try std.testing.expect(width >= 0);
1435
- }
1436
- }
1437
-
1438
- test "TextBufferView line info - single character lines" {
1439
- const pool = gp.initGlobalPool(std.testing.allocator);
1440
- defer gp.deinitGlobalPool();
1441
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1442
- defer link.deinitGlobalLinkPool();
1443
-
1444
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1445
- defer tb.deinit();
1446
-
1447
- var view = try TextBufferView.init(std.testing.allocator, tb);
1448
- defer view.deinit();
1449
-
1450
- try tb.setText("A\nB\nC");
1451
-
1452
- const line_count = view.getVirtualLineCount();
1453
- try std.testing.expectEqual(@as(u32, 3), line_count);
1454
-
1455
- const line_info = view.getCachedLineInfo();
1456
- for (line_info.line_width_cols) |width| {
1457
- try std.testing.expect(width > 0);
1458
- }
1459
- }
1460
-
1461
- test "TextBufferView line info - complex Unicode combining characters" {
1462
- const pool = gp.initGlobalPool(std.testing.allocator);
1463
- defer gp.deinitGlobalPool();
1464
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1465
- defer link.deinitGlobalLinkPool();
1466
-
1467
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1468
- defer tb.deinit();
1469
-
1470
- var view = try TextBufferView.init(std.testing.allocator, tb);
1471
- defer view.deinit();
1472
-
1473
- try tb.setText("café\nnaïve\nrésumé");
1474
-
1475
- const line_count = view.getVirtualLineCount();
1476
- try std.testing.expectEqual(@as(u32, 3), line_count);
1477
-
1478
- const line_info = view.getCachedLineInfo();
1479
- for (line_info.line_width_cols) |width| {
1480
- try std.testing.expect(width > 0);
1481
- }
1482
- }
1483
-
1484
- test "TextBufferView line info - extremely long single line" {
1485
- const pool = gp.initGlobalPool(std.testing.allocator);
1486
- defer gp.deinitGlobalPool();
1487
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1488
- defer link.deinitGlobalLinkPool();
1489
-
1490
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1491
- defer tb.deinit();
1492
-
1493
- var view = try TextBufferView.init(std.testing.allocator, tb);
1494
- defer view.deinit();
1495
-
1496
- const extremelyLongText = [_]u8{'A'} ** 10000;
1497
- try tb.setText(&extremelyLongText);
1498
-
1499
- const line_count = view.getVirtualLineCount();
1500
- try std.testing.expectEqual(@as(u32, 1), line_count);
1501
-
1502
- const line_info = view.getCachedLineInfo();
1503
- try std.testing.expect(line_info.line_width_cols[0] > 0);
1504
- }
1505
-
1506
- test "TextBufferView line info - extremely long line with wrapping" {
1507
- const pool = gp.initGlobalPool(std.testing.allocator);
1508
- defer gp.deinitGlobalPool();
1509
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1510
- defer link.deinitGlobalLinkPool();
1511
-
1512
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1513
- defer tb.deinit();
1514
-
1515
- var view = try TextBufferView.init(std.testing.allocator, tb);
1516
- defer view.deinit();
1517
-
1518
- // Create extremely long text with 10000 'A' characters
1519
- const extremelyLongText = [_]u8{'A'} ** 10000;
1520
- try tb.setText(&extremelyLongText);
1521
-
1522
- view.setWrapMode(.char);
1523
- view.setWrapWidth(80);
1524
- const wrapped_count = view.getVirtualLineCount();
1525
-
1526
- try std.testing.expect(wrapped_count > 100);
1527
- }
1528
-
1529
- test "TextBufferView getPlainTextIntoBuffer - simple text without newlines" {
1530
- const pool = gp.initGlobalPool(std.testing.allocator);
1531
- defer gp.deinitGlobalPool();
1532
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1533
- defer link.deinitGlobalLinkPool();
1534
-
1535
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1536
- defer tb.deinit();
1537
-
1538
- var view = try TextBufferView.init(std.testing.allocator, tb);
1539
- defer view.deinit();
1540
-
1541
- try tb.setText("Hello World");
1542
-
1543
- var buffer: [100]u8 = undefined;
1544
- const len = view.getPlainTextIntoBuffer(&buffer);
1545
- const text = buffer[0..len];
1546
-
1547
- try std.testing.expectEqualStrings("Hello World", text);
1548
- }
1549
-
1550
- test "TextBufferView getPlainTextIntoBuffer - text with newlines" {
1551
- const pool = gp.initGlobalPool(std.testing.allocator);
1552
- defer gp.deinitGlobalPool();
1553
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1554
- defer link.deinitGlobalLinkPool();
1555
-
1556
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1557
- defer tb.deinit();
1558
-
1559
- var view = try TextBufferView.init(std.testing.allocator, tb);
1560
- defer view.deinit();
1561
-
1562
- try tb.setText("Line 1\nLine 2\nLine 3");
1563
-
1564
- var buffer: [100]u8 = undefined;
1565
- const len = view.getPlainTextIntoBuffer(&buffer);
1566
- const text = buffer[0..len];
1567
-
1568
- try std.testing.expectEqualStrings("Line 1\nLine 2\nLine 3", text);
1569
- }
1570
-
1571
- test "TextBufferView getPlainTextIntoBuffer - text with only newlines" {
1572
- const pool = gp.initGlobalPool(std.testing.allocator);
1573
- defer gp.deinitGlobalPool();
1574
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1575
- defer link.deinitGlobalLinkPool();
1576
-
1577
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1578
- defer tb.deinit();
1579
-
1580
- var view = try TextBufferView.init(std.testing.allocator, tb);
1581
- defer view.deinit();
1582
-
1583
- try tb.setText("\n\n\n");
1584
-
1585
- var buffer: [100]u8 = undefined;
1586
- const len = view.getPlainTextIntoBuffer(&buffer);
1587
- const text = buffer[0..len];
1588
-
1589
- try std.testing.expectEqualStrings("\n\n\n", text);
1590
- }
1591
-
1592
- test "TextBufferView getPlainTextIntoBuffer - empty lines between content" {
1593
- const pool = gp.initGlobalPool(std.testing.allocator);
1594
- defer gp.deinitGlobalPool();
1595
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1596
- defer link.deinitGlobalLinkPool();
1597
-
1598
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1599
- defer tb.deinit();
1600
-
1601
- var view = try TextBufferView.init(std.testing.allocator, tb);
1602
- defer view.deinit();
1603
-
1604
- try tb.setText("First\n\nThird");
1605
-
1606
- var buffer: [100]u8 = undefined;
1607
- const len = view.getPlainTextIntoBuffer(&buffer);
1608
- const text = buffer[0..len];
1609
-
1610
- try std.testing.expectEqualStrings("First\n\nThird", text);
1611
- }
1612
-
1613
- test "TextBufferView line info - text starting with newline" {
1614
- const pool = gp.initGlobalPool(std.testing.allocator);
1615
- defer gp.deinitGlobalPool();
1616
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1617
- defer link.deinitGlobalLinkPool();
1618
-
1619
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1620
- defer tb.deinit();
1621
-
1622
- var view = try TextBufferView.init(std.testing.allocator, tb);
1623
- defer view.deinit();
1624
-
1625
- try tb.setText("\nHello World");
1626
-
1627
- const line_count = view.getVirtualLineCount();
1628
- try std.testing.expectEqual(@as(u32, 2), line_count);
1629
-
1630
- const line_info = view.getCachedLineInfo();
1631
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1632
-
1633
- try std.testing.expectEqual(@as(u32, 1), line_info.line_start_cols[1]);
1634
- }
1635
-
1636
- test "TextBufferView line info - lines with different widths" {
1637
- const pool = gp.initGlobalPool(std.testing.allocator);
1638
- defer gp.deinitGlobalPool();
1639
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1640
- defer link.deinitGlobalLinkPool();
1641
-
1642
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1643
- defer tb.deinit();
1644
-
1645
- var view = try TextBufferView.init(std.testing.allocator, tb);
1646
- defer view.deinit();
1647
-
1648
- var text_builder: std.ArrayListUnmanaged(u8) = .{};
1649
- defer text_builder.deinit(std.testing.allocator);
1650
- try text_builder.appendSlice(std.testing.allocator, "Short\n");
1651
- try text_builder.appendNTimes(std.testing.allocator, 'A', 50);
1652
- try text_builder.appendSlice(std.testing.allocator, "\nMedium");
1653
- const text = text_builder.items;
1654
-
1655
- try tb.setText(text);
1656
-
1657
- const line_count = view.getVirtualLineCount();
1658
- try std.testing.expectEqual(@as(u32, 3), line_count);
1659
-
1660
- const line_info = view.getCachedLineInfo();
1661
- try std.testing.expect(line_info.line_width_cols[0] < line_info.line_width_cols[1]);
1662
- try std.testing.expect(line_info.line_width_cols[1] > line_info.line_width_cols[2]);
1663
- }
1664
-
1665
- test "TextBufferView line info - alternating empty and content lines" {
1666
- const pool = gp.initGlobalPool(std.testing.allocator);
1667
- defer gp.deinitGlobalPool();
1668
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1669
- defer link.deinitGlobalLinkPool();
1670
-
1671
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1672
- defer tb.deinit();
1673
-
1674
- var view = try TextBufferView.init(std.testing.allocator, tb);
1675
- defer view.deinit();
1676
-
1677
- try tb.setText("\nContent\n\nMore\n\n");
1678
-
1679
- const line_count = view.getVirtualLineCount();
1680
- try std.testing.expectEqual(@as(u32, 6), line_count);
1681
-
1682
- const line_info = view.getCachedLineInfo();
1683
- for (line_info.line_width_cols) |width| {
1684
- try std.testing.expect(width >= 0);
1685
- }
1686
- }
1687
-
1688
- test "TextBufferView line info - thousands of lines" {
1689
- const pool = gp.initGlobalPool(std.testing.allocator);
1690
- defer gp.deinitGlobalPool();
1691
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1692
- defer link.deinitGlobalLinkPool();
1693
-
1694
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1695
- defer tb.deinit();
1696
-
1697
- var view = try TextBufferView.init(std.testing.allocator, tb);
1698
- defer view.deinit();
1699
-
1700
- var text_builder: std.ArrayListUnmanaged(u8) = .{};
1701
- defer text_builder.deinit(std.testing.allocator);
1702
-
1703
- var i: u32 = 0;
1704
- while (i < 999) : (i += 1) {
1705
- try text_builder.writer(std.testing.allocator).print("Line {}\n", .{i});
1706
- }
1707
- try text_builder.writer(std.testing.allocator).print("Line {}", .{i});
1708
-
1709
- try tb.setText(text_builder.items);
1710
-
1711
- const line_count = view.getVirtualLineCount();
1712
- try std.testing.expectEqual(@as(u32, 1000), line_count);
1713
-
1714
- const line_info = view.getCachedLineInfo();
1715
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
1716
-
1717
- var line_idx: u32 = 1;
1718
- while (line_idx < 1000) : (line_idx += 1) {
1719
- try std.testing.expect(line_info.line_start_cols[line_idx] > line_info.line_start_cols[line_idx - 1]);
1720
- }
1721
- }
1722
-
1723
- test "TextBufferView highlights - add single highlight to line" {
1724
- const pool = gp.initGlobalPool(std.testing.allocator);
1725
- defer gp.deinitGlobalPool();
1726
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1727
- defer link.deinitGlobalLinkPool();
1728
-
1729
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1730
- defer tb.deinit();
1731
-
1732
- var view = try TextBufferView.init(std.testing.allocator, tb);
1733
- defer view.deinit();
1734
-
1735
- try tb.setText("Hello World");
1736
-
1737
- try tb.addHighlight(0, 0, 5, 1, 0, 0);
1738
-
1739
- const highlights = tb.getLineHighlights(0);
1740
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
1741
- try std.testing.expectEqual(@as(u32, 0), highlights[0].col_start);
1742
- try std.testing.expectEqual(@as(u32, 5), highlights[0].col_end);
1743
- try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
1744
- }
1745
-
1746
- test "TextBufferView highlights - add multiple highlights to same line" {
1747
- const pool = gp.initGlobalPool(std.testing.allocator);
1748
- defer gp.deinitGlobalPool();
1749
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1750
- defer link.deinitGlobalLinkPool();
1751
-
1752
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1753
- defer tb.deinit();
1754
-
1755
- var view = try TextBufferView.init(std.testing.allocator, tb);
1756
- defer view.deinit();
1757
-
1758
- try tb.setText("Hello World");
1759
-
1760
- try tb.addHighlight(0, 0, 5, 1, 0, 0);
1761
- try tb.addHighlight(0, 6, 11, 2, 0, 0);
1762
-
1763
- const highlights = tb.getLineHighlights(0);
1764
- try std.testing.expectEqual(@as(usize, 2), highlights.len);
1765
- try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
1766
- try std.testing.expectEqual(@as(u32, 2), highlights[1].style_id);
1767
- }
1768
-
1769
- test "TextBufferView highlights - add highlights to multiple lines" {
1770
- const pool = gp.initGlobalPool(std.testing.allocator);
1771
- defer gp.deinitGlobalPool();
1772
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1773
- defer link.deinitGlobalLinkPool();
1774
-
1775
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1776
- defer tb.deinit();
1777
-
1778
- var view = try TextBufferView.init(std.testing.allocator, tb);
1779
- defer view.deinit();
1780
-
1781
- try tb.setText("Line 1\nLine 2\nLine 3");
1782
-
1783
- try tb.addHighlight(0, 0, 6, 1, 0, 0);
1784
- try tb.addHighlight(1, 0, 6, 2, 0, 0);
1785
- try tb.addHighlight(2, 0, 6, 3, 0, 0);
1786
-
1787
- try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(0).len);
1788
- try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(1).len);
1789
- try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(2).len);
1790
- }
1791
-
1792
- test "TextBufferView highlights - remove highlights by reference" {
1793
- const pool = gp.initGlobalPool(std.testing.allocator);
1794
- defer gp.deinitGlobalPool();
1795
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1796
- defer link.deinitGlobalLinkPool();
1797
-
1798
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1799
- defer tb.deinit();
1800
-
1801
- var view = try TextBufferView.init(std.testing.allocator, tb);
1802
- defer view.deinit();
1803
-
1804
- try tb.setText("Line 1\nLine 2");
1805
-
1806
- try tb.addHighlight(0, 0, 3, 1, 0, 100);
1807
- try tb.addHighlight(0, 3, 6, 2, 0, 200);
1808
- try tb.addHighlight(1, 0, 6, 3, 0, 100);
1809
-
1810
- tb.removeHighlightsByRef(100);
1811
-
1812
- const line0_highlights = tb.getLineHighlights(0);
1813
- const line1_highlights = tb.getLineHighlights(1);
1814
-
1815
- try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
1816
- try std.testing.expectEqual(@as(u32, 2), line0_highlights[0].style_id);
1817
- try std.testing.expectEqual(@as(usize, 0), line1_highlights.len);
1818
- }
1819
-
1820
- test "TextBufferView highlights - clear line highlights" {
1821
- const pool = gp.initGlobalPool(std.testing.allocator);
1822
- defer gp.deinitGlobalPool();
1823
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1824
- defer link.deinitGlobalLinkPool();
1825
-
1826
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1827
- defer tb.deinit();
1828
-
1829
- var view = try TextBufferView.init(std.testing.allocator, tb);
1830
- defer view.deinit();
1831
-
1832
- try tb.setText("Line 1\nLine 2");
1833
-
1834
- try tb.addHighlight(0, 0, 6, 1, 0, 0);
1835
- try tb.addHighlight(0, 6, 10, 2, 0, 0);
1836
-
1837
- tb.clearLineHighlights(0);
1838
-
1839
- const highlights = tb.getLineHighlights(0);
1840
- try std.testing.expectEqual(@as(usize, 0), highlights.len);
1841
- }
1842
-
1843
- test "TextBufferView highlights - clear all highlights" {
1844
- const pool = gp.initGlobalPool(std.testing.allocator);
1845
- defer gp.deinitGlobalPool();
1846
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1847
- defer link.deinitGlobalLinkPool();
1848
-
1849
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1850
- defer tb.deinit();
1851
-
1852
- var view = try TextBufferView.init(std.testing.allocator, tb);
1853
- defer view.deinit();
1854
-
1855
- try tb.setText("Line 1\nLine 2\nLine 3");
1856
-
1857
- try tb.addHighlight(0, 0, 6, 1, 0, 0);
1858
- try tb.addHighlight(1, 0, 6, 2, 0, 0);
1859
- try tb.addHighlight(2, 0, 6, 3, 0, 0);
1860
-
1861
- tb.clearAllHighlights();
1862
-
1863
- try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(0).len);
1864
- try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(1).len);
1865
- try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(2).len);
1866
- }
1867
-
1868
- test "TextBufferView highlights - overlapping highlights" {
1869
- const pool = gp.initGlobalPool(std.testing.allocator);
1870
- defer gp.deinitGlobalPool();
1871
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1872
- defer link.deinitGlobalLinkPool();
1873
-
1874
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1875
- defer tb.deinit();
1876
-
1877
- var view = try TextBufferView.init(std.testing.allocator, tb);
1878
- defer view.deinit();
1879
-
1880
- try tb.setText("Hello World");
1881
-
1882
- try tb.addHighlight(0, 0, 8, 1, 0, 0);
1883
- try tb.addHighlight(0, 5, 11, 2, 0, 0);
1884
-
1885
- const highlights = tb.getLineHighlights(0);
1886
- try std.testing.expectEqual(@as(usize, 2), highlights.len);
1887
- }
1888
-
1889
- test "TextBufferView highlights - style spans computed correctly" {
1890
- const pool = gp.initGlobalPool(std.testing.allocator);
1891
- defer gp.deinitGlobalPool();
1892
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1893
- defer link.deinitGlobalLinkPool();
1894
-
1895
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1896
- defer tb.deinit();
1897
-
1898
- var view = try TextBufferView.init(std.testing.allocator, tb);
1899
- defer view.deinit();
1900
-
1901
- try tb.setText("0123456789");
1902
-
1903
- try tb.addHighlight(0, 0, 3, 1, 1, 0);
1904
- try tb.addHighlight(0, 5, 8, 2, 1, 0);
1905
-
1906
- const spans = tb.getLineSpans(0);
1907
- try std.testing.expect(spans.len > 0);
1908
-
1909
- var found_style1 = false;
1910
- var found_style2 = false;
1911
- for (spans) |span| {
1912
- if (span.style_id == 1) found_style1 = true;
1913
- if (span.style_id == 2) found_style2 = true;
1914
- }
1915
- try std.testing.expect(found_style1);
1916
- try std.testing.expect(found_style2);
1917
- }
1918
-
1919
- test "TextBufferView highlights - priority handling in spans" {
1920
- const pool = gp.initGlobalPool(std.testing.allocator);
1921
- defer gp.deinitGlobalPool();
1922
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1923
- defer link.deinitGlobalLinkPool();
1924
-
1925
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1926
- defer tb.deinit();
1927
-
1928
- var view = try TextBufferView.init(std.testing.allocator, tb);
1929
- defer view.deinit();
1930
-
1931
- try tb.setText("0123456789");
1932
-
1933
- try tb.addHighlight(0, 0, 8, 1, 1, 0);
1934
- try tb.addHighlight(0, 3, 6, 2, 5, 0);
1935
-
1936
- const spans = tb.getLineSpans(0);
1937
- try std.testing.expect(spans.len > 0);
1938
-
1939
- var found_high_priority = false;
1940
- for (spans) |span| {
1941
- if (span.col >= 3 and span.col < 6 and span.style_id == 2) {
1942
- found_high_priority = true;
1943
- }
1944
- }
1945
- try std.testing.expect(found_high_priority);
1946
- }
1947
-
1948
- test "TextBufferView char range highlights - single line highlight" {
1949
- const pool = gp.initGlobalPool(std.testing.allocator);
1950
- defer gp.deinitGlobalPool();
1951
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1952
- defer link.deinitGlobalLinkPool();
1953
-
1954
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1955
- defer tb.deinit();
1956
-
1957
- var view = try TextBufferView.init(std.testing.allocator, tb);
1958
- defer view.deinit();
1959
-
1960
- try tb.setText("Hello World");
1961
-
1962
- try tb.addHighlightByCharRange(0, 5, 1, 1, 0);
1963
-
1964
- const highlights = tb.getLineHighlights(0);
1965
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
1966
- try std.testing.expectEqual(@as(u32, 0), highlights[0].col_start);
1967
- try std.testing.expectEqual(@as(u32, 5), highlights[0].col_end);
1968
- try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
1969
- }
1970
-
1971
- test "TextBufferView char range highlights - multi-line highlight" {
1972
- const pool = gp.initGlobalPool(std.testing.allocator);
1973
- defer gp.deinitGlobalPool();
1974
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
1975
- defer link.deinitGlobalLinkPool();
1976
-
1977
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
1978
- defer tb.deinit();
1979
-
1980
- var view = try TextBufferView.init(std.testing.allocator, tb);
1981
- defer view.deinit();
1982
-
1983
- try tb.setText("Hello\nWorld\nTest");
1984
-
1985
- try tb.addHighlightByCharRange(3, 9, 1, 1, 0);
1986
-
1987
- const line0_highlights = tb.getLineHighlights(0);
1988
- const line1_highlights = tb.getLineHighlights(1);
1989
-
1990
- try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
1991
- try std.testing.expectEqual(@as(usize, 1), line1_highlights.len);
1992
-
1993
- try std.testing.expectEqual(@as(u32, 3), line0_highlights[0].col_start);
1994
- try std.testing.expectEqual(@as(u32, 5), line0_highlights[0].col_end);
1995
-
1996
- try std.testing.expectEqual(@as(u32, 0), line1_highlights[0].col_start);
1997
- try std.testing.expectEqual(@as(u32, 4), line1_highlights[0].col_end);
1998
- }
1999
-
2000
- test "TextBufferView char range highlights - spanning three lines" {
2001
- const pool = gp.initGlobalPool(std.testing.allocator);
2002
- defer gp.deinitGlobalPool();
2003
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2004
- defer link.deinitGlobalLinkPool();
2005
-
2006
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2007
- defer tb.deinit();
2008
-
2009
- var view = try TextBufferView.init(std.testing.allocator, tb);
2010
- defer view.deinit();
2011
-
2012
- try tb.setText("Line1\nLine2\nLine3");
2013
-
2014
- try tb.addHighlightByCharRange(3, 13, 1, 1, 0);
2015
-
2016
- const line0_highlights = tb.getLineHighlights(0);
2017
- const line1_highlights = tb.getLineHighlights(1);
2018
- const line2_highlights = tb.getLineHighlights(2);
2019
-
2020
- try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
2021
- try std.testing.expectEqual(@as(usize, 1), line1_highlights.len);
2022
- try std.testing.expectEqual(@as(usize, 1), line2_highlights.len);
2023
-
2024
- try std.testing.expectEqual(@as(u32, 3), line0_highlights[0].col_start);
2025
- try std.testing.expectEqual(@as(u32, 0), line1_highlights[0].col_start);
2026
- try std.testing.expectEqual(@as(u32, 0), line2_highlights[0].col_start);
2027
- }
2028
-
2029
- test "TextBufferView char range highlights - empty range" {
2030
- const pool = gp.initGlobalPool(std.testing.allocator);
2031
- defer gp.deinitGlobalPool();
2032
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2033
- defer link.deinitGlobalLinkPool();
2034
-
2035
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2036
- defer tb.deinit();
2037
-
2038
- var view = try TextBufferView.init(std.testing.allocator, tb);
2039
- defer view.deinit();
2040
-
2041
- try tb.setText("Hello World");
2042
-
2043
- try tb.addHighlightByCharRange(5, 5, 1, 1, 0);
2044
-
2045
- const highlights = tb.getLineHighlights(0);
2046
- try std.testing.expectEqual(@as(usize, 0), highlights.len);
2047
- }
2048
-
2049
- test "TextBufferView char range highlights - multiple non-overlapping ranges" {
2050
- const pool = gp.initGlobalPool(std.testing.allocator);
2051
- defer gp.deinitGlobalPool();
2052
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2053
- defer link.deinitGlobalLinkPool();
2054
-
2055
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2056
- defer tb.deinit();
2057
-
2058
- var view = try TextBufferView.init(std.testing.allocator, tb);
2059
- defer view.deinit();
2060
-
2061
- try tb.setText("function hello() { return 42; }");
2062
-
2063
- try tb.addHighlightByCharRange(0, 8, 1, 1, 0);
2064
- try tb.addHighlightByCharRange(9, 14, 2, 1, 0);
2065
- try tb.addHighlightByCharRange(19, 25, 3, 1, 0);
2066
-
2067
- const highlights = tb.getLineHighlights(0);
2068
- try std.testing.expectEqual(@as(usize, 3), highlights.len);
2069
- try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
2070
- try std.testing.expectEqual(@as(u32, 2), highlights[1].style_id);
2071
- try std.testing.expectEqual(@as(u32, 3), highlights[2].style_id);
2072
- }
2073
-
2074
- test "TextBufferView char range highlights - with reference ID for removal" {
2075
- const pool = gp.initGlobalPool(std.testing.allocator);
2076
- defer gp.deinitGlobalPool();
2077
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2078
- defer link.deinitGlobalLinkPool();
2079
-
2080
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2081
- defer tb.deinit();
2082
-
2083
- var view = try TextBufferView.init(std.testing.allocator, tb);
2084
- defer view.deinit();
2085
-
2086
- try tb.setText("Line1\nLine2\nLine3");
2087
-
2088
- try tb.addHighlightByCharRange(0, 5, 1, 1, 100);
2089
- try tb.addHighlightByCharRange(6, 11, 2, 1, 100);
2090
-
2091
- try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(0).len);
2092
- try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(1).len);
2093
-
2094
- tb.removeHighlightsByRef(100);
2095
-
2096
- try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(0).len);
2097
- try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(1).len);
2098
- }
2099
-
2100
- test "TextBufferView highlights - work correctly with wrapped lines" {
2101
- const pool = gp.initGlobalPool(std.testing.allocator);
2102
- defer gp.deinitGlobalPool();
2103
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2104
- defer link.deinitGlobalLinkPool();
2105
-
2106
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2107
- defer tb.deinit();
2108
-
2109
- var view = try TextBufferView.init(std.testing.allocator, tb);
2110
- defer view.deinit();
2111
-
2112
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
2113
-
2114
- try tb.addHighlight(0, 5, 15, 1, 1, 0);
2115
-
2116
- view.setWrapMode(.char);
2117
- view.setWrapWidth(10);
2118
-
2119
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
2120
-
2121
- const vline0_info = view.getVirtualLineSpans(0);
2122
- const vline1_info = view.getVirtualLineSpans(1);
2123
-
2124
- try std.testing.expectEqual(@as(usize, 0), vline0_info.source_line);
2125
- try std.testing.expectEqual(@as(usize, 0), vline1_info.source_line);
2126
-
2127
- try std.testing.expectEqual(@as(u32, 0), vline0_info.col_offset);
2128
- try std.testing.expectEqual(@as(u32, 10), vline1_info.col_offset);
2129
-
2130
- try std.testing.expect(vline0_info.spans.len > 0);
2131
- try std.testing.expect(vline1_info.spans.len > 0);
2132
- }
2133
-
2134
- test "TextBufferView measureForDimensions - does not modify cache" {
2135
- const pool = gp.initGlobalPool(std.testing.allocator);
2136
- defer gp.deinitGlobalPool();
2137
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2138
- defer link.deinitGlobalLinkPool();
2139
-
2140
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2141
- defer tb.deinit();
2142
-
2143
- var view = try TextBufferView.init(std.testing.allocator, tb);
2144
- defer view.deinit();
2145
-
2146
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
2147
-
2148
- // Set wrap mode but don't call updateVirtualLines
2149
- view.setWrapMode(.char);
2150
- view.setWrapWidth(100); // Large width, no wrapping expected
2151
-
2152
- // Measure with different width WITHOUT updating cache
2153
- const result = try view.measureForDimensions(10, 10);
2154
-
2155
- // Should have 2 lines for width 10
2156
- try std.testing.expectEqual(@as(u32, 2), result.line_count);
2157
- try std.testing.expectEqual(@as(u32, 10), result.width_cols_max);
2158
-
2159
- // Now check that the actual cached virtual lines are NOT changed
2160
- const actual_count = view.getVirtualLineCount();
2161
- // Should be 1 line because wrap_width is 100
2162
- try std.testing.expectEqual(@as(u32, 1), actual_count);
2163
- }
2164
-
2165
- test "TextBufferView measureForDimensions - cache invalidates after updateVirtualLines" {
2166
- const pool = gp.initGlobalPool(std.testing.allocator);
2167
- defer gp.deinitGlobalPool();
2168
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2169
- defer link.deinitGlobalLinkPool();
2170
-
2171
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2172
- defer tb.deinit();
2173
-
2174
- var view = try TextBufferView.init(std.testing.allocator, tb);
2175
- defer view.deinit();
2176
-
2177
- try tb.setText("AAAAA");
2178
- view.setWrapMode(.char);
2179
- view.setWrapWidth(5);
2180
-
2181
- const result1 = try view.measureForDimensions(5, 10);
2182
- try std.testing.expectEqual(@as(u32, 1), result1.line_count);
2183
- try std.testing.expectEqual(@as(u32, 5), result1.width_cols_max);
2184
-
2185
- try tb.setText("AAAAAAAAAA");
2186
-
2187
- // This clears the dirty flag, which would cause a false cache hit
2188
- // if we keyed on dirty instead of epoch.
2189
- _ = view.getVirtualLineCount();
2190
-
2191
- const result2 = try view.measureForDimensions(5, 10);
2192
- try std.testing.expectEqual(@as(u32, 2), result2.line_count);
2193
- try std.testing.expectEqual(@as(u32, 5), result2.width_cols_max);
2194
- }
2195
-
2196
- test "TextBufferView measureForDimensions - width 0 uses intrinsic line widths" {
2197
- const pool = gp.initGlobalPool(std.testing.allocator);
2198
- defer gp.deinitGlobalPool();
2199
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2200
- defer link.deinitGlobalLinkPool();
2201
-
2202
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2203
- defer tb.deinit();
2204
-
2205
- var view = try TextBufferView.init(std.testing.allocator, tb);
2206
- defer view.deinit();
2207
-
2208
- try tb.setText("abc\ndefghij");
2209
- view.setWrapMode(.char);
2210
-
2211
- const result = try view.measureForDimensions(0, 24);
2212
- try std.testing.expectEqual(tb.getLineCount(), result.line_count);
2213
- try std.testing.expectEqual(iter_mod.getMaxLineWidth(tb.rope()), result.width_cols_max);
2214
- }
2215
-
2216
- test "TextBufferView measureForDimensions - no wrap matches multi-segment line widths" {
2217
- const pool = gp.initGlobalPool(std.testing.allocator);
2218
- defer gp.deinitGlobalPool();
2219
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2220
- defer link.deinitGlobalLinkPool();
2221
-
2222
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2223
- defer tb.deinit();
2224
-
2225
- var view = try TextBufferView.init(std.testing.allocator, tb);
2226
- defer view.deinit();
2227
-
2228
- try tb.setText("AAAA");
2229
- try tb.append("BBBB");
2230
- view.setWrapMode(.none);
2231
-
2232
- const line_info = view.getCachedLineInfo();
2233
- var expected_max: u32 = 0;
2234
- for (line_info.line_width_cols) |w| {
2235
- expected_max = @max(expected_max, w);
2236
- }
2237
-
2238
- const result = try view.measureForDimensions(80, 24);
2239
- try std.testing.expectEqual(expected_max, result.width_cols_max);
2240
- try std.testing.expectEqual(@as(u32, @intCast(line_info.line_width_cols.len)), result.line_count);
2241
- }
2242
-
2243
- test "TextBufferView measureForDimensions - cache invalidates on switchToBuffer" {
2244
- const pool = gp.initGlobalPool(std.testing.allocator);
2245
- defer gp.deinitGlobalPool();
2246
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2247
- defer link.deinitGlobalLinkPool();
2248
-
2249
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2250
- defer tb.deinit();
2251
-
2252
- var other_tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2253
- defer other_tb.deinit();
2254
-
2255
- var view = try TextBufferView.init(std.testing.allocator, tb);
2256
- defer view.deinit();
2257
-
2258
- try tb.setText("AAAAAA");
2259
- view.setWrapMode(.char);
2260
-
2261
- const result1 = try view.measureForDimensions(10, 10);
2262
- try std.testing.expectEqual(@as(u32, 6), result1.width_cols_max);
2263
-
2264
- try other_tb.setText("BBBBBBBBBB");
2265
- try std.testing.expectEqual(tb.getContentEpoch(), other_tb.getContentEpoch());
2266
-
2267
- view.switchToBuffer(other_tb);
2268
-
2269
- const result2 = try view.measureForDimensions(10, 10);
2270
- try std.testing.expectEqual(@as(u32, 10), result2.width_cols_max);
2271
- try std.testing.expectEqual(@as(u32, 1), result2.line_count);
2272
- }
2273
-
2274
- test "TextBufferView measureForDimensions - char wrap" {
2275
- const pool = gp.initGlobalPool(std.testing.allocator);
2276
- defer gp.deinitGlobalPool();
2277
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2278
- defer link.deinitGlobalLinkPool();
2279
-
2280
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2281
- defer tb.deinit();
2282
-
2283
- var view = try TextBufferView.init(std.testing.allocator, tb);
2284
- defer view.deinit();
2285
-
2286
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
2287
- view.setWrapMode(.char);
2288
-
2289
- // Test different widths
2290
- const result1 = try view.measureForDimensions(10, 10);
2291
- try std.testing.expectEqual(@as(u32, 2), result1.line_count);
2292
- try std.testing.expectEqual(@as(u32, 10), result1.width_cols_max);
2293
-
2294
- const result2 = try view.measureForDimensions(5, 10);
2295
- try std.testing.expectEqual(@as(u32, 4), result2.line_count);
2296
- try std.testing.expectEqual(@as(u32, 5), result2.width_cols_max);
2297
-
2298
- const result3 = try view.measureForDimensions(20, 10);
2299
- try std.testing.expectEqual(@as(u32, 1), result3.line_count);
2300
- try std.testing.expectEqual(@as(u32, 20), result3.width_cols_max);
2301
- }
2302
-
2303
- test "TextBufferView measureForDimensions - no wrap mode" {
2304
- const pool = gp.initGlobalPool(std.testing.allocator);
2305
- defer gp.deinitGlobalPool();
2306
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2307
- defer link.deinitGlobalLinkPool();
2308
-
2309
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2310
- defer tb.deinit();
2311
-
2312
- var view = try TextBufferView.init(std.testing.allocator, tb);
2313
- defer view.deinit();
2314
-
2315
- try tb.setText("Hello\nWorld\nTest");
2316
- view.setWrapMode(.none);
2317
-
2318
- // With no wrap, width shouldn't matter
2319
- const result = try view.measureForDimensions(3, 10);
2320
- try std.testing.expectEqual(@as(u32, 3), result.line_count);
2321
- // width_cols_max should be the longest line
2322
- try std.testing.expect(result.width_cols_max >= 4);
2323
- }
2324
-
2325
- test "TextBufferView measureForDimensions - word wrap" {
2326
- const pool = gp.initGlobalPool(std.testing.allocator);
2327
- defer gp.deinitGlobalPool();
2328
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2329
- defer link.deinitGlobalLinkPool();
2330
-
2331
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2332
- defer tb.deinit();
2333
-
2334
- var view = try TextBufferView.init(std.testing.allocator, tb);
2335
- defer view.deinit();
2336
-
2337
- try tb.setText("Hello wonderful world");
2338
- view.setWrapMode(.word);
2339
-
2340
- const result = try view.measureForDimensions(10, 10);
2341
- // Should wrap at word boundaries
2342
- try std.testing.expect(result.line_count >= 2);
2343
- try std.testing.expect(result.width_cols_max <= 10);
2344
- }
2345
-
2346
- test "TextBufferView measureForDimensions - empty buffer" {
2347
- const pool = gp.initGlobalPool(std.testing.allocator);
2348
- defer gp.deinitGlobalPool();
2349
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2350
- defer link.deinitGlobalLinkPool();
2351
-
2352
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2353
- defer tb.deinit();
2354
-
2355
- var view = try TextBufferView.init(std.testing.allocator, tb);
2356
- defer view.deinit();
2357
-
2358
- try tb.setText("");
2359
- view.setWrapMode(.char);
2360
-
2361
- const result = try view.measureForDimensions(10, 10);
2362
- try std.testing.expectEqual(@as(u32, 1), result.line_count);
2363
- try std.testing.expectEqual(@as(u32, 0), result.width_cols_max);
2364
- }
2365
-
2366
- test "TextBufferView truncation - basic truncate single line" {
2367
- const pool = gp.initGlobalPool(std.testing.allocator);
2368
- defer gp.deinitGlobalPool();
2369
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2370
- defer link.deinitGlobalLinkPool();
2371
-
2372
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2373
- defer tb.deinit();
2374
-
2375
- var view = try TextBufferView.init(std.testing.allocator, tb);
2376
- defer view.deinit();
2377
-
2378
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
2379
-
2380
- view.setTruncate(true);
2381
- view.setWrapMode(.none);
2382
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 10, .height = 5 });
2383
-
2384
- const vlines = view.getVirtualLines();
2385
-
2386
- // With truncation, line should be truncated to viewport width
2387
- try std.testing.expectEqual(@as(usize, 1), vlines.len);
2388
- // Width should be reduced (prefix + suffix, ellipsis handled separately)
2389
- try std.testing.expect(vlines[0].width_cols <= 10);
2390
- }
2391
-
2392
- test "TextBufferView truncation - multiline with truncate" {
2393
- const pool = gp.initGlobalPool(std.testing.allocator);
2394
- defer gp.deinitGlobalPool();
2395
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2396
- defer link.deinitGlobalLinkPool();
2397
-
2398
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2399
- defer tb.deinit();
2400
-
2401
- var view = try TextBufferView.init(std.testing.allocator, tb);
2402
- defer view.deinit();
2403
-
2404
- try tb.setText("ABCDEFGHIJKLMNOPQRST\nShortLine\nAnotherVeryLongLineHere");
2405
-
2406
- view.setTruncate(true);
2407
- view.setWrapMode(.none);
2408
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 12, .height = 5 });
2409
-
2410
- const vlines = view.getVirtualLines();
2411
-
2412
- try std.testing.expectEqual(@as(usize, 3), vlines.len);
2413
-
2414
- // First line should be truncated
2415
- try std.testing.expect(vlines[0].width_cols <= 12);
2416
- // Second line is short, should not be truncated
2417
- try std.testing.expectEqual(@as(u32, 9), vlines[1].width_cols);
2418
- // Third line should be truncated
2419
- try std.testing.expect(vlines[2].width_cols <= 12);
2420
- }
2421
-
2422
- test "TextBufferView truncation - with wrapping disabled" {
2423
- const pool = gp.initGlobalPool(std.testing.allocator);
2424
- defer gp.deinitGlobalPool();
2425
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2426
- defer link.deinitGlobalLinkPool();
2427
-
2428
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2429
- defer tb.deinit();
2430
-
2431
- var view = try TextBufferView.init(std.testing.allocator, tb);
2432
- defer view.deinit();
2433
-
2434
- try tb.setText("0123456789ABCDEFGHIJ");
2435
-
2436
- view.setTruncate(true);
2437
- view.setWrapMode(.none);
2438
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 15, .height = 1 });
2439
-
2440
- const vlines = view.getVirtualLines();
2441
-
2442
- try std.testing.expectEqual(@as(usize, 1), vlines.len);
2443
- // Should be truncated to fit viewport
2444
- try std.testing.expect(vlines[0].width_cols <= 15);
2445
- }
2446
-
2447
- test "TextBufferView truncation - toggle truncate on and off" {
2448
- const pool = gp.initGlobalPool(std.testing.allocator);
2449
- defer gp.deinitGlobalPool();
2450
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2451
- defer link.deinitGlobalLinkPool();
2452
-
2453
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2454
- defer tb.deinit();
2455
-
2456
- var view = try TextBufferView.init(std.testing.allocator, tb);
2457
- defer view.deinit();
2458
-
2459
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
2460
-
2461
- view.setWrapMode(.none);
2462
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 10, .height = 1 });
2463
-
2464
- // Without truncation
2465
- view.setTruncate(false);
2466
- var vlines = view.getVirtualLines();
2467
- const width_no_truncate = vlines[0].width_cols;
2468
-
2469
- // With truncation
2470
- view.setTruncate(true);
2471
- vlines = view.getVirtualLines();
2472
- const width_with_truncate = vlines[0].width_cols;
2473
-
2474
- try std.testing.expectEqual(@as(u32, 26), width_no_truncate);
2475
- try std.testing.expect(width_with_truncate <= 10);
2476
- }
2477
-
2478
- test "TextBufferView truncation - very small viewport" {
2479
- const pool = gp.initGlobalPool(std.testing.allocator);
2480
- defer gp.deinitGlobalPool();
2481
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2482
- defer link.deinitGlobalLinkPool();
2483
-
2484
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2485
- defer tb.deinit();
2486
-
2487
- var view = try TextBufferView.init(std.testing.allocator, tb);
2488
- defer view.deinit();
2489
-
2490
- try tb.setText("Hello World");
2491
-
2492
- view.setTruncate(true);
2493
- view.setWrapMode(.none);
2494
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 3, .height = 1 });
2495
-
2496
- const vlines = view.getVirtualLines();
2497
-
2498
- // With width=3, only room for "..." - should clear the line
2499
- try std.testing.expectEqual(@as(u32, 0), vlines[0].width_cols);
2500
- }
2501
-
2502
- test "TextBufferView truncation - verify ellipsis chunk injection" {
2503
- const pool = gp.initGlobalPool(std.testing.allocator);
2504
- defer gp.deinitGlobalPool();
2505
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2506
- defer link.deinitGlobalLinkPool();
2507
-
2508
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2509
- defer tb.deinit();
2510
-
2511
- var view = try TextBufferView.init(std.testing.allocator, tb);
2512
- defer view.deinit();
2513
-
2514
- try tb.setText("0123456789ABCDEFGHIJ");
2515
-
2516
- view.setTruncate(true);
2517
- view.setWrapMode(.none);
2518
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 10, .height = 1 });
2519
-
2520
- const vlines = view.getVirtualLines();
2521
-
2522
- try std.testing.expectEqual(@as(usize, 1), vlines.len);
2523
- try std.testing.expectEqual(@as(u32, 10), vlines[0].width_cols);
2524
-
2525
- // Should have 3 chunks: prefix, ellipsis, suffix
2526
- try std.testing.expectEqual(@as(usize, 3), vlines[0].chunks.items.len);
2527
-
2528
- // Verify the middle chunk is the ellipsis
2529
- const ellipsis_chunk = vlines[0].chunks.items[1];
2530
- try std.testing.expectEqual(@as(u32, 3), ellipsis_chunk.width);
2531
-
2532
- // Get the ellipsis text to verify it's "..."
2533
- const ellipsis_text = ellipsis_chunk.chunk.getBytes(tb.memRegistry());
2534
- try std.testing.expectEqualStrings("...", ellipsis_text);
2535
- }
2536
-
2537
- test "TextBufferView truncation - works with wrapping" {
2538
- const pool = gp.initGlobalPool(std.testing.allocator);
2539
- defer gp.deinitGlobalPool();
2540
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2541
- defer link.deinitGlobalLinkPool();
2542
-
2543
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2544
- defer tb.deinit();
2545
-
2546
- var view = try TextBufferView.init(std.testing.allocator, tb);
2547
- defer view.deinit();
2548
-
2549
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
2550
-
2551
- view.setTruncate(true);
2552
- view.setWrapMode(.char);
2553
- view.setWrapWidth(10);
2554
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 15, .height = 5 });
2555
-
2556
- const vlines = view.getVirtualLines();
2557
-
2558
- // With char wrap at 10, should wrap into multiple lines first
2559
- // Then truncation should apply to lines exceeding viewport width
2560
- try std.testing.expect(vlines.len >= 2);
2561
- }
2562
-
2563
- test "TextBufferView truncation - verify prefix and suffix content" {
2564
- const pool = gp.initGlobalPool(std.testing.allocator);
2565
- defer gp.deinitGlobalPool();
2566
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2567
- defer link.deinitGlobalLinkPool();
2568
-
2569
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2570
- defer tb.deinit();
2571
-
2572
- var view = try TextBufferView.init(std.testing.allocator, tb);
2573
- defer view.deinit();
2574
-
2575
- try tb.setText("0123456789ABCDEFGHIJ");
2576
-
2577
- view.setTruncate(true);
2578
- view.setWrapMode(.none);
2579
- view.setViewport(text_buffer_view.Viewport{ .x = 0, .y = 0, .width = 10, .height = 1 });
2580
-
2581
- const vlines = view.getVirtualLines();
2582
- const chunks = vlines[0].chunks.items;
2583
-
2584
- // Should have 3 chunks: prefix, ellipsis, suffix
2585
- try std.testing.expectEqual(@as(usize, 3), chunks.len);
2586
-
2587
- // Middle chunk (ellipsis)
2588
- const ellipsis_bytes = chunks[1].chunk.getBytes(tb.memRegistry());
2589
-
2590
- // Verify ellipsis is correct
2591
- try std.testing.expectEqualStrings("...", ellipsis_bytes);
2592
-
2593
- // Verify total width matches viewport
2594
- try std.testing.expectEqual(@as(u32, 10), vlines[0].width_cols);
2595
- }
2596
-
2597
- test "TextBufferView measureForDimensions - multiple lines with different widths" {
2598
- const pool = gp.initGlobalPool(std.testing.allocator);
2599
- defer gp.deinitGlobalPool();
2600
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2601
- defer link.deinitGlobalLinkPool();
2602
-
2603
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2604
- defer tb.deinit();
2605
-
2606
- var view = try TextBufferView.init(std.testing.allocator, tb);
2607
- defer view.deinit();
2608
-
2609
- try tb.setText("Short\nAVeryLongLineHere\nMedium");
2610
- view.setWrapMode(.char);
2611
-
2612
- const result = try view.measureForDimensions(10, 10);
2613
- // "Short" (1 line), "AVeryLongLineHere" (2 lines), "Medium" (1 line) = 4 lines
2614
- try std.testing.expectEqual(@as(u32, 4), result.line_count);
2615
- try std.testing.expectEqual(@as(u32, 10), result.width_cols_max);
2616
- }
2617
-
2618
- test "TextBufferView highlights - multiple highlights on wrapped line" {
2619
- const pool = gp.initGlobalPool(std.testing.allocator);
2620
- defer gp.deinitGlobalPool();
2621
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2622
- defer link.deinitGlobalLinkPool();
2623
-
2624
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2625
- defer tb.deinit();
2626
-
2627
- var view = try TextBufferView.init(std.testing.allocator, tb);
2628
- defer view.deinit();
2629
-
2630
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
2631
-
2632
- try tb.addHighlight(0, 2, 8, 1, 1, 0);
2633
- try tb.addHighlight(0, 12, 18, 2, 1, 0);
2634
- try tb.addHighlight(0, 22, 26, 3, 1, 0);
2635
-
2636
- view.setWrapMode(.char);
2637
- view.setWrapWidth(10);
2638
-
2639
- const vline_count = view.getVirtualLineCount();
2640
- try std.testing.expect(vline_count >= 3);
2641
-
2642
- for (0..vline_count) |i| {
2643
- const vline_info = view.getVirtualLineSpans(i);
2644
- try std.testing.expectEqual(@as(usize, 0), vline_info.source_line);
2645
- try std.testing.expectEqual(@as(u32, @intCast(i * 10)), vline_info.col_offset);
2646
- }
2647
- }
2648
-
2649
- test "TextBufferView highlights - with emojis and wrapping" {
2650
- const pool = gp.initGlobalPool(std.testing.allocator);
2651
- defer gp.deinitGlobalPool();
2652
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2653
- defer link.deinitGlobalLinkPool();
2654
-
2655
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2656
- defer tb.deinit();
2657
-
2658
- var view = try TextBufferView.init(std.testing.allocator, tb);
2659
- defer view.deinit();
2660
-
2661
- try tb.setText("AB🌟CD🎨EF🚀GH");
2662
-
2663
- try tb.addHighlight(0, 2, 8, 1, 1, 0);
2664
-
2665
- view.setWrapMode(.char);
2666
- view.setWrapWidth(6);
2667
-
2668
- const vline_count = view.getVirtualLineCount();
2669
- try std.testing.expect(vline_count >= 2);
2670
-
2671
- const vline0_info = view.getVirtualLineSpans(0);
2672
- const vline1_info = view.getVirtualLineSpans(1);
2673
-
2674
- try std.testing.expectEqual(@as(usize, 0), vline0_info.source_line);
2675
- try std.testing.expectEqual(@as(usize, 0), vline1_info.source_line);
2676
-
2677
- try std.testing.expectEqual(@as(u32, 0), vline0_info.col_offset);
2678
- try std.testing.expect(vline1_info.col_offset == 6);
2679
-
2680
- try std.testing.expect(vline0_info.spans.len > 0);
2681
- }
2682
-
2683
- test "TextBufferView highlights - with CJK characters and wrapping" {
2684
- const pool = gp.initGlobalPool(std.testing.allocator);
2685
- defer gp.deinitGlobalPool();
2686
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2687
- defer link.deinitGlobalLinkPool();
2688
-
2689
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2690
- defer tb.deinit();
2691
-
2692
- var view = try TextBufferView.init(std.testing.allocator, tb);
2693
- defer view.deinit();
2694
-
2695
- try tb.setText("AB测试CD文字EF");
2696
-
2697
- try tb.addHighlight(0, 2, 6, 1, 1, 0);
2698
-
2699
- view.setWrapMode(.char);
2700
- view.setWrapWidth(6);
2701
-
2702
- const vline_count = view.getVirtualLineCount();
2703
- try std.testing.expect(vline_count >= 2);
2704
-
2705
- for (0..vline_count) |i| {
2706
- const vline_info = view.getVirtualLineSpans(i);
2707
- try std.testing.expectEqual(@as(usize, 0), vline_info.source_line);
2708
-
2709
- if (i == 0) {
2710
- try std.testing.expectEqual(@as(u32, 0), vline_info.col_offset);
2711
- } else if (i == 1) {
2712
- try std.testing.expectEqual(@as(u32, 6), vline_info.col_offset);
2713
- }
2714
- }
2715
- }
2716
-
2717
- test "TextBufferView highlights - mixed ASCII and wide chars with wrapping" {
2718
- const pool = gp.initGlobalPool(std.testing.allocator);
2719
- defer gp.deinitGlobalPool();
2720
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2721
- defer link.deinitGlobalLinkPool();
2722
-
2723
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2724
- defer tb.deinit();
2725
-
2726
- var view = try TextBufferView.init(std.testing.allocator, tb);
2727
- defer view.deinit();
2728
-
2729
- try tb.setText("Hello🌟世界");
2730
-
2731
- try tb.addHighlight(0, 5, 11, 1, 1, 0);
2732
-
2733
- view.setWrapMode(.char);
2734
- view.setWrapWidth(7);
2735
-
2736
- const vline_count = view.getVirtualLineCount();
2737
- try std.testing.expect(vline_count >= 2);
2738
-
2739
- const vline0_info = view.getVirtualLineSpans(0);
2740
- const vline1_info = view.getVirtualLineSpans(1);
2741
-
2742
- try std.testing.expectEqual(@as(usize, 0), vline0_info.source_line);
2743
- try std.testing.expectEqual(@as(usize, 0), vline1_info.source_line);
2744
-
2745
- try std.testing.expectEqual(@as(u32, 0), vline0_info.col_offset);
2746
- try std.testing.expectEqual(@as(u32, 7), vline1_info.col_offset);
2747
-
2748
- try std.testing.expect(vline0_info.spans.len > 0);
2749
- try std.testing.expect(vline1_info.spans.len > 0);
2750
- }
2751
-
2752
- test "TextBufferView highlights - emoji at wrap boundary" {
2753
- const pool = gp.initGlobalPool(std.testing.allocator);
2754
- defer gp.deinitGlobalPool();
2755
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2756
- defer link.deinitGlobalLinkPool();
2757
-
2758
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2759
- defer tb.deinit();
2760
-
2761
- var view = try TextBufferView.init(std.testing.allocator, tb);
2762
- defer view.deinit();
2763
-
2764
- try tb.setText("ABCD🌟EFGH");
2765
-
2766
- try tb.addHighlight(0, 3, 7, 1, 1, 0);
2767
-
2768
- view.setWrapMode(.char);
2769
- view.setWrapWidth(5);
2770
-
2771
- const vline_count = view.getVirtualLineCount();
2772
- try std.testing.expect(vline_count >= 2);
2773
-
2774
- const vline0_info = view.getVirtualLineSpans(0);
2775
- const vline1_info = view.getVirtualLineSpans(1);
2776
-
2777
- try std.testing.expectEqual(@as(u32, 0), vline0_info.col_offset);
2778
- try std.testing.expect(vline1_info.col_offset >= 4);
2779
- }
2780
-
2781
- test "TextBufferView highlights - emojis without wrapping" {
2782
- const pool = gp.initGlobalPool(std.testing.allocator);
2783
- defer gp.deinitGlobalPool();
2784
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2785
- defer link.deinitGlobalLinkPool();
2786
-
2787
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2788
- defer tb.deinit();
2789
-
2790
- var view = try TextBufferView.init(std.testing.allocator, tb);
2791
- defer view.deinit();
2792
-
2793
- try tb.setText("AB🌟CD🎨EF");
2794
-
2795
- try tb.addHighlight(0, 2, 8, 1, 1, 0);
2796
-
2797
- const vline_count = view.getVirtualLineCount();
2798
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2799
-
2800
- const spans = tb.getLineSpans(0);
2801
- try std.testing.expect(spans.len > 0);
2802
-
2803
- const highlights = tb.getLineHighlights(0);
2804
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
2805
- try std.testing.expectEqual(@as(u32, 2), highlights[0].col_start);
2806
- try std.testing.expectEqual(@as(u32, 8), highlights[0].col_end);
2807
- }
2808
-
2809
- test "TextBufferView highlights - CJK without wrapping" {
2810
- const pool = gp.initGlobalPool(std.testing.allocator);
2811
- defer gp.deinitGlobalPool();
2812
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2813
- defer link.deinitGlobalLinkPool();
2814
-
2815
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2816
- defer tb.deinit();
2817
-
2818
- var view = try TextBufferView.init(std.testing.allocator, tb);
2819
- defer view.deinit();
2820
-
2821
- try tb.setText("AB测试CD");
2822
-
2823
- try tb.addHighlight(0, 2, 6, 1, 1, 0);
2824
-
2825
- const vline_count = view.getVirtualLineCount();
2826
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2827
-
2828
- const highlights = tb.getLineHighlights(0);
2829
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
2830
- try std.testing.expectEqual(@as(u32, 2), highlights[0].col_start);
2831
- try std.testing.expectEqual(@as(u32, 6), highlights[0].col_end);
2832
-
2833
- const spans = tb.getLineSpans(0);
2834
- try std.testing.expect(spans.len > 0);
2835
- }
2836
-
2837
- test "TextBufferView highlights - mixed width graphemes without wrapping" {
2838
- const pool = gp.initGlobalPool(std.testing.allocator);
2839
- defer gp.deinitGlobalPool();
2840
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2841
- defer link.deinitGlobalLinkPool();
2842
-
2843
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2844
- defer tb.deinit();
2845
-
2846
- var view = try TextBufferView.init(std.testing.allocator, tb);
2847
- defer view.deinit();
2848
-
2849
- try tb.setText("A🌟B测C试D");
2850
-
2851
- try tb.addHighlight(0, 1, 4, 1, 1, 0);
2852
- try tb.addHighlight(0, 4, 7, 2, 1, 0);
2853
-
2854
- const vline_count = view.getVirtualLineCount();
2855
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2856
-
2857
- const highlights = tb.getLineHighlights(0);
2858
- try std.testing.expectEqual(@as(usize, 2), highlights.len);
2859
- try std.testing.expectEqual(@as(u32, 1), highlights[0].col_start);
2860
- try std.testing.expectEqual(@as(u32, 4), highlights[0].col_end);
2861
- try std.testing.expectEqual(@as(u32, 4), highlights[1].col_start);
2862
- try std.testing.expectEqual(@as(u32, 7), highlights[1].col_end);
2863
-
2864
- const spans = tb.getLineSpans(0);
2865
- try std.testing.expect(spans.len > 0);
2866
- }
2867
-
2868
- test "TextBufferView highlights - emoji at start without wrapping" {
2869
- const pool = gp.initGlobalPool(std.testing.allocator);
2870
- defer gp.deinitGlobalPool();
2871
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2872
- defer link.deinitGlobalLinkPool();
2873
-
2874
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2875
- defer tb.deinit();
2876
-
2877
- var view = try TextBufferView.init(std.testing.allocator, tb);
2878
- defer view.deinit();
2879
-
2880
- try tb.setText("🌟ABCD");
2881
-
2882
- try tb.addHighlight(0, 0, 3, 1, 1, 0);
2883
-
2884
- const vline_count = view.getVirtualLineCount();
2885
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2886
-
2887
- const highlights = tb.getLineHighlights(0);
2888
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
2889
- try std.testing.expectEqual(@as(u32, 0), highlights[0].col_start);
2890
- try std.testing.expectEqual(@as(u32, 3), highlights[0].col_end);
2891
- }
2892
-
2893
- test "TextBufferView highlights - emoji at end without wrapping" {
2894
- const pool = gp.initGlobalPool(std.testing.allocator);
2895
- defer gp.deinitGlobalPool();
2896
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2897
- defer link.deinitGlobalLinkPool();
2898
-
2899
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2900
- defer tb.deinit();
2901
-
2902
- var view = try TextBufferView.init(std.testing.allocator, tb);
2903
- defer view.deinit();
2904
-
2905
- try tb.setText("ABCD🌟");
2906
-
2907
- try tb.addHighlight(0, 3, 6, 1, 1, 0);
2908
-
2909
- const vline_count = view.getVirtualLineCount();
2910
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2911
-
2912
- const highlights = tb.getLineHighlights(0);
2913
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
2914
- try std.testing.expectEqual(@as(u32, 3), highlights[0].col_start);
2915
- try std.testing.expectEqual(@as(u32, 6), highlights[0].col_end);
2916
- }
2917
-
2918
- test "TextBufferView highlights - consecutive emojis without wrapping" {
2919
- const pool = gp.initGlobalPool(std.testing.allocator);
2920
- defer gp.deinitGlobalPool();
2921
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2922
- defer link.deinitGlobalLinkPool();
2923
-
2924
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2925
- defer tb.deinit();
2926
-
2927
- var view = try TextBufferView.init(std.testing.allocator, tb);
2928
- defer view.deinit();
2929
-
2930
- try tb.setText("A🌟🎨🚀B");
2931
-
2932
- try tb.addHighlight(0, 1, 7, 1, 1, 0);
2933
-
2934
- const vline_count = view.getVirtualLineCount();
2935
- try std.testing.expectEqual(@as(u32, 1), vline_count);
2936
-
2937
- const highlights = tb.getLineHighlights(0);
2938
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
2939
- try std.testing.expectEqual(@as(u32, 1), highlights[0].col_start);
2940
- try std.testing.expectEqual(@as(u32, 7), highlights[0].col_end);
2941
- }
2942
-
2943
- test "TextBufferView accessor methods - getVirtualLines and getLines" {
2944
- const pool = gp.initGlobalPool(std.testing.allocator);
2945
- defer gp.deinitGlobalPool();
2946
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2947
- defer link.deinitGlobalLinkPool();
2948
-
2949
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2950
- defer tb.deinit();
2951
-
2952
- var view = try TextBufferView.init(std.testing.allocator, tb);
2953
- defer view.deinit();
2954
-
2955
- try tb.setText("Line 1\nLine 2");
2956
-
2957
- const virtual_lines = view.getVirtualLines();
2958
- try std.testing.expectEqual(@as(usize, 2), virtual_lines.len);
2959
-
2960
- try std.testing.expectEqual(@as(u32, 2), tb.lineCount());
2961
-
2962
- try std.testing.expect(virtual_lines[0].chunks.items.len > 0);
2963
- }
2964
-
2965
- test "TextBufferView accessor methods - with wrapping" {
2966
- const pool = gp.initGlobalPool(std.testing.allocator);
2967
- defer gp.deinitGlobalPool();
2968
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2969
- defer link.deinitGlobalLinkPool();
2970
-
2971
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2972
- defer tb.deinit();
2973
-
2974
- var view = try TextBufferView.init(std.testing.allocator, tb);
2975
- defer view.deinit();
2976
-
2977
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
2978
-
2979
- view.setWrapMode(.char);
2980
- view.setWrapWidth(10);
2981
-
2982
- const virtual_lines = view.getVirtualLines();
2983
- try std.testing.expectEqual(@as(usize, 2), virtual_lines.len);
2984
-
2985
- try std.testing.expectEqual(@as(u32, 1), tb.lineCount());
2986
- }
2987
-
2988
- test "TextBufferView virtual lines - match real lines when no wrap" {
2989
- const pool = gp.initGlobalPool(std.testing.allocator);
2990
- defer gp.deinitGlobalPool();
2991
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
2992
- defer link.deinitGlobalLinkPool();
2993
-
2994
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
2995
- defer tb.deinit();
2996
-
2997
- var view = try TextBufferView.init(std.testing.allocator, tb);
2998
- defer view.deinit();
2999
-
3000
- try tb.setText("Line 1\nLine 2\nLine 3");
3001
-
3002
- try std.testing.expectEqual(@as(u32, 3), view.getVirtualLineCount());
3003
- try std.testing.expectEqual(@as(u32, 3), tb.getLineCount());
3004
-
3005
- const line_info = view.getCachedLineInfo();
3006
- try std.testing.expectEqual(@as(usize, 3), line_info.line_start_cols.len);
3007
- try std.testing.expectEqual(@as(usize, 3), line_info.line_width_cols.len);
3008
- }
3009
-
3010
- test "TextBufferView virtual lines - updated when wrap width set" {
3011
- const pool = gp.initGlobalPool(std.testing.allocator);
3012
- defer gp.deinitGlobalPool();
3013
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3014
- defer link.deinitGlobalLinkPool();
3015
-
3016
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3017
- defer tb.deinit();
3018
-
3019
- var view = try TextBufferView.init(std.testing.allocator, tb);
3020
- defer view.deinit();
3021
-
3022
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3023
-
3024
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3025
-
3026
- view.setWrapMode(.char);
3027
- view.setWrapWidth(10);
3028
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
3029
- }
3030
-
3031
- test "TextBufferView virtual lines - reset to match real lines when wrap removed" {
3032
- const pool = gp.initGlobalPool(std.testing.allocator);
3033
- defer gp.deinitGlobalPool();
3034
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3035
- defer link.deinitGlobalLinkPool();
3036
-
3037
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3038
- defer tb.deinit();
3039
-
3040
- var view = try TextBufferView.init(std.testing.allocator, tb);
3041
- defer view.deinit();
3042
-
3043
- try tb.setText("ABCDEFGHIJKLMNOPQRST\nShort");
3044
-
3045
- view.setWrapMode(.char);
3046
- view.setWrapWidth(10);
3047
- try std.testing.expectEqual(@as(u32, 3), view.getVirtualLineCount());
3048
-
3049
- view.setWrapWidth(null);
3050
-
3051
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
3052
-
3053
- const line_info = view.getCachedLineInfo();
3054
- try std.testing.expectEqual(@as(usize, 2), line_info.line_start_cols.len);
3055
- try std.testing.expectEqual(@as(usize, 2), line_info.line_width_cols.len);
3056
- }
3057
-
3058
- test "TextBufferView virtual lines - multi-line text without wrap" {
3059
- const pool = gp.initGlobalPool(std.testing.allocator);
3060
- defer gp.deinitGlobalPool();
3061
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3062
- defer link.deinitGlobalLinkPool();
3063
-
3064
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3065
- defer tb.deinit();
3066
-
3067
- var view = try TextBufferView.init(std.testing.allocator, tb);
3068
- defer view.deinit();
3069
-
3070
- try tb.setText("First line\n\nThird line with more text\n");
3071
-
3072
- try std.testing.expectEqual(@as(u32, 4), view.getVirtualLineCount());
3073
-
3074
- const line_info = view.getCachedLineInfo();
3075
- try std.testing.expectEqual(@as(usize, 4), line_info.line_start_cols.len);
3076
- try std.testing.expectEqual(@as(usize, 4), line_info.line_width_cols.len);
3077
-
3078
- // Verify the line starts are monotonically non-decreasing (empty lines have same start)
3079
- try std.testing.expect(line_info.line_start_cols[0] == 0);
3080
- try std.testing.expect(line_info.line_start_cols[1] >= line_info.line_start_cols[0]);
3081
- try std.testing.expect(line_info.line_start_cols[2] >= line_info.line_start_cols[1]);
3082
- try std.testing.expect(line_info.line_start_cols[3] >= line_info.line_start_cols[2]);
3083
- }
3084
-
3085
- test "TextBufferView line info - line starts and widths consistency" {
3086
- const pool = gp.initGlobalPool(std.testing.allocator);
3087
- defer gp.deinitGlobalPool();
3088
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3089
- defer link.deinitGlobalLinkPool();
3090
-
3091
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3092
- defer tb.deinit();
3093
-
3094
- var view = try TextBufferView.init(std.testing.allocator, tb);
3095
- defer view.deinit();
3096
-
3097
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3098
-
3099
- view.setWrapMode(.char);
3100
- view.setWrapWidth(7);
3101
- const line_count = view.getVirtualLineCount();
3102
- const line_info = view.getCachedLineInfo();
3103
-
3104
- try std.testing.expectEqual(@as(usize, line_count), line_info.line_start_cols.len);
3105
- try std.testing.expectEqual(@as(usize, line_count), line_info.line_width_cols.len);
3106
-
3107
- for (line_info.line_width_cols, 0..) |width, i| {
3108
- if (i < line_info.line_width_cols.len - 1) {
3109
- try std.testing.expect(width <= 7);
3110
- }
3111
- }
3112
- }
3113
-
3114
- test "TextBufferView line info - line starts monotonically increasing" {
3115
- const pool = gp.initGlobalPool(std.testing.allocator);
3116
- defer gp.deinitGlobalPool();
3117
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3118
- defer link.deinitGlobalLinkPool();
3119
-
3120
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3121
- defer tb.deinit();
3122
-
3123
- var view = try TextBufferView.init(std.testing.allocator, tb);
3124
- defer view.deinit();
3125
-
3126
- var text_builder: std.ArrayListUnmanaged(u8) = .{};
3127
- defer text_builder.deinit(std.testing.allocator);
3128
-
3129
- var i: u32 = 0;
3130
- while (i < 99) : (i += 1) {
3131
- try text_builder.writer(std.testing.allocator).print("Line {}\n", .{i});
3132
- }
3133
- try text_builder.writer(std.testing.allocator).print("Line {}", .{i});
3134
-
3135
- try tb.setText(text_builder.items);
3136
-
3137
- const line_count = view.getVirtualLineCount();
3138
- try std.testing.expectEqual(@as(u32, 100), line_count);
3139
-
3140
- const line_info = view.getCachedLineInfo();
3141
- try std.testing.expectEqual(@as(u32, 0), line_info.line_start_cols[0]);
3142
-
3143
- var line_idx: u32 = 1;
3144
- while (line_idx < 100) : (line_idx += 1) {
3145
- try std.testing.expect(line_info.line_start_cols[line_idx] >= line_info.line_start_cols[line_idx - 1]);
3146
- }
3147
- }
3148
-
3149
- test "TextBufferView - highlights preserved after wrap width change" {
3150
- const pool = gp.initGlobalPool(std.testing.allocator);
3151
- defer gp.deinitGlobalPool();
3152
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3153
- defer link.deinitGlobalLinkPool();
3154
-
3155
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3156
- defer tb.deinit();
3157
-
3158
- var view = try TextBufferView.init(std.testing.allocator, tb);
3159
- defer view.deinit();
3160
-
3161
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3162
-
3163
- try tb.addHighlight(0, 0, 10, 1, 0, 0);
3164
-
3165
- view.setWrapMode(.char);
3166
- view.setWrapWidth(10);
3167
-
3168
- const highlights = tb.getLineHighlights(0);
3169
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
3170
- }
3171
-
3172
- test "TextBufferView - get highlights from non-existent line" {
3173
- const pool = gp.initGlobalPool(std.testing.allocator);
3174
- defer gp.deinitGlobalPool();
3175
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3176
- defer link.deinitGlobalLinkPool();
3177
-
3178
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3179
- defer tb.deinit();
3180
-
3181
- var view = try TextBufferView.init(std.testing.allocator, tb);
3182
- defer view.deinit();
3183
-
3184
- try tb.setText("Line 1");
3185
-
3186
- const highlights = tb.getLineHighlights(10);
3187
- try std.testing.expectEqual(@as(usize, 0), highlights.len);
3188
- }
3189
-
3190
- test "TextBufferView - char range highlights out of bounds" {
3191
- const pool = gp.initGlobalPool(std.testing.allocator);
3192
- defer gp.deinitGlobalPool();
3193
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3194
- defer link.deinitGlobalLinkPool();
3195
-
3196
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3197
- defer tb.deinit();
3198
-
3199
- var view = try TextBufferView.init(std.testing.allocator, tb);
3200
- defer view.deinit();
3201
-
3202
- try tb.setText("Hello");
3203
-
3204
- try tb.addHighlightByCharRange(3, 100, 1, 1, 0);
3205
-
3206
- const highlights = tb.getLineHighlights(0);
3207
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
3208
- try std.testing.expectEqual(@as(u32, 3), highlights[0].col_start);
3209
- }
3210
-
3211
- test "TextBufferView - char range highlights invalid range" {
3212
- const pool = gp.initGlobalPool(std.testing.allocator);
3213
- defer gp.deinitGlobalPool();
3214
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3215
- defer link.deinitGlobalLinkPool();
3216
-
3217
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3218
- defer tb.deinit();
3219
-
3220
- var view = try TextBufferView.init(std.testing.allocator, tb);
3221
- defer view.deinit();
3222
-
3223
- try tb.setText("Hello World");
3224
-
3225
- try tb.addHighlightByCharRange(10, 5, 1, 1, 0);
3226
-
3227
- const highlights = tb.getLineHighlights(0);
3228
- try std.testing.expectEqual(@as(usize, 0), highlights.len);
3229
- }
3230
-
3231
- test "TextBufferView - char range highlights exact line boundaries" {
3232
- const pool = gp.initGlobalPool(std.testing.allocator);
3233
- defer gp.deinitGlobalPool();
3234
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3235
- defer link.deinitGlobalLinkPool();
3236
-
3237
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3238
- defer tb.deinit();
3239
-
3240
- var view = try TextBufferView.init(std.testing.allocator, tb);
3241
- defer view.deinit();
3242
-
3243
- try tb.setText("AAAA\nBBBB\nCCCC");
3244
-
3245
- try tb.addHighlightByCharRange(0, 4, 1, 1, 0);
3246
-
3247
- const line0_highlights = tb.getLineHighlights(0);
3248
- try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
3249
- try std.testing.expectEqual(@as(u32, 0), line0_highlights[0].col_start);
3250
- try std.testing.expectEqual(@as(u32, 4), line0_highlights[0].col_end);
3251
-
3252
- const line1_highlights = tb.getLineHighlights(1);
3253
- try std.testing.expectEqual(@as(usize, 0), line1_highlights.len);
3254
- }
3255
-
3256
- test "TextBufferView - char range highlights unicode text" {
3257
- const pool = gp.initGlobalPool(std.testing.allocator);
3258
- defer gp.deinitGlobalPool();
3259
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3260
- defer link.deinitGlobalLinkPool();
3261
-
3262
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3263
- defer tb.deinit();
3264
-
3265
- var view = try TextBufferView.init(std.testing.allocator, tb);
3266
- defer view.deinit();
3267
-
3268
- try tb.setText("Hello 世界 🌟");
3269
-
3270
- const text_len = tb.getLength();
3271
- try tb.addHighlightByCharRange(0, text_len, 1, 1, 0);
3272
-
3273
- const highlights = tb.getLineHighlights(0);
3274
- try std.testing.expectEqual(@as(usize, 1), highlights.len);
3275
- }
3276
-
3277
- test "TextBufferView automatic updates - view reflects buffer changes immediately" {
3278
- const pool = gp.initGlobalPool(std.testing.allocator);
3279
- defer gp.deinitGlobalPool();
3280
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3281
- defer link.deinitGlobalLinkPool();
3282
-
3283
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3284
- defer tb.deinit();
3285
-
3286
- var view = try TextBufferView.init(std.testing.allocator, tb);
3287
- defer view.deinit();
3288
-
3289
- try tb.setText("Hello");
3290
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3291
-
3292
- var buffer: [100]u8 = undefined;
3293
- const len1 = view.getPlainTextIntoBuffer(&buffer);
3294
- try std.testing.expectEqualStrings("Hello", buffer[0..len1]);
3295
-
3296
- try tb.setText("Hello\nWorld");
3297
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
3298
-
3299
- const len2 = view.getPlainTextIntoBuffer(&buffer);
3300
- try std.testing.expectEqualStrings("Hello\nWorld", buffer[0..len2]);
3301
- }
3302
-
3303
- test "TextBufferView automatic updates - multiple views update independently" {
3304
- const pool = gp.initGlobalPool(std.testing.allocator);
3305
- defer gp.deinitGlobalPool();
3306
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3307
- defer link.deinitGlobalLinkPool();
3308
-
3309
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3310
- defer tb.deinit();
3311
-
3312
- var view1 = try TextBufferView.init(std.testing.allocator, tb);
3313
- defer view1.deinit();
3314
-
3315
- var view2 = try TextBufferView.init(std.testing.allocator, tb);
3316
- defer view2.deinit();
3317
-
3318
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3319
-
3320
- try std.testing.expectEqual(@as(u32, 1), view1.getVirtualLineCount());
3321
- try std.testing.expectEqual(@as(u32, 1), view2.getVirtualLineCount());
3322
-
3323
- view1.setWrapMode(.char);
3324
- view1.setWrapWidth(10);
3325
- view2.setWrapMode(.char);
3326
- view2.setWrapWidth(5);
3327
-
3328
- try std.testing.expectEqual(@as(u32, 2), view1.getVirtualLineCount());
3329
- try std.testing.expectEqual(@as(u32, 4), view2.getVirtualLineCount());
3330
-
3331
- try tb.setText("Short");
3332
-
3333
- try std.testing.expectEqual(@as(u32, 1), view1.getVirtualLineCount());
3334
- try std.testing.expectEqual(@as(u32, 1), view2.getVirtualLineCount());
3335
- }
3336
-
3337
- test "TextBufferView automatic updates - view destroyed doesn't affect others" {
3338
- const pool = gp.initGlobalPool(std.testing.allocator);
3339
- defer gp.deinitGlobalPool();
3340
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3341
- defer link.deinitGlobalLinkPool();
3342
-
3343
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3344
- defer tb.deinit();
3345
-
3346
- var view1 = try TextBufferView.init(std.testing.allocator, tb);
3347
- defer view1.deinit();
3348
-
3349
- var view2 = try TextBufferView.init(std.testing.allocator, tb);
3350
-
3351
- try tb.setText("Hello");
3352
- try std.testing.expectEqual(@as(u32, 1), view1.getVirtualLineCount());
3353
- try std.testing.expectEqual(@as(u32, 1), view2.getVirtualLineCount());
3354
-
3355
- view2.deinit();
3356
-
3357
- try tb.setText("Hello\nWorld");
3358
- try std.testing.expectEqual(@as(u32, 2), view1.getVirtualLineCount());
3359
- }
3360
-
3361
- test "TextBufferView automatic updates - with wrapping across buffer changes" {
3362
- const pool = gp.initGlobalPool(std.testing.allocator);
3363
- defer gp.deinitGlobalPool();
3364
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3365
- defer link.deinitGlobalLinkPool();
3366
-
3367
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3368
- defer tb.deinit();
3369
-
3370
- var view = try TextBufferView.init(std.testing.allocator, tb);
3371
- defer view.deinit();
3372
-
3373
- view.setWrapMode(.char);
3374
- view.setWrapWidth(10);
3375
-
3376
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3377
- try std.testing.expectEqual(@as(u32, 2), view.getVirtualLineCount());
3378
-
3379
- const info1 = view.getCachedLineInfo();
3380
- try std.testing.expectEqual(@as(usize, 2), info1.line_start_cols.len);
3381
-
3382
- try tb.setText("Short");
3383
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3384
-
3385
- const info2 = view.getCachedLineInfo();
3386
- try std.testing.expectEqual(@as(usize, 1), info2.line_start_cols.len);
3387
-
3388
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
3389
- const vline_count = view.getVirtualLineCount();
3390
- try std.testing.expect(vline_count >= 3);
3391
-
3392
- const info3 = view.getCachedLineInfo();
3393
- try std.testing.expect(info3.line_start_cols.len >= 3);
3394
- }
3395
-
3396
- test "TextBufferView automatic updates - reset clears content and marks views dirty" {
3397
- const pool = gp.initGlobalPool(std.testing.allocator);
3398
- defer gp.deinitGlobalPool();
3399
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3400
- defer link.deinitGlobalLinkPool();
3401
-
3402
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3403
- defer tb.deinit();
3404
-
3405
- var view = try TextBufferView.init(std.testing.allocator, tb);
3406
- defer view.deinit();
3407
-
3408
- try tb.setText("Hello World");
3409
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3410
-
3411
- tb.reset();
3412
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3413
-
3414
- try tb.setText("");
3415
- try std.testing.expectEqual(@as(u32, 1), view.getVirtualLineCount());
3416
-
3417
- var buffer: [100]u8 = undefined;
3418
- const len = view.getPlainTextIntoBuffer(&buffer);
3419
- try std.testing.expectEqual(@as(usize, 0), len);
3420
- }
3421
-
3422
- test "TextBufferView automatic updates - view updates work with selection" {
3423
- const pool = gp.initGlobalPool(std.testing.allocator);
3424
- defer gp.deinitGlobalPool();
3425
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3426
- defer link.deinitGlobalLinkPool();
3427
-
3428
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3429
- defer tb.deinit();
3430
-
3431
- var view = try TextBufferView.init(std.testing.allocator, tb);
3432
- defer view.deinit();
3433
-
3434
- try tb.setText("Hello World");
3435
- view.setSelection(0, 5, null, null);
3436
-
3437
- var buffer: [100]u8 = undefined;
3438
- var len = view.getSelectedTextIntoBuffer(&buffer);
3439
- try std.testing.expectEqualStrings("Hello", buffer[0..len]);
3440
-
3441
- try tb.setText("Hi");
3442
-
3443
- len = view.getPlainTextIntoBuffer(&buffer);
3444
- try std.testing.expectEqualStrings("Hi", buffer[0..len]);
3445
- }
3446
-
3447
- test "TextBufferView automatic updates - multiple views with different wrap settings" {
3448
- const pool = gp.initGlobalPool(std.testing.allocator);
3449
- defer gp.deinitGlobalPool();
3450
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3451
- defer link.deinitGlobalLinkPool();
3452
-
3453
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3454
- defer tb.deinit();
3455
-
3456
- var view_nowrap = try TextBufferView.init(std.testing.allocator, tb);
3457
- defer view_nowrap.deinit();
3458
-
3459
- var view_wrap10 = try TextBufferView.init(std.testing.allocator, tb);
3460
- defer view_wrap10.deinit();
3461
- view_wrap10.setWrapMode(.char);
3462
- view_wrap10.setWrapWidth(10);
3463
-
3464
- var view_wrap5 = try TextBufferView.init(std.testing.allocator, tb);
3465
- defer view_wrap5.deinit();
3466
- view_wrap5.setWrapMode(.char);
3467
- view_wrap5.setWrapWidth(5);
3468
-
3469
- try tb.setText("ABCDEFGHIJKLMNOPQRST");
3470
-
3471
- try std.testing.expectEqual(@as(u32, 1), view_nowrap.getVirtualLineCount());
3472
- try std.testing.expectEqual(@as(u32, 2), view_wrap10.getVirtualLineCount());
3473
- try std.testing.expectEqual(@as(u32, 4), view_wrap5.getVirtualLineCount());
3474
- try tb.setText("Short");
3475
-
3476
- try std.testing.expectEqual(@as(u32, 1), view_nowrap.getVirtualLineCount());
3477
- try std.testing.expectEqual(@as(u32, 1), view_wrap10.getVirtualLineCount());
3478
- try std.testing.expectEqual(@as(u32, 1), view_wrap5.getVirtualLineCount());
3479
-
3480
- try tb.setText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
3481
-
3482
- try std.testing.expectEqual(@as(u32, 1), view_nowrap.getVirtualLineCount());
3483
- try std.testing.expectEqual(@as(u32, 3), view_wrap10.getVirtualLineCount());
3484
- try std.testing.expectEqual(@as(u32, 6), view_wrap5.getVirtualLineCount());
3485
- }
3486
-
3487
- test "TextBufferView - tab indicator set and get" {
3488
- const pool = gp.initGlobalPool(std.testing.allocator);
3489
- defer gp.deinitGlobalPool();
3490
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3491
- defer link.deinitGlobalLinkPool();
3492
-
3493
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3494
- defer tb.deinit();
3495
-
3496
- var view = try TextBufferView.init(std.testing.allocator, tb);
3497
- defer view.deinit();
3498
-
3499
- try std.testing.expect(view.getTabIndicator() == null);
3500
- try std.testing.expect(view.getTabIndicatorColor() == null);
3501
-
3502
- view.setTabIndicator(@as(u32, '·'));
3503
- view.setTabIndicatorColor(RGBA{ 0.4, 0.4, 0.4, 1.0 });
3504
-
3505
- try std.testing.expectEqual(@as(u32, '·'), view.getTabIndicator().?);
3506
- try std.testing.expectEqual(@as(f32, 0.4), view.getTabIndicatorColor().?[0]);
3507
- }
3508
-
3509
- test "TextBufferView findVisualLineIndex - finds correct line for wrapped text" {
3510
- const pool = gp.initGlobalPool(std.testing.allocator);
3511
- defer gp.deinitGlobalPool();
3512
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3513
- defer link.deinitGlobalLinkPool();
3514
-
3515
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3516
- defer tb.deinit();
3517
-
3518
- var view = try TextBufferView.init(std.testing.allocator, tb);
3519
- defer view.deinit();
3520
-
3521
- // Same text as in the failing test - wraps into 7 virtual lines
3522
- try tb.setText("This is a very long line that will definitely wrap into multiple visual lines when the viewport is small");
3523
-
3524
- view.setWrapMode(.word);
3525
- view.setWrapWidth(20);
3526
-
3527
- // Test findVisualLineIndex for various logical columns
3528
- // Column 0 should be in visual line 0
3529
- const idx0 = view.findVisualLineIndex(0, 0);
3530
- try std.testing.expectEqual(@as(u32, 0), idx0);
3531
-
3532
- // Column 20 should be in visual line 1 (starts at col 20)
3533
- const idx20 = view.findVisualLineIndex(0, 20);
3534
- try std.testing.expectEqual(@as(u32, 1), idx20);
3535
-
3536
- // Column 35 should be in visual line 2 (starts at col 35)
3537
- const idx35 = view.findVisualLineIndex(0, 35);
3538
- try std.testing.expectEqual(@as(u32, 2), idx35);
3539
-
3540
- // Column 50 is the last column of visual line 2
3541
- const idx50 = view.findVisualLineIndex(0, 50);
3542
- try std.testing.expectEqual(@as(u32, 2), idx50);
3543
-
3544
- // Column 51 should be in visual line 3 (starts at col 51)
3545
- const idx51 = view.findVisualLineIndex(0, 51);
3546
- try std.testing.expectEqual(@as(u32, 3), idx51);
3547
- }
3548
-
3549
- test "TextBufferView word wrapping - chunk at exact wrap boundary" {
3550
- const pool = gp.initGlobalPool(std.testing.allocator);
3551
- defer gp.deinitGlobalPool();
3552
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3553
- defer link.deinitGlobalLinkPool();
3554
-
3555
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3556
- defer tb.deinit();
3557
-
3558
- var view = try TextBufferView.init(std.testing.allocator, tb);
3559
- defer view.deinit();
3560
-
3561
- const text = "hello world ddddddddd";
3562
- const mem_id = try tb.registerMemBuffer(text, false);
3563
-
3564
- const seg_mod = @import("../text-buffer-segment.zig");
3565
- const Segment = seg_mod.Segment;
3566
-
3567
- var segments: std.ArrayListUnmanaged(Segment) = .{};
3568
- defer segments.deinit(std.testing.allocator);
3569
-
3570
- try segments.append(std.testing.allocator, Segment{ .linestart = {} });
3571
-
3572
- const chunk1 = tb.createChunk(mem_id, 0, 17);
3573
- try segments.append(std.testing.allocator, Segment{ .text = chunk1 });
3574
-
3575
- const chunk2 = tb.createChunk(mem_id, 17, 21);
3576
- try segments.append(std.testing.allocator, Segment{ .text = chunk2 });
3577
-
3578
- try tb.rope().setSegments(segments.items);
3579
- view.virtual_lines_dirty = true;
3580
-
3581
- view.setWrapMode(.word);
3582
- view.setWrapWidth(17);
3583
-
3584
- const vlines = view.getVirtualLines();
3585
-
3586
- try std.testing.expectEqual(@as(usize, 2), vlines.len);
3587
- try std.testing.expectEqual(@as(u32, 12), vlines[0].width_cols);
3588
- try std.testing.expectEqual(@as(u32, 9), vlines[1].width_cols);
3589
- }
3590
-
3591
- test "TextBufferView word wrapping - does not split 'uses' across lines" {
3592
- const pool = gp.initGlobalPool(std.testing.allocator);
3593
- defer gp.deinitGlobalPool();
3594
- const link_pool = link.initGlobalLinkPool(std.testing.allocator);
3595
- defer link.deinitGlobalLinkPool();
3596
-
3597
- var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
3598
- defer tb.deinit();
3599
-
3600
- var view = try TextBufferView.init(std.testing.allocator, tb);
3601
- defer view.deinit();
3602
-
3603
- const text =
3604
- "So: the per‑repo config is the baseline; the -c flags are a “don’t depend on baseline” guard for commands where output consistency matters. " ++
3605
- "Revert uses checkout, which is less about output formatting and already respects the repo config, so it didn’t get the extra guard. " ++
3606
- "If you want stricter consistency, we can add -c core.autocrlf=false there too.";
3607
-
3608
- try tb.setText(text);
3609
- view.setWrapMode(.word);
3610
-
3611
- var split_found = false;
3612
-
3613
- var width: u32 = 100;
3614
- while (width >= 80) : (width -= 1) {
3615
- view.setWrapWidth(width);
3616
-
3617
- const vlines = view.getVirtualLines();
3618
- var i: usize = 0;
3619
- while (i + 1 < vlines.len) : (i += 1) {
3620
- var line_buf: [1024]u8 = undefined;
3621
- var next_line_buf: [1024]u8 = undefined;
3622
-
3623
- const line_len = tb.getTextRange(vlines[i].col_offset, vlines[i].col_offset + vlines[i].width_cols, &line_buf);
3624
- const next_line_len = tb.getTextRange(
3625
- vlines[i + 1].col_offset,
3626
- vlines[i + 1].col_offset + vlines[i + 1].width_cols,
3627
- &next_line_buf,
3628
- );
3629
-
3630
- const line = std.mem.trim(u8, line_buf[0..line_len], " \t");
3631
- const next_line = std.mem.trim(u8, next_line_buf[0..next_line_len], " \t");
3632
-
3633
- const split_u = std.mem.endsWith(u8, line, "Revert u") and std.mem.startsWith(u8, next_line, "ses checkout");
3634
- const split_us = std.mem.endsWith(u8, line, "Revert us") and std.mem.startsWith(u8, next_line, "es checkout");
3635
- const split_use = std.mem.endsWith(u8, line, "Revert use") and std.mem.startsWith(u8, next_line, "s checkout");
3636
-
3637
- if (split_u or split_us or split_use) {
3638
- split_found = true;
3639
- break;
3640
- }
3641
- }
3642
-
3643
- if (split_found or width == 80) {
3644
- break;
3645
- }
3646
- }
3647
-
3648
- try std.testing.expect(!split_found);
3649
- }