@fairyhunter13/opentui-core 0.1.90 → 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 (571) 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/README.md +2 -2
  21. package/Renderable.d.ts +334 -0
  22. package/animation/Timeline.d.ts +126 -0
  23. package/ansi.d.ts +13 -0
  24. package/buffer.d.ts +107 -0
  25. package/console.d.ts +143 -0
  26. package/edit-buffer.d.ts +98 -0
  27. package/editor-view.d.ts +73 -0
  28. package/index-e6ec7apq.js +18415 -0
  29. package/index-e6ec7apq.js.map +64 -0
  30. package/index-h066zmrb.js +12619 -0
  31. package/index-h066zmrb.js.map +43 -0
  32. package/index-ynzawt3n.js +113 -0
  33. package/index-ynzawt3n.js.map +10 -0
  34. package/index.d.ts +21 -0
  35. package/index.js +430 -0
  36. package/index.js.map +9 -0
  37. package/lib/KeyHandler.d.ts +61 -0
  38. package/lib/RGBA.d.ts +25 -0
  39. package/lib/ascii.font.d.ts +508 -0
  40. package/lib/border.d.ts +49 -0
  41. package/lib/bunfs.d.ts +7 -0
  42. package/lib/clipboard.d.ts +17 -0
  43. package/lib/clock.d.ts +15 -0
  44. package/lib/data-paths.d.ts +26 -0
  45. package/lib/debounce.d.ts +42 -0
  46. package/lib/detect-links.d.ts +6 -0
  47. package/lib/env.d.ts +42 -0
  48. package/lib/extmarks-history.d.ts +17 -0
  49. package/lib/extmarks.d.ts +89 -0
  50. package/lib/hast-styled-text.d.ts +17 -0
  51. package/lib/index.d.ts +21 -0
  52. package/lib/keymapping.d.ts +25 -0
  53. package/lib/objects-in-viewport.d.ts +24 -0
  54. package/lib/output.capture.d.ts +24 -0
  55. package/lib/parse.keypress-kitty.d.ts +2 -0
  56. package/lib/parse.keypress.d.ts +26 -0
  57. package/lib/parse.mouse.d.ts +30 -0
  58. package/lib/paste.d.ts +7 -0
  59. package/lib/queue.d.ts +15 -0
  60. package/lib/renderable.validations.d.ts +12 -0
  61. package/lib/scroll-acceleration.d.ts +43 -0
  62. package/lib/selection.d.ts +63 -0
  63. package/lib/singleton.d.ts +7 -0
  64. package/lib/stdin-parser.d.ts +76 -0
  65. package/lib/styled-text.d.ts +63 -0
  66. package/lib/terminal-capability-detection.d.ts +30 -0
  67. package/lib/terminal-palette.d.ts +50 -0
  68. package/lib/tree-sitter/assets/update.d.ts +11 -0
  69. package/lib/tree-sitter/client.d.ts +47 -0
  70. package/lib/tree-sitter/default-parsers.d.ts +2 -0
  71. package/lib/tree-sitter/download-utils.d.ts +21 -0
  72. package/lib/tree-sitter/index.d.ts +8 -0
  73. package/lib/tree-sitter/parser.worker.d.ts +1 -0
  74. package/lib/tree-sitter/parsers-config.d.ts +38 -0
  75. package/lib/tree-sitter/resolve-ft.d.ts +2 -0
  76. package/lib/tree-sitter/types.d.ts +81 -0
  77. package/lib/tree-sitter-styled-text.d.ts +14 -0
  78. package/lib/validate-dir-name.d.ts +1 -0
  79. package/lib/yoga.options.d.ts +32 -0
  80. package/package.json +51 -63
  81. package/parser.worker.js +869 -0
  82. package/parser.worker.js.map +12 -0
  83. package/plugins/core-slot.d.ts +72 -0
  84. package/plugins/registry.d.ts +38 -0
  85. package/plugins/types.d.ts +34 -0
  86. package/post/filters.d.ts +105 -0
  87. package/renderables/ASCIIFont.d.ts +52 -0
  88. package/renderables/Box.d.ts +72 -0
  89. package/renderables/Code.d.ts +78 -0
  90. package/renderables/Diff.d.ts +142 -0
  91. package/renderables/EditBufferRenderable.d.ts +162 -0
  92. package/renderables/FrameBuffer.d.ts +16 -0
  93. package/renderables/Input.d.ts +67 -0
  94. package/renderables/LineNumberRenderable.d.ts +74 -0
  95. package/renderables/Markdown.d.ts +173 -0
  96. package/renderables/ScrollBar.d.ts +77 -0
  97. package/renderables/ScrollBox.d.ts +124 -0
  98. package/renderables/Select.d.ts +115 -0
  99. package/renderables/Slider.d.ts +44 -0
  100. package/renderables/TabSelect.d.ts +96 -0
  101. package/renderables/Text.d.ts +36 -0
  102. package/renderables/TextBufferRenderable.d.ts +105 -0
  103. package/renderables/TextNode.d.ts +91 -0
  104. package/renderables/TextTable.d.ts +140 -0
  105. package/renderables/Textarea.d.ts +114 -0
  106. package/renderables/TimeToFirstDraw.d.ts +24 -0
  107. package/renderables/__tests__/renderable-test-utils.d.ts +12 -0
  108. package/renderables/composition/VRenderable.d.ts +16 -0
  109. package/renderables/composition/constructs.d.ts +35 -0
  110. package/renderables/composition/vnode.d.ts +46 -0
  111. package/renderables/index.d.ts +22 -0
  112. package/renderables/markdown-parser.d.ts +10 -0
  113. package/renderer.d.ts +388 -0
  114. package/runtime-plugin-support.d.ts +3 -0
  115. package/runtime-plugin-support.js +29 -0
  116. package/runtime-plugin-support.js.map +10 -0
  117. package/runtime-plugin.d.ts +11 -0
  118. package/runtime-plugin.js +16 -0
  119. package/runtime-plugin.js.map +9 -0
  120. package/syntax-style.d.ts +54 -0
  121. package/testing/manual-clock.d.ts +16 -0
  122. package/testing/mock-keys.d.ts +81 -0
  123. package/testing/mock-mouse.d.ts +38 -0
  124. package/testing/mock-tree-sitter-client.d.ts +23 -0
  125. package/testing/spy.d.ts +7 -0
  126. package/testing/test-recorder.d.ts +61 -0
  127. package/testing/test-renderer.d.ts +23 -0
  128. package/testing.d.ts +6 -0
  129. package/testing.js +675 -0
  130. package/testing.js.map +15 -0
  131. package/text-buffer-view.d.ts +42 -0
  132. package/text-buffer.d.ts +67 -0
  133. package/types.d.ts +131 -0
  134. package/utils.d.ts +14 -0
  135. package/zig-structs.d.ts +155 -0
  136. package/zig.d.ts +351 -0
  137. package/dev/keypress-debug-renderer.ts +0 -148
  138. package/dev/keypress-debug.ts +0 -43
  139. package/dev/print-env-vars.ts +0 -32
  140. package/dev/test-tmux-graphics-334.sh +0 -68
  141. package/dev/thai-debug-test.ts +0 -68
  142. package/docs/development.md +0 -141
  143. package/docs/env-vars.md +0 -140
  144. package/docs/getting-started.md +0 -353
  145. package/docs/renderables-vs-constructs.md +0 -159
  146. package/docs/tree-sitter.md +0 -311
  147. package/scripts/build.ts +0 -400
  148. package/scripts/publish.ts +0 -60
  149. package/src/3d/SpriteResourceManager.ts +0 -286
  150. package/src/3d/SpriteUtils.ts +0 -71
  151. package/src/3d/TextureUtils.ts +0 -196
  152. package/src/3d/ThreeRenderable.ts +0 -197
  153. package/src/3d/WGPURenderer.ts +0 -294
  154. package/src/3d/animation/ExplodingSpriteEffect.ts +0 -513
  155. package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +0 -429
  156. package/src/3d/animation/SpriteAnimator.ts +0 -633
  157. package/src/3d/animation/SpriteParticleGenerator.ts +0 -435
  158. package/src/3d/canvas.ts +0 -464
  159. package/src/3d/index.ts +0 -12
  160. package/src/3d/physics/PlanckPhysicsAdapter.ts +0 -72
  161. package/src/3d/physics/RapierPhysicsAdapter.ts +0 -66
  162. package/src/3d/physics/physics-interface.ts +0 -31
  163. package/src/3d/shaders/supersampling.wgsl +0 -201
  164. package/src/3d.ts +0 -3
  165. package/src/NativeSpanFeed.ts +0 -300
  166. package/src/Renderable.ts +0 -1698
  167. package/src/__snapshots__/buffer.test.ts.snap +0 -28
  168. package/src/animation/Timeline.test.ts +0 -2709
  169. package/src/animation/Timeline.ts +0 -598
  170. package/src/ansi.ts +0 -18
  171. package/src/benchmark/latest-all-bench-run.json +0 -707
  172. package/src/benchmark/latest-async-bench-run.json +0 -336
  173. package/src/benchmark/latest-default-bench-run.json +0 -657
  174. package/src/benchmark/latest-large-bench-run.json +0 -707
  175. package/src/benchmark/latest-quick-bench-run.json +0 -207
  176. package/src/benchmark/markdown-benchmark.ts +0 -1804
  177. package/src/benchmark/native-span-feed-async-benchmark.ts +0 -355
  178. package/src/benchmark/native-span-feed-benchmark.md +0 -56
  179. package/src/benchmark/native-span-feed-benchmark.ts +0 -596
  180. package/src/benchmark/native-span-feed-compare.ts +0 -280
  181. package/src/benchmark/renderer-benchmark.ts +0 -754
  182. package/src/benchmark/text-table-benchmark.ts +0 -947
  183. package/src/buffer.test.ts +0 -291
  184. package/src/buffer.ts +0 -519
  185. package/src/console.test.ts +0 -612
  186. package/src/console.ts +0 -1255
  187. package/src/edit-buffer.test.ts +0 -1769
  188. package/src/edit-buffer.ts +0 -411
  189. package/src/editor-view.test.ts +0 -1032
  190. package/src/editor-view.ts +0 -284
  191. package/src/examples/ascii-font-selection-demo.ts +0 -245
  192. package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
  193. package/src/examples/assets/concrete.png +0 -0
  194. package/src/examples/assets/crate.png +0 -0
  195. package/src/examples/assets/crate_emissive.png +0 -0
  196. package/src/examples/assets/forrest_background.png +0 -0
  197. package/src/examples/assets/hast-example.json +0 -1018
  198. package/src/examples/assets/heart.png +0 -0
  199. package/src/examples/assets/main_char_heavy_attack.png +0 -0
  200. package/src/examples/assets/main_char_idle.png +0 -0
  201. package/src/examples/assets/main_char_jump_end.png +0 -0
  202. package/src/examples/assets/main_char_jump_landing.png +0 -0
  203. package/src/examples/assets/main_char_jump_start.png +0 -0
  204. package/src/examples/assets/main_char_run_loop.png +0 -0
  205. package/src/examples/assets/roughness_map.jpg +0 -0
  206. package/src/examples/build.ts +0 -115
  207. package/src/examples/code-demo.ts +0 -584
  208. package/src/examples/console-demo.ts +0 -358
  209. package/src/examples/core-plugin-slots-demo.ts +0 -759
  210. package/src/examples/diff-demo.ts +0 -699
  211. package/src/examples/draggable-three-demo.ts +0 -259
  212. package/src/examples/editor-demo.ts +0 -322
  213. package/src/examples/extmarks-demo.ts +0 -204
  214. package/src/examples/focus-restore-demo.ts +0 -310
  215. package/src/examples/fonts.ts +0 -245
  216. package/src/examples/fractal-shader-demo.ts +0 -268
  217. package/src/examples/framebuffer-demo.ts +0 -674
  218. package/src/examples/full-unicode-demo.ts +0 -181
  219. package/src/examples/golden-star-demo.ts +0 -933
  220. package/src/examples/grayscale-buffer-demo.ts +0 -249
  221. package/src/examples/hast-syntax-highlighting-demo.ts +0 -129
  222. package/src/examples/index.ts +0 -925
  223. package/src/examples/input-demo.ts +0 -377
  224. package/src/examples/input-select-layout-demo.ts +0 -425
  225. package/src/examples/install.sh +0 -143
  226. package/src/examples/keypress-debug-demo.ts +0 -452
  227. package/src/examples/lib/HexList.ts +0 -122
  228. package/src/examples/lib/PaletteGrid.ts +0 -125
  229. package/src/examples/lib/standalone-keys.ts +0 -25
  230. package/src/examples/lib/tab-controller.ts +0 -243
  231. package/src/examples/lights-phong-demo.ts +0 -290
  232. package/src/examples/link-demo.ts +0 -220
  233. package/src/examples/live-state-demo.ts +0 -480
  234. package/src/examples/markdown-demo.ts +0 -620
  235. package/src/examples/mouse-interaction-demo.ts +0 -428
  236. package/src/examples/nested-zindex-demo.ts +0 -357
  237. package/src/examples/opacity-example.ts +0 -235
  238. package/src/examples/opentui-demo.ts +0 -1057
  239. package/src/examples/physx-planck-2d-demo.ts +0 -507
  240. package/src/examples/physx-rapier-2d-demo.ts +0 -526
  241. package/src/examples/relative-positioning-demo.ts +0 -323
  242. package/src/examples/scroll-example.ts +0 -214
  243. package/src/examples/scrollbox-mouse-test.ts +0 -112
  244. package/src/examples/scrollbox-overlay-hit-test.ts +0 -206
  245. package/src/examples/select-demo.ts +0 -237
  246. package/src/examples/shader-cube-demo.ts +0 -772
  247. package/src/examples/simple-layout-example.ts +0 -591
  248. package/src/examples/slider-demo.ts +0 -617
  249. package/src/examples/split-mode-demo.ts +0 -445
  250. package/src/examples/sprite-animation-demo.ts +0 -443
  251. package/src/examples/sprite-particle-generator-demo.ts +0 -486
  252. package/src/examples/static-sprite-demo.ts +0 -193
  253. package/src/examples/sticky-scroll-example.ts +0 -308
  254. package/src/examples/styled-text-demo.ts +0 -282
  255. package/src/examples/tab-select-demo.ts +0 -219
  256. package/src/examples/terminal-title.ts +0 -29
  257. package/src/examples/terminal.ts +0 -305
  258. package/src/examples/text-node-demo.ts +0 -416
  259. package/src/examples/text-selection-demo.ts +0 -377
  260. package/src/examples/text-table-demo.ts +0 -503
  261. package/src/examples/text-truncation-demo.ts +0 -481
  262. package/src/examples/text-wrap.ts +0 -757
  263. package/src/examples/texture-loading-demo.ts +0 -259
  264. package/src/examples/timeline-example.ts +0 -670
  265. package/src/examples/transparency-demo.ts +0 -241
  266. package/src/examples/vnode-composition-demo.ts +0 -404
  267. package/src/index.ts +0 -22
  268. package/src/lib/KeyHandler.integration.test.ts +0 -292
  269. package/src/lib/KeyHandler.stopPropagation.test.ts +0 -289
  270. package/src/lib/KeyHandler.test.ts +0 -662
  271. package/src/lib/KeyHandler.ts +0 -222
  272. package/src/lib/RGBA.test.ts +0 -984
  273. package/src/lib/RGBA.ts +0 -204
  274. package/src/lib/ascii.font.ts +0 -330
  275. package/src/lib/border.test.ts +0 -83
  276. package/src/lib/border.ts +0 -168
  277. package/src/lib/bunfs.test.ts +0 -27
  278. package/src/lib/bunfs.ts +0 -18
  279. package/src/lib/clipboard.test.ts +0 -41
  280. package/src/lib/clipboard.ts +0 -47
  281. package/src/lib/clock.ts +0 -31
  282. package/src/lib/data-paths.test.ts +0 -133
  283. package/src/lib/data-paths.ts +0 -109
  284. package/src/lib/debounce.ts +0 -106
  285. package/src/lib/detect-links.test.ts +0 -98
  286. package/src/lib/detect-links.ts +0 -56
  287. package/src/lib/env.test.ts +0 -228
  288. package/src/lib/env.ts +0 -209
  289. package/src/lib/extmarks-history.ts +0 -51
  290. package/src/lib/extmarks-multiwidth.test.ts +0 -322
  291. package/src/lib/extmarks.test.ts +0 -3457
  292. package/src/lib/extmarks.ts +0 -843
  293. package/src/lib/fonts/block.json +0 -405
  294. package/src/lib/fonts/grid.json +0 -265
  295. package/src/lib/fonts/huge.json +0 -741
  296. package/src/lib/fonts/pallet.json +0 -314
  297. package/src/lib/fonts/shade.json +0 -591
  298. package/src/lib/fonts/slick.json +0 -321
  299. package/src/lib/fonts/tiny.json +0 -69
  300. package/src/lib/hast-styled-text.ts +0 -59
  301. package/src/lib/index.ts +0 -21
  302. package/src/lib/keymapping.test.ts +0 -280
  303. package/src/lib/keymapping.ts +0 -87
  304. package/src/lib/objects-in-viewport.test.ts +0 -787
  305. package/src/lib/objects-in-viewport.ts +0 -153
  306. package/src/lib/output.capture.ts +0 -58
  307. package/src/lib/parse.keypress-kitty.protocol.test.ts +0 -340
  308. package/src/lib/parse.keypress-kitty.test.ts +0 -663
  309. package/src/lib/parse.keypress-kitty.ts +0 -439
  310. package/src/lib/parse.keypress.test.ts +0 -1849
  311. package/src/lib/parse.keypress.ts +0 -397
  312. package/src/lib/parse.mouse.test.ts +0 -552
  313. package/src/lib/parse.mouse.ts +0 -232
  314. package/src/lib/paste.ts +0 -16
  315. package/src/lib/queue.ts +0 -65
  316. package/src/lib/renderable.validations.test.ts +0 -87
  317. package/src/lib/renderable.validations.ts +0 -83
  318. package/src/lib/scroll-acceleration.ts +0 -98
  319. package/src/lib/selection.ts +0 -240
  320. package/src/lib/singleton.ts +0 -28
  321. package/src/lib/stdin-parser.test.ts +0 -1676
  322. package/src/lib/stdin-parser.ts +0 -1248
  323. package/src/lib/styled-text.ts +0 -178
  324. package/src/lib/terminal-capability-detection.test.ts +0 -202
  325. package/src/lib/terminal-capability-detection.ts +0 -79
  326. package/src/lib/terminal-palette.test.ts +0 -878
  327. package/src/lib/terminal-palette.ts +0 -383
  328. package/src/lib/tree-sitter/assets/README.md +0 -118
  329. package/src/lib/tree-sitter/assets/update.ts +0 -331
  330. package/src/lib/tree-sitter/assets.d.ts +0 -9
  331. package/src/lib/tree-sitter/cache.test.ts +0 -270
  332. package/src/lib/tree-sitter/client.test.ts +0 -1061
  333. package/src/lib/tree-sitter/client.ts +0 -615
  334. package/src/lib/tree-sitter/default-parsers.ts +0 -80
  335. package/src/lib/tree-sitter/download-utils.ts +0 -148
  336. package/src/lib/tree-sitter/index.ts +0 -28
  337. package/src/lib/tree-sitter/parser.worker.ts +0 -1001
  338. package/src/lib/tree-sitter/parsers-config.ts +0 -75
  339. package/src/lib/tree-sitter/resolve-ft.ts +0 -62
  340. package/src/lib/tree-sitter/types.ts +0 -81
  341. package/src/lib/tree-sitter-styled-text.test.ts +0 -1253
  342. package/src/lib/tree-sitter-styled-text.ts +0 -306
  343. package/src/lib/validate-dir-name.ts +0 -55
  344. package/src/lib/yoga.options.test.ts +0 -628
  345. package/src/lib/yoga.options.ts +0 -346
  346. package/src/plugins/core-slot.ts +0 -579
  347. package/src/plugins/registry.ts +0 -377
  348. package/src/plugins/types.ts +0 -46
  349. package/src/post/filters.ts +0 -888
  350. package/src/renderables/ASCIIFont.ts +0 -219
  351. package/src/renderables/Box.test.ts +0 -160
  352. package/src/renderables/Box.ts +0 -295
  353. package/src/renderables/Code.test.ts +0 -2062
  354. package/src/renderables/Code.ts +0 -357
  355. package/src/renderables/Diff.regression.test.ts +0 -226
  356. package/src/renderables/Diff.test.ts +0 -3027
  357. package/src/renderables/Diff.ts +0 -1209
  358. package/src/renderables/EditBufferRenderable.ts +0 -764
  359. package/src/renderables/FrameBuffer.ts +0 -47
  360. package/src/renderables/Input.test.ts +0 -1228
  361. package/src/renderables/Input.ts +0 -245
  362. package/src/renderables/LineNumberRenderable.ts +0 -675
  363. package/src/renderables/Markdown.ts +0 -1106
  364. package/src/renderables/ScrollBar.ts +0 -422
  365. package/src/renderables/ScrollBox.ts +0 -883
  366. package/src/renderables/Select.test.ts +0 -1010
  367. package/src/renderables/Select.ts +0 -523
  368. package/src/renderables/Slider.test.ts +0 -456
  369. package/src/renderables/Slider.ts +0 -347
  370. package/src/renderables/TabSelect.test.ts +0 -197
  371. package/src/renderables/TabSelect.ts +0 -455
  372. package/src/renderables/Text.selection-buffer.test.ts +0 -123
  373. package/src/renderables/Text.test.ts +0 -2660
  374. package/src/renderables/Text.ts +0 -147
  375. package/src/renderables/TextBufferRenderable.ts +0 -518
  376. package/src/renderables/TextNode.test.ts +0 -1058
  377. package/src/renderables/TextNode.ts +0 -325
  378. package/src/renderables/TextTable.test.ts +0 -1421
  379. package/src/renderables/TextTable.ts +0 -1344
  380. package/src/renderables/Textarea.ts +0 -732
  381. package/src/renderables/TimeToFirstDraw.ts +0 -89
  382. package/src/renderables/__snapshots__/Code.test.ts.snap +0 -13
  383. package/src/renderables/__snapshots__/Diff.test.ts.snap +0 -785
  384. package/src/renderables/__snapshots__/Text.test.ts.snap +0 -421
  385. package/src/renderables/__snapshots__/TextTable.test.ts.snap +0 -215
  386. package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +0 -144
  387. package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +0 -816
  388. package/src/renderables/__tests__/LineNumberRenderable.test.ts +0 -1787
  389. package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +0 -85
  390. package/src/renderables/__tests__/Markdown.test.ts +0 -2287
  391. package/src/renderables/__tests__/MultiRenderable.selection.test.ts +0 -87
  392. package/src/renderables/__tests__/Textarea.buffer.test.ts +0 -682
  393. package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +0 -675
  394. package/src/renderables/__tests__/Textarea.editing.test.ts +0 -2041
  395. package/src/renderables/__tests__/Textarea.error-handling.test.ts +0 -35
  396. package/src/renderables/__tests__/Textarea.events.test.ts +0 -738
  397. package/src/renderables/__tests__/Textarea.highlights.test.ts +0 -590
  398. package/src/renderables/__tests__/Textarea.keybinding.test.ts +0 -3149
  399. package/src/renderables/__tests__/Textarea.paste.test.ts +0 -357
  400. package/src/renderables/__tests__/Textarea.rendering.test.ts +0 -1864
  401. package/src/renderables/__tests__/Textarea.scroll.test.ts +0 -733
  402. package/src/renderables/__tests__/Textarea.selection.test.ts +0 -1590
  403. package/src/renderables/__tests__/Textarea.stress.test.ts +0 -670
  404. package/src/renderables/__tests__/Textarea.undo-redo.test.ts +0 -383
  405. package/src/renderables/__tests__/Textarea.visual-lines.test.ts +0 -310
  406. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +0 -221
  407. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +0 -89
  408. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +0 -457
  409. package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +0 -158
  410. package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +0 -387
  411. package/src/renderables/__tests__/markdown-parser.test.ts +0 -217
  412. package/src/renderables/__tests__/renderable-test-utils.ts +0 -60
  413. package/src/renderables/composition/README.md +0 -8
  414. package/src/renderables/composition/VRenderable.ts +0 -32
  415. package/src/renderables/composition/constructs.ts +0 -127
  416. package/src/renderables/composition/vnode.ts +0 -289
  417. package/src/renderables/index.ts +0 -22
  418. package/src/renderables/markdown-parser.ts +0 -66
  419. package/src/renderer.ts +0 -2363
  420. package/src/runtime-plugin-support.ts +0 -39
  421. package/src/runtime-plugin.ts +0 -144
  422. package/src/syntax-style.test.ts +0 -841
  423. package/src/syntax-style.ts +0 -264
  424. package/src/testing/README.md +0 -210
  425. package/src/testing/capture-spans.test.ts +0 -194
  426. package/src/testing/integration.test.ts +0 -276
  427. package/src/testing/manual-clock.ts +0 -106
  428. package/src/testing/mock-keys.test.ts +0 -1356
  429. package/src/testing/mock-keys.ts +0 -449
  430. package/src/testing/mock-mouse.test.ts +0 -218
  431. package/src/testing/mock-mouse.ts +0 -247
  432. package/src/testing/mock-tree-sitter-client.ts +0 -73
  433. package/src/testing/spy.ts +0 -13
  434. package/src/testing/test-recorder.test.ts +0 -415
  435. package/src/testing/test-recorder.ts +0 -145
  436. package/src/testing/test-renderer.ts +0 -116
  437. package/src/testing.ts +0 -7
  438. package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +0 -481
  439. package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +0 -19
  440. package/src/tests/__snapshots__/scrollbox.test.ts.snap +0 -29
  441. package/src/tests/absolute-positioning.snapshot.test.ts +0 -638
  442. package/src/tests/allocator-stats.test.ts +0 -38
  443. package/src/tests/destroy-during-render.test.ts +0 -200
  444. package/src/tests/hover-cursor.test.ts +0 -98
  445. package/src/tests/native-span-feed-async.test.ts +0 -173
  446. package/src/tests/native-span-feed-close.test.ts +0 -120
  447. package/src/tests/native-span-feed-coverage.test.ts +0 -227
  448. package/src/tests/native-span-feed-edge-cases.test.ts +0 -352
  449. package/src/tests/native-span-feed-use-after-free.test.ts +0 -45
  450. package/src/tests/opacity.test.ts +0 -123
  451. package/src/tests/renderable.snapshot.test.ts +0 -524
  452. package/src/tests/renderable.test.ts +0 -1281
  453. package/src/tests/renderer.console-startup.test.ts +0 -65
  454. package/src/tests/renderer.control.test.ts +0 -364
  455. package/src/tests/renderer.core-slot-binding.test.ts +0 -952
  456. package/src/tests/renderer.cursor.test.ts +0 -26
  457. package/src/tests/renderer.destroy-during-render.test.ts +0 -110
  458. package/src/tests/renderer.focus-restore.test.ts +0 -228
  459. package/src/tests/renderer.focus.test.ts +0 -251
  460. package/src/tests/renderer.idle.test.ts +0 -219
  461. package/src/tests/renderer.input.test.ts +0 -2145
  462. package/src/tests/renderer.kitty-flags.test.ts +0 -195
  463. package/src/tests/renderer.mouse.test.ts +0 -1269
  464. package/src/tests/renderer.palette.test.ts +0 -629
  465. package/src/tests/renderer.selection.test.ts +0 -49
  466. package/src/tests/renderer.slot-registry.test.ts +0 -649
  467. package/src/tests/renderer.useMouse.test.ts +0 -50
  468. package/src/tests/runtime-plugin-support.fixture.ts +0 -11
  469. package/src/tests/runtime-plugin-support.test.ts +0 -28
  470. package/src/tests/runtime-plugin.fixture.ts +0 -40
  471. package/src/tests/runtime-plugin.test.ts +0 -190
  472. package/src/tests/scrollbox-culling-bug.test.ts +0 -114
  473. package/src/tests/scrollbox-hitgrid-resize.test.ts +0 -136
  474. package/src/tests/scrollbox-hitgrid.test.ts +0 -909
  475. package/src/tests/scrollbox.test.ts +0 -1530
  476. package/src/tests/wrap-resize-perf.test.ts +0 -229
  477. package/src/tests/yoga-setters.test.ts +0 -921
  478. package/src/text-buffer-view.test.ts +0 -705
  479. package/src/text-buffer-view.ts +0 -189
  480. package/src/text-buffer.test.ts +0 -347
  481. package/src/text-buffer.ts +0 -250
  482. package/src/types.ts +0 -152
  483. package/src/utils.ts +0 -88
  484. package/src/zig/ansi.zig +0 -268
  485. package/src/zig/bench/README.md +0 -50
  486. package/src/zig/bench/buffer-draw-text-buffer_bench.zig +0 -887
  487. package/src/zig/bench/edit-buffer_bench.zig +0 -476
  488. package/src/zig/bench/native-span-feed_bench.zig +0 -100
  489. package/src/zig/bench/rope-markers_bench.zig +0 -713
  490. package/src/zig/bench/rope_bench.zig +0 -514
  491. package/src/zig/bench/styled-text_bench.zig +0 -470
  492. package/src/zig/bench/text-buffer-coords_bench.zig +0 -362
  493. package/src/zig/bench/text-buffer-view_bench.zig +0 -459
  494. package/src/zig/bench/text-chunk-graphemes_bench.zig +0 -273
  495. package/src/zig/bench/utf8_bench.zig +0 -799
  496. package/src/zig/bench-utils.zig +0 -431
  497. package/src/zig/bench.zig +0 -217
  498. package/src/zig/buffer.zig +0 -2223
  499. package/src/zig/build.zig +0 -289
  500. package/src/zig/build.zig.zon +0 -16
  501. package/src/zig/edit-buffer.zig +0 -825
  502. package/src/zig/editor-view.zig +0 -802
  503. package/src/zig/event-bus.zig +0 -13
  504. package/src/zig/event-emitter.zig +0 -65
  505. package/src/zig/file-logger.zig +0 -92
  506. package/src/zig/grapheme.zig +0 -599
  507. package/src/zig/lib.zig +0 -1834
  508. package/src/zig/link.zig +0 -333
  509. package/src/zig/logger.zig +0 -43
  510. package/src/zig/mem-registry.zig +0 -125
  511. package/src/zig/native-span-feed-bench-lib.zig +0 -7
  512. package/src/zig/native-span-feed.zig +0 -708
  513. package/src/zig/renderer.zig +0 -1386
  514. package/src/zig/rope.zig +0 -1220
  515. package/src/zig/syntax-style.zig +0 -161
  516. package/src/zig/terminal.zig +0 -975
  517. package/src/zig/test.zig +0 -70
  518. package/src/zig/tests/README.md +0 -18
  519. package/src/zig/tests/buffer_test.zig +0 -2526
  520. package/src/zig/tests/edit-buffer-history_test.zig +0 -271
  521. package/src/zig/tests/edit-buffer_test.zig +0 -1689
  522. package/src/zig/tests/editor-view_test.zig +0 -3299
  523. package/src/zig/tests/event-emitter_test.zig +0 -249
  524. package/src/zig/tests/grapheme_test.zig +0 -1304
  525. package/src/zig/tests/link_test.zig +0 -190
  526. package/src/zig/tests/mem-registry_test.zig +0 -473
  527. package/src/zig/tests/memory_leak_regression_test.zig +0 -159
  528. package/src/zig/tests/native-span-feed_test.zig +0 -1264
  529. package/src/zig/tests/renderer_test.zig +0 -1010
  530. package/src/zig/tests/rope-nested_test.zig +0 -712
  531. package/src/zig/tests/rope_fuzz_test.zig +0 -238
  532. package/src/zig/tests/rope_test.zig +0 -2362
  533. package/src/zig/tests/segment-merge.test.zig +0 -148
  534. package/src/zig/tests/syntax-style_test.zig +0 -557
  535. package/src/zig/tests/terminal_test.zig +0 -719
  536. package/src/zig/tests/text-buffer-drawing_test.zig +0 -3237
  537. package/src/zig/tests/text-buffer-highlights_test.zig +0 -666
  538. package/src/zig/tests/text-buffer-iterators_test.zig +0 -776
  539. package/src/zig/tests/text-buffer-segment_test.zig +0 -320
  540. package/src/zig/tests/text-buffer-selection_test.zig +0 -1035
  541. package/src/zig/tests/text-buffer-selection_viewport_test.zig +0 -358
  542. package/src/zig/tests/text-buffer-view_test.zig +0 -3649
  543. package/src/zig/tests/text-buffer_test.zig +0 -2191
  544. package/src/zig/tests/unicode-width-map.zon +0 -3909
  545. package/src/zig/tests/utf8_no_zwj_test.zig +0 -260
  546. package/src/zig/tests/utf8_test.zig +0 -4057
  547. package/src/zig/tests/utf8_wcwidth_cursor_test.zig +0 -267
  548. package/src/zig/tests/utf8_wcwidth_test.zig +0 -357
  549. package/src/zig/tests/word-wrap-editing_test.zig +0 -498
  550. package/src/zig/tests/wrap-cache-perf_test.zig +0 -113
  551. package/src/zig/text-buffer-iterators.zig +0 -499
  552. package/src/zig/text-buffer-segment.zig +0 -404
  553. package/src/zig/text-buffer-view.zig +0 -1371
  554. package/src/zig/text-buffer.zig +0 -1180
  555. package/src/zig/utf8.zig +0 -1948
  556. package/src/zig/utils.zig +0 -9
  557. package/src/zig-structs.ts +0 -261
  558. package/src/zig.ts +0 -3843
  559. package/tsconfig.build.json +0 -22
  560. package/tsconfig.json +0 -28
  561. /package/{src/lib/tree-sitter/assets → assets}/javascript/highlights.scm +0 -0
  562. /package/{src/lib/tree-sitter/assets → assets}/javascript/tree-sitter-javascript.wasm +0 -0
  563. /package/{src/lib/tree-sitter/assets → assets}/markdown/highlights.scm +0 -0
  564. /package/{src/lib/tree-sitter/assets → assets}/markdown/injections.scm +0 -0
  565. /package/{src/lib/tree-sitter/assets → assets}/markdown/tree-sitter-markdown.wasm +0 -0
  566. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/highlights.scm +0 -0
  567. /package/{src/lib/tree-sitter/assets → assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
  568. /package/{src/lib/tree-sitter/assets → assets}/typescript/highlights.scm +0 -0
  569. /package/{src/lib/tree-sitter/assets → assets}/typescript/tree-sitter-typescript.wasm +0 -0
  570. /package/{src/lib/tree-sitter/assets → assets}/zig/highlights.scm +0 -0
  571. /package/{src/lib/tree-sitter/assets → assets}/zig/tree-sitter-zig.wasm +0 -0
@@ -1,1371 +0,0 @@
1
- const std = @import("std");
2
- const Allocator = std.mem.Allocator;
3
- const tb = @import("text-buffer.zig");
4
- const seg_mod = @import("text-buffer-segment.zig");
5
- const iter_mod = @import("text-buffer-iterators.zig");
6
- const gp = @import("grapheme.zig");
7
- const utf8 = @import("utf8.zig");
8
-
9
- const logger = @import("logger.zig");
10
-
11
- const UnifiedTextBuffer = tb.UnifiedTextBuffer;
12
- const RGBA = tb.RGBA;
13
- const TextSelection = tb.TextSelection;
14
- pub const WrapMode = tb.WrapMode;
15
- const TextChunk = seg_mod.TextChunk;
16
- const StyleSpan = tb.StyleSpan;
17
- const GraphemeInfo = seg_mod.GraphemeInfo;
18
-
19
- pub const TextBufferViewError = error{
20
- OutOfMemory,
21
- };
22
-
23
- /// Viewport defines a rectangular window into the virtual line space
24
- pub const Viewport = struct {
25
- x: u32,
26
- y: u32,
27
- width: u32,
28
- height: u32,
29
- };
30
-
31
- pub const LineInfo = struct {
32
- line_start_cols: []const u32,
33
- line_width_cols: []const u32,
34
- line_sources: []const u32,
35
- line_wraps: []const u32,
36
- line_width_cols_max: u32,
37
- };
38
-
39
- pub const WrapInfo = struct {
40
- line_first_vline: []const u32,
41
- line_vline_counts: []const u32,
42
- };
43
-
44
- /// Output structure for virtual line calculation
45
- pub const VirtualLineOutput = struct {
46
- virtual_lines: *std.ArrayListUnmanaged(VirtualLine),
47
- cached_line_starts: *std.ArrayListUnmanaged(u32),
48
- cached_line_widths: *std.ArrayListUnmanaged(u32),
49
- cached_line_sources: *std.ArrayListUnmanaged(u32),
50
- cached_line_wrap_indices: *std.ArrayListUnmanaged(u32),
51
- cached_line_first_vline: *std.ArrayListUnmanaged(u32),
52
- cached_line_vline_counts: *std.ArrayListUnmanaged(u32),
53
- };
54
-
55
- /// Result from measuring dimensions without modifying cache
56
- pub const MeasureResult = struct {
57
- line_count: u32,
58
- width_cols_max: u32,
59
- };
60
-
61
- pub const VirtualLineSpanInfo = struct {
62
- spans: []const StyleSpan,
63
- source_line: usize,
64
- col_offset: u32,
65
- };
66
-
67
- pub const VirtualChunk = struct {
68
- grapheme_start: u32,
69
- width: u32,
70
- // Direct reference to source chunk for rendering
71
- chunk: *const TextChunk,
72
- };
73
-
74
- pub const VirtualLine = struct {
75
- chunks: std.ArrayListUnmanaged(VirtualChunk),
76
- width_cols: u32,
77
- col_offset: u32,
78
- source_line: usize,
79
- source_col_offset: u32,
80
- is_truncated: bool,
81
- ellipsis_pos: u32,
82
- truncation_suffix_start: u32,
83
-
84
- pub fn init() VirtualLine {
85
- return .{
86
- .chunks = .{},
87
- .width_cols = 0,
88
- .col_offset = 0,
89
- .source_line = 0,
90
- .source_col_offset = 0,
91
- .is_truncated = false,
92
- .ellipsis_pos = 0,
93
- .truncation_suffix_start = 0,
94
- };
95
- }
96
-
97
- pub fn deinit(self: *VirtualLine, allocator: Allocator) void {
98
- self.chunks.deinit(allocator);
99
- }
100
- };
101
-
102
- pub const LocalSelection = struct {
103
- anchorX: i32,
104
- anchorY: i32,
105
- focusX: i32,
106
- focusY: i32,
107
- isActive: bool,
108
- };
109
-
110
- pub const TextBufferView = UnifiedTextBufferView;
111
-
112
- pub const UnifiedTextBufferView = struct {
113
- const Self = @This();
114
-
115
- text_buffer: *UnifiedTextBuffer,
116
- original_text_buffer: *UnifiedTextBuffer,
117
- view_id: u32,
118
- selection: ?TextSelection,
119
- selection_anchor_offset: ?u32,
120
- viewport: ?Viewport,
121
- wrap_width: ?u32,
122
- wrap_mode: WrapMode,
123
- virtual_lines: std.ArrayListUnmanaged(VirtualLine),
124
- virtual_lines_dirty: bool,
125
- cached_line_starts: std.ArrayListUnmanaged(u32),
126
- cached_line_widths: std.ArrayListUnmanaged(u32),
127
- cached_line_sources: std.ArrayListUnmanaged(u32),
128
- cached_line_wrap_indices: std.ArrayListUnmanaged(u32),
129
- cached_line_first_vline: std.ArrayListUnmanaged(u32),
130
- cached_line_vline_counts: std.ArrayListUnmanaged(u32),
131
- global_allocator: Allocator,
132
- virtual_lines_arena: *std.heap.ArenaAllocator,
133
-
134
- /// Persistent arena for measureForDimensions. Each call resets it with
135
- /// retain_capacity to avoid mmap/munmap churn during streaming.
136
- measure_arena: std.heap.ArenaAllocator,
137
- tab_indicator: ?u32,
138
- tab_indicator_color: ?RGBA,
139
- truncate: bool,
140
- ellipsis_chunk: TextChunk,
141
- ellipsis_mem_id: u8,
142
-
143
- // Measurement cache for Yoga layout. Keyed by (buffer, epoch, width, wrap_mode).
144
- // Using epoch instead of dirty flag prevents stale returns when unrelated
145
- // code paths clear dirty (e.g., updateVirtualLines).
146
- cached_measure_width: ?u32,
147
- cached_measure_wrap_mode: WrapMode,
148
- cached_measure_result: ?MeasureResult,
149
- cached_measure_epoch: u64,
150
- cached_measure_buffer: ?*UnifiedTextBuffer,
151
-
152
- truncation_applied: bool,
153
- truncation_epoch: u64,
154
- truncation_viewport: ?Viewport,
155
-
156
- pub fn init(global_allocator: Allocator, text_buffer: *UnifiedTextBuffer) TextBufferViewError!*Self {
157
- const self = global_allocator.create(Self) catch return TextBufferViewError.OutOfMemory;
158
- errdefer global_allocator.destroy(self);
159
-
160
- const virtual_lines_internal_arena = global_allocator.create(std.heap.ArenaAllocator) catch return TextBufferViewError.OutOfMemory;
161
- errdefer global_allocator.destroy(virtual_lines_internal_arena);
162
- virtual_lines_internal_arena.* = std.heap.ArenaAllocator.init(global_allocator);
163
-
164
- const view_id = text_buffer.registerView() catch return TextBufferViewError.OutOfMemory;
165
-
166
- const ellipsis_text = "...";
167
- const ellipsis_mem_id = text_buffer.registerMemBuffer(ellipsis_text, false) catch return TextBufferViewError.OutOfMemory;
168
- const ellipsis_chunk = text_buffer.createChunk(ellipsis_mem_id, 0, 3);
169
-
170
- self.* = .{
171
- .text_buffer = text_buffer,
172
- .original_text_buffer = text_buffer,
173
- .view_id = view_id,
174
- .selection = null,
175
- .selection_anchor_offset = null,
176
- .viewport = null,
177
- .wrap_width = null,
178
- .wrap_mode = .none,
179
- .virtual_lines = .{},
180
- .virtual_lines_dirty = true,
181
- .cached_line_starts = .{},
182
- .cached_line_widths = .{},
183
- .cached_line_sources = .{},
184
- .cached_line_wrap_indices = .{},
185
- .cached_line_first_vline = .{},
186
- .cached_line_vline_counts = .{},
187
- .global_allocator = global_allocator,
188
- .virtual_lines_arena = virtual_lines_internal_arena,
189
- .measure_arena = std.heap.ArenaAllocator.init(global_allocator),
190
- .tab_indicator = null,
191
- .tab_indicator_color = null,
192
- .truncate = false,
193
- .ellipsis_chunk = ellipsis_chunk,
194
- .ellipsis_mem_id = ellipsis_mem_id,
195
- .cached_measure_width = null,
196
- .cached_measure_wrap_mode = .none,
197
- .cached_measure_result = null,
198
- .cached_measure_epoch = 0,
199
- .cached_measure_buffer = null,
200
- .truncation_applied = false,
201
- .truncation_epoch = 0,
202
- .truncation_viewport = null,
203
- };
204
-
205
- return self;
206
- }
207
-
208
- /// IMPORTANT: Views must be destroyed BEFORE their associated TextBuffer.
209
- /// Destroying the TextBuffer first will cause use-after-free when calling deinit.
210
- /// The TypeScript wrappers enforce this order via the destroy() methods.
211
- pub fn deinit(self: *Self) void {
212
- self.original_text_buffer.unregisterView(self.view_id);
213
- self.virtual_lines_arena.deinit();
214
- self.global_allocator.destroy(self.virtual_lines_arena);
215
- self.measure_arena.deinit();
216
- self.global_allocator.destroy(self);
217
- }
218
-
219
- pub fn setViewport(self: *Self, vp: ?Viewport) void {
220
- self.viewport = vp;
221
-
222
- // If viewport has width, set wrap width (wrapping behavior depends on wrap_mode)
223
- if (vp) |viewport| {
224
- if (self.wrap_width != viewport.width) {
225
- self.wrap_width = viewport.width;
226
- self.virtual_lines_dirty = true;
227
- self.truncation_applied = false;
228
- }
229
- } else {
230
- self.truncation_applied = false;
231
- }
232
- }
233
-
234
- pub fn getViewport(self: *const Self) ?Viewport {
235
- return self.viewport;
236
- }
237
-
238
- // This is a convenience method that preserves existing offset
239
- pub fn setViewportSize(self: *Self, width: u32, height: u32) void {
240
- if (self.viewport) |vp| {
241
- self.setViewport(Viewport{
242
- .x = vp.x,
243
- .y = vp.y,
244
- .width = width,
245
- .height = height,
246
- });
247
- } else {
248
- self.setViewport(Viewport{
249
- .x = 0,
250
- .y = 0,
251
- .width = width,
252
- .height = height,
253
- });
254
- }
255
- }
256
-
257
- pub fn setWrapWidth(self: *Self, width: ?u32) void {
258
- if (self.wrap_width != width) {
259
- self.wrap_width = width;
260
- self.virtual_lines_dirty = true;
261
- self.truncation_applied = false;
262
- }
263
- }
264
-
265
- pub fn setWrapMode(self: *Self, mode: WrapMode) void {
266
- if (self.wrap_mode != mode) {
267
- self.wrap_mode = mode;
268
- self.virtual_lines_dirty = true;
269
- self.truncation_applied = false;
270
- }
271
- }
272
-
273
- fn calculateChunkFitWord(self: *const Self, chunk: *const TextChunk, char_offset_in_chunk: u32, max_width: u32) tb.ChunkFitResult {
274
- if (max_width == 0) return .{ .char_count = 0, .width = 0 };
275
-
276
- const total_width = @as(u32, chunk.width) - char_offset_in_chunk;
277
- if (total_width == 0) return .{ .char_count = 0, .width = 0 };
278
- if (total_width <= max_width) return .{ .char_count = total_width, .width = total_width };
279
-
280
- const wrap_offsets = self.text_buffer.getWrapOffsetsFor(chunk) catch {
281
- const fit_width = @min(max_width, total_width);
282
- return .{ .char_count = fit_width, .width = fit_width };
283
- };
284
-
285
- var last_boundary: ?u32 = null;
286
- var first_boundary: ?u32 = null;
287
-
288
- for (wrap_offsets) |wrap_break| {
289
- const offset = @as(u32, wrap_break.char_offset);
290
- if (offset < char_offset_in_chunk) continue;
291
-
292
- const local_offset = offset - char_offset_in_chunk;
293
- if (local_offset >= total_width) break;
294
-
295
- const width_to_boundary = local_offset + 1;
296
- if (first_boundary == null) first_boundary = width_to_boundary;
297
-
298
- if (width_to_boundary <= max_width) {
299
- last_boundary = width_to_boundary;
300
- } else break;
301
- }
302
-
303
- if (last_boundary) |width| return .{ .char_count = width, .width = width };
304
-
305
- const line_width = self.wrap_width orelse max_width;
306
- const needs_force_break = (first_boundary orelse total_width) > line_width;
307
-
308
- if (needs_force_break) {
309
- const fit_width = @min(max_width, total_width);
310
- return .{ .char_count = fit_width, .width = fit_width };
311
- }
312
-
313
- return .{ .char_count = 0, .width = 0 };
314
- }
315
-
316
- pub fn updateVirtualLines(self: *Self) void {
317
- const buffer_dirty = self.text_buffer.isViewDirty(self.view_id);
318
- if (!self.virtual_lines_dirty and !buffer_dirty) return;
319
-
320
- _ = self.virtual_lines_arena.reset(.free_all);
321
- self.virtual_lines = .{};
322
- self.cached_line_starts = .{};
323
- self.cached_line_widths = .{};
324
- self.cached_line_sources = .{};
325
- self.cached_line_wrap_indices = .{};
326
- self.cached_line_first_vline = .{};
327
- self.cached_line_vline_counts = .{};
328
- self.truncation_applied = false;
329
- const virtual_allocator = self.virtual_lines_arena.allocator();
330
-
331
- // Create output structure for the generic function
332
- const output = VirtualLineOutput{
333
- .virtual_lines = &self.virtual_lines,
334
- .cached_line_starts = &self.cached_line_starts,
335
- .cached_line_widths = &self.cached_line_widths,
336
- .cached_line_sources = &self.cached_line_sources,
337
- .cached_line_wrap_indices = &self.cached_line_wrap_indices,
338
- .cached_line_first_vline = &self.cached_line_first_vline,
339
- .cached_line_vline_counts = &self.cached_line_vline_counts,
340
- };
341
-
342
- // Call the generic calculation function
343
- calculateVirtualLinesGeneric(
344
- self.text_buffer,
345
- self.wrap_mode,
346
- self.wrap_width,
347
- virtual_allocator,
348
- output,
349
- );
350
-
351
- self.virtual_lines_dirty = false;
352
- self.text_buffer.clearViewDirty(self.view_id);
353
- }
354
-
355
- pub fn getVirtualLineCount(self: *Self) u32 {
356
- self.updateVirtualLines();
357
- return @intCast(self.virtual_lines.items.len);
358
- }
359
-
360
- pub fn getVirtualLines(self: *Self) []const VirtualLine {
361
- self.updateVirtualLines();
362
-
363
- const all_vlines = self.virtual_lines.items;
364
-
365
- if (self.truncate and self.viewport != null) {
366
- self.ensureTruncation();
367
- }
368
-
369
- if (self.viewport) |vp| {
370
- const start_idx = @min(vp.y, @as(u32, @intCast(all_vlines.len)));
371
- const end_idx = @min(start_idx + vp.height, @as(u32, @intCast(all_vlines.len)));
372
- return all_vlines[start_idx..end_idx];
373
- }
374
-
375
- return all_vlines;
376
- }
377
-
378
- pub fn getCachedLineInfo(self: *Self) LineInfo {
379
- self.updateVirtualLines();
380
-
381
- // If viewport is set, return only the visible lines' info
382
- if (self.viewport) |vp| {
383
- const start_idx = @min(vp.y, @as(u32, @intCast(self.cached_line_starts.items.len)));
384
- const end_idx = @min(start_idx + vp.height, @as(u32, @intCast(self.cached_line_starts.items.len)));
385
-
386
- const viewport_line_start_cols = self.cached_line_starts.items[start_idx..end_idx];
387
- const viewport_line_width_cols = self.cached_line_widths.items[start_idx..end_idx];
388
- const viewport_line_sources = self.cached_line_sources.items[start_idx..end_idx];
389
- const viewport_line_wraps = self.cached_line_wrap_indices.items[start_idx..end_idx];
390
-
391
- var width_cols_max: u32 = 0;
392
- for (viewport_line_width_cols) |w| {
393
- width_cols_max = @max(width_cols_max, w);
394
- }
395
-
396
- return LineInfo{
397
- .line_start_cols = viewport_line_start_cols,
398
- .line_width_cols = viewport_line_width_cols,
399
- .line_sources = viewport_line_sources,
400
- .line_wraps = viewport_line_wraps,
401
- .line_width_cols_max = width_cols_max,
402
- };
403
- }
404
-
405
- return LineInfo{
406
- .line_start_cols = self.cached_line_starts.items,
407
- .line_width_cols = self.cached_line_widths.items,
408
- .line_sources = self.cached_line_sources.items,
409
- .line_wraps = self.cached_line_wrap_indices.items,
410
- .line_width_cols_max = self.text_buffer.lineWidthColsMax(),
411
- };
412
- }
413
-
414
- pub fn getLogicalLineInfo(self: *Self) LineInfo {
415
- self.updateVirtualLines();
416
-
417
- return LineInfo{
418
- .line_start_cols = self.cached_line_starts.items,
419
- .line_width_cols = self.cached_line_widths.items,
420
- .line_sources = self.cached_line_sources.items,
421
- .line_wraps = self.cached_line_wrap_indices.items,
422
- .line_width_cols_max = self.text_buffer.lineWidthColsMax(),
423
- };
424
- }
425
-
426
- pub fn getWrapInfo(self: *Self) WrapInfo {
427
- self.updateVirtualLines();
428
- return WrapInfo{
429
- .line_first_vline = self.cached_line_first_vline.items,
430
- .line_vline_counts = self.cached_line_vline_counts.items,
431
- };
432
- }
433
-
434
- pub fn findVisualLineIndex(self: *Self, logical_row: u32, logical_col: u32) u32 {
435
- self.updateVirtualLines();
436
-
437
- const vlines = self.virtual_lines.items;
438
- if (vlines.len == 0) return 0;
439
-
440
- const wrap_info = self.getWrapInfo();
441
-
442
- // Clamp logical_row to valid range
443
- const clamped_row = if (logical_row >= wrap_info.line_first_vline.len)
444
- if (wrap_info.line_first_vline.len > 0) wrap_info.line_first_vline.len - 1 else 0
445
- else
446
- logical_row;
447
-
448
- if (clamped_row >= wrap_info.line_first_vline.len) return 0;
449
-
450
- const first_vline_idx = wrap_info.line_first_vline[clamped_row];
451
- const vline_count = wrap_info.line_vline_counts[clamped_row];
452
-
453
- if (vline_count == 0) return first_vline_idx;
454
-
455
- var i: u32 = 0;
456
- while (i < vline_count) : (i += 1) {
457
- const vline_idx = first_vline_idx + i;
458
- if (vline_idx >= vlines.len) break;
459
-
460
- const vline = &vlines[vline_idx];
461
- const vline_start_col = vline.source_col_offset;
462
- const vline_end_col = vline_start_col + vline.width_cols;
463
-
464
- const is_last_vline = (i == vline_count - 1);
465
-
466
- // For the end check: use < for all lines except the last line where we use <=
467
- // This ensures that a position exactly at vline_end_col goes to the NEXT line
468
- // unless this is the last line (where there is no next line)
469
- const end_check = if (is_last_vline) logical_col <= vline_end_col else logical_col < vline_end_col;
470
-
471
- if (logical_col >= vline_start_col and end_check) {
472
- return vline_idx;
473
- }
474
- }
475
-
476
- // If not found, return last virtual line for this logical line
477
- const last_vline_idx = first_vline_idx + vline_count - 1;
478
- if (last_vline_idx < vlines.len) {
479
- return last_vline_idx;
480
- }
481
-
482
- return first_vline_idx;
483
- }
484
-
485
- pub fn getPlainTextIntoBuffer(self: *const Self, out_buffer: []u8) usize {
486
- return self.text_buffer.getPlainTextIntoBuffer(out_buffer);
487
- }
488
-
489
- pub fn getArenaAllocatedBytes(self: *const Self) usize {
490
- return self.virtual_lines_arena.queryCapacity();
491
- }
492
-
493
- pub fn setSelection(self: *Self, start: u32, end: u32, bgColor: ?RGBA, fgColor: ?RGBA) void {
494
- self.selection = TextSelection{
495
- .start = start,
496
- .end = end,
497
- .bgColor = bgColor,
498
- .fgColor = fgColor,
499
- };
500
- }
501
-
502
- pub fn updateSelection(self: *Self, end: u32, bgColor: ?RGBA, fgColor: ?RGBA) void {
503
- if (self.selection) |sel| {
504
- self.selection = TextSelection{
505
- .start = sel.start,
506
- .end = end,
507
- .bgColor = bgColor,
508
- .fgColor = fgColor,
509
- };
510
- }
511
- }
512
-
513
- pub fn resetSelection(self: *Self) void {
514
- self.selection = null;
515
- }
516
-
517
- pub fn getSelection(self: *const Self) ?TextSelection {
518
- return self.selection;
519
- }
520
-
521
- pub fn getTextBuffer(self: *const Self) *UnifiedTextBuffer {
522
- return self.text_buffer;
523
- }
524
-
525
- pub fn switchToBuffer(self: *Self, buffer: *UnifiedTextBuffer) void {
526
- self.text_buffer = buffer;
527
- self.virtual_lines_dirty = true;
528
- }
529
-
530
- pub fn switchToOriginalBuffer(self: *Self) void {
531
- if (self.text_buffer != self.original_text_buffer) {
532
- self.text_buffer = self.original_text_buffer;
533
- self.virtual_lines_dirty = true;
534
- }
535
- }
536
-
537
- pub fn setLocalSelection(self: *Self, anchorX: i32, anchorY: i32, focusX: i32, focusY: i32, bgColor: ?RGBA, fgColor: ?RGBA) bool {
538
- self.updateVirtualLines();
539
- if (self.truncate and self.viewport != null) {
540
- self.ensureTruncation();
541
- }
542
-
543
- const anchor_above = anchorY < 0;
544
- const focus_above = focusY < 0;
545
- const max_y = @as(i32, @intCast(self.virtual_lines.items.len)) - 1;
546
- const anchor_below = anchorY > max_y;
547
- const focus_below = focusY > max_y;
548
-
549
- if ((anchor_above and focus_above) or (anchor_below and focus_below)) {
550
- const had_selection = self.selection != null;
551
- self.selection = null;
552
- self.selection_anchor_offset = null;
553
- return had_selection;
554
- }
555
-
556
- const text_end_offset = self.getTextEndOffset();
557
-
558
- const anchor_offset = if (anchor_above or anchorX < 0)
559
- 0
560
- else if (anchor_below)
561
- text_end_offset
562
- else
563
- self.coordsToCharOffset(anchorX, anchorY) orelse {
564
- const had_selection = self.selection != null;
565
- self.selection = null;
566
- self.selection_anchor_offset = null;
567
- return had_selection;
568
- };
569
-
570
- const focus_offset = if (focus_above or focusX < 0)
571
- 0
572
- else if (focus_below)
573
- text_end_offset
574
- else
575
- self.coordsToCharOffset(focusX, focusY) orelse {
576
- const had_selection = self.selection != null;
577
- self.selection = null;
578
- self.selection_anchor_offset = null;
579
- return had_selection;
580
- };
581
-
582
- self.selection_anchor_offset = anchor_offset;
583
-
584
- const new_start = @min(anchor_offset, focus_offset);
585
- const new_end = @max(anchor_offset, focus_offset);
586
-
587
- // Always store selection, even if zero-width, to preserve anchor for updateLocalSelection
588
- const new_selection = TextSelection{
589
- .start = new_start,
590
- .end = new_end,
591
- .bgColor = bgColor,
592
- .fgColor = fgColor,
593
- };
594
-
595
- const selection_changed = if (self.selection) |old_sel|
596
- old_sel.start != new_selection.start or old_sel.end != new_selection.end
597
- else
598
- true;
599
-
600
- self.selection = new_selection;
601
- return selection_changed;
602
- }
603
-
604
- pub fn updateLocalSelection(self: *Self, anchorX: i32, anchorY: i32, focusX: i32, focusY: i32, bgColor: ?RGBA, fgColor: ?RGBA) bool {
605
- if (self.selection_anchor_offset) |_| {
606
- return self.updateLocalSelectionFocusOnly(focusX, focusY, bgColor, fgColor);
607
- } else {
608
- return self.setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor);
609
- }
610
- }
611
-
612
- fn updateLocalSelectionFocusOnly(self: *Self, focusX: i32, focusY: i32, bgColor: ?RGBA, fgColor: ?RGBA) bool {
613
- const anchor_offset = self.selection_anchor_offset orelse return false;
614
-
615
- self.updateVirtualLines();
616
- if (self.truncate and self.viewport != null) {
617
- self.applyTruncation();
618
- }
619
-
620
- const focus_above = focusY < 0;
621
- const max_y = @as(i32, @intCast(self.virtual_lines.items.len)) - 1;
622
- const focus_below = focusY > max_y;
623
-
624
- const text_end_offset = self.getTextEndOffset();
625
-
626
- const focus_col_offset = if (focus_above or focusX < 0)
627
- 0
628
- else if (focus_below)
629
- text_end_offset
630
- else
631
- self.coordsToCharOffset(focusX, focusY) orelse return false;
632
-
633
- const new_start = @min(anchor_offset, focus_col_offset);
634
- var new_end = @max(anchor_offset, focus_col_offset);
635
-
636
- if (focus_col_offset < anchor_offset) {
637
- new_end = @min(new_end + 1, text_end_offset);
638
- }
639
-
640
- self.selection = TextSelection{
641
- .start = new_start,
642
- .end = new_end,
643
- .bgColor = bgColor,
644
- .fgColor = fgColor,
645
- };
646
-
647
- return true;
648
- }
649
-
650
- pub fn resetLocalSelection(self: *Self) void {
651
- self.selection = null;
652
- self.selection_anchor_offset = null;
653
- }
654
-
655
- fn getTextEndOffset(self: *Self) u32 {
656
- if (self.truncate and self.viewport != null) {
657
- self.ensureTruncation();
658
- }
659
-
660
- if (self.virtual_lines.items.len == 0) return 0;
661
- const last_line_idx = self.virtual_lines.items.len - 1;
662
- const last_vline = &self.virtual_lines.items[last_line_idx];
663
-
664
- if (last_vline.is_truncated) {
665
- return last_vline.col_offset + last_vline.truncation_suffix_start + (last_vline.width_cols - last_vline.ellipsis_pos - 3);
666
- }
667
-
668
- return last_vline.col_offset + last_vline.width_cols;
669
- }
670
-
671
- fn coordsToCharOffset(self: *Self, x: i32, y: i32) ?u32 {
672
- self.updateVirtualLines();
673
- if (self.truncate and self.viewport != null) {
674
- self.ensureTruncation();
675
- }
676
-
677
- const y_offset: i32 = if (self.viewport) |vp| @intCast(vp.y) else 0;
678
- const x_offset: i32 = if (self.viewport) |vp|
679
- (if (self.wrap_mode == .none) @intCast(vp.x) else 0)
680
- else
681
- 0;
682
-
683
- if (self.virtual_lines.items.len == 0) {
684
- return 0;
685
- }
686
-
687
- const abs_y = y + y_offset;
688
- const abs_x = x + x_offset;
689
-
690
- const clamped_y = @max(0, @min(abs_y, @as(i32, @intCast(self.virtual_lines.items.len)) - 1));
691
-
692
- const vline_idx: usize = @intCast(clamped_y);
693
- const vline = &self.virtual_lines.items[vline_idx];
694
- const lineStart = vline.col_offset;
695
- const lineWidth = vline.width_cols;
696
-
697
- var localX = @max(0, @min(abs_x, @as(i32, @intCast(lineWidth))));
698
-
699
- if (vline.is_truncated) {
700
- const ellipsis_width: u32 = 3;
701
- const localX_u32: u32 = @intCast(localX);
702
-
703
- if (localX_u32 >= vline.ellipsis_pos and localX_u32 < vline.ellipsis_pos + ellipsis_width) {
704
- localX = @intCast(vline.ellipsis_pos);
705
- } else if (localX_u32 >= vline.ellipsis_pos + ellipsis_width) {
706
- const suffix_offset = localX_u32 - vline.ellipsis_pos - ellipsis_width;
707
- localX = @intCast(vline.truncation_suffix_start + suffix_offset);
708
- }
709
- }
710
-
711
- const result = lineStart + @as(u32, @intCast(localX));
712
-
713
- return result;
714
- }
715
-
716
- /// Pack selection info into u64 for efficient passing
717
- /// Returns 0xFFFF_FFFF_FFFF_FFFF for no selection or zero-width selection
718
- pub fn packSelectionInfo(self: *const Self) u64 {
719
- if (self.selection) |sel| {
720
- if (sel.start == sel.end) {
721
- return 0xFFFF_FFFF_FFFF_FFFF;
722
- }
723
- return (@as(u64, sel.start) << 32) | @as(u64, sel.end);
724
- } else {
725
- return 0xFFFF_FFFF_FFFF_FFFF;
726
- }
727
- }
728
-
729
- /// Get selected text into buffer - using efficient single-pass API
730
- pub fn getSelectedTextIntoBuffer(self: *Self, out_buffer: []u8) usize {
731
- const selection = self.selection orelse return 0;
732
- if (selection.start == selection.end) return 0;
733
- return self.text_buffer.getTextRange(selection.start, selection.end, out_buffer);
734
- }
735
-
736
- pub fn getVirtualLineSpans(self: *const Self, vline_idx: usize) VirtualLineSpanInfo {
737
- if (vline_idx >= self.virtual_lines.items.len) {
738
- return VirtualLineSpanInfo{ .spans = &[_]StyleSpan{}, .source_line = 0, .col_offset = 0 };
739
- }
740
-
741
- const vline = &self.virtual_lines.items[vline_idx];
742
- const spans = self.text_buffer.getLineSpans(vline.source_line);
743
-
744
- return VirtualLineSpanInfo{
745
- .spans = spans,
746
- .source_line = vline.source_line,
747
- .col_offset = vline.source_col_offset,
748
- };
749
- }
750
-
751
- pub fn setTabIndicator(self: *Self, indicator: ?u32) void {
752
- self.tab_indicator = indicator;
753
- }
754
-
755
- pub fn getTabIndicator(self: *const Self) ?u32 {
756
- return self.tab_indicator;
757
- }
758
-
759
- pub fn setTabIndicatorColor(self: *Self, color: ?RGBA) void {
760
- self.tab_indicator_color = color;
761
- }
762
-
763
- pub fn getTabIndicatorColor(self: *const Self) ?RGBA {
764
- return self.tab_indicator_color;
765
- }
766
-
767
- pub fn setTruncate(self: *Self, truncate: bool) void {
768
- if (self.truncate != truncate) {
769
- self.truncate = truncate;
770
- self.virtual_lines_dirty = true;
771
- self.truncation_applied = false;
772
- }
773
- }
774
-
775
- pub fn getTruncate(self: *const Self) bool {
776
- return self.truncate;
777
- }
778
-
779
- fn ensureTruncation(self: *Self) void {
780
- if (!self.truncate or self.viewport == null) return;
781
-
782
- const epoch = self.text_buffer.getContentEpoch();
783
- if (self.truncation_applied and self.truncation_epoch == epoch and
784
- self.truncation_viewport != null and self.viewport != null and
785
- self.truncation_viewport.?.x == self.viewport.?.x and
786
- self.truncation_viewport.?.y == self.viewport.?.y and
787
- self.truncation_viewport.?.width == self.viewport.?.width and
788
- self.truncation_viewport.?.height == self.viewport.?.height)
789
- {
790
- return;
791
- }
792
-
793
- self.applyTruncation();
794
- self.truncation_applied = true;
795
- self.truncation_epoch = epoch;
796
- self.truncation_viewport = self.viewport;
797
- }
798
-
799
- fn applyTruncation(self: *Self) void {
800
- const vp = self.viewport orelse return;
801
- if (vp.width == 0) return;
802
-
803
- const ellipsis_width: u32 = 3;
804
-
805
- for (self.virtual_lines.items) |*vline| {
806
- if (vline.width_cols <= vp.width) continue;
807
-
808
- if (vp.width <= ellipsis_width) {
809
- vline.chunks.clearRetainingCapacity();
810
- vline.width_cols = 0;
811
- vline.is_truncated = true;
812
- vline.ellipsis_pos = 0;
813
- vline.truncation_suffix_start = vline.width_cols;
814
- continue;
815
- }
816
-
817
- const available_width = vp.width - ellipsis_width;
818
- const prefix_width = available_width / 2;
819
- const suffix_width = available_width - prefix_width;
820
-
821
- var new_chunks: std.ArrayListUnmanaged(VirtualChunk) = .{};
822
-
823
- var prefix_accumulated: u32 = 0;
824
- for (vline.chunks.items) |chunk| {
825
- if (prefix_accumulated >= prefix_width) break;
826
-
827
- const space_left = prefix_width - prefix_accumulated;
828
- if (chunk.width <= space_left) {
829
- new_chunks.append(self.virtual_lines_arena.allocator(), chunk) catch return;
830
- prefix_accumulated += chunk.width;
831
- } else {
832
- var partial = chunk;
833
- partial.width = space_left;
834
- new_chunks.append(self.virtual_lines_arena.allocator(), partial) catch return;
835
- prefix_accumulated += space_left;
836
- break;
837
- }
838
- }
839
-
840
- new_chunks.append(self.virtual_lines_arena.allocator(), VirtualChunk{
841
- .grapheme_start = 0,
842
- .width = ellipsis_width,
843
- .chunk = &self.ellipsis_chunk,
844
- }) catch return;
845
-
846
- const suffix_start_pos = vline.width_cols - suffix_width;
847
-
848
- var pos_accumulated: u32 = 0;
849
- for (vline.chunks.items) |chunk| {
850
- const chunk_end = pos_accumulated + chunk.width;
851
-
852
- if (chunk_end <= suffix_start_pos) {
853
- pos_accumulated += chunk.width;
854
- continue;
855
- }
856
-
857
- if (pos_accumulated >= suffix_start_pos) {
858
- new_chunks.append(self.virtual_lines_arena.allocator(), chunk) catch return;
859
- } else {
860
- const offset_in_chunk = suffix_start_pos - pos_accumulated;
861
- var partial = chunk;
862
- partial.grapheme_start += offset_in_chunk;
863
- partial.width = chunk.width - offset_in_chunk;
864
- new_chunks.append(self.virtual_lines_arena.allocator(), partial) catch return;
865
- }
866
-
867
- pos_accumulated += chunk.width;
868
- }
869
-
870
- vline.chunks.clearRetainingCapacity();
871
- vline.chunks.appendSlice(self.virtual_lines_arena.allocator(), new_chunks.items) catch return;
872
- vline.width_cols = vp.width;
873
- vline.is_truncated = true;
874
- vline.ellipsis_pos = prefix_width;
875
- vline.truncation_suffix_start = suffix_start_pos;
876
- }
877
- }
878
-
879
- /// Measure dimensions for given width/height WITHOUT modifying virtual lines cache
880
- /// This is useful for Yoga measure functions that need to know dimensions without committing changes
881
- /// Special case: width=0 or wrap_mode=.none means "measure intrinsic/max-content width" (no wrapping)
882
- pub fn measureForDimensions(self: *Self, width: u32, height: u32) TextBufferViewError!MeasureResult {
883
- _ = height; // Height is for future use, currently only width affects layout
884
- const epoch = self.text_buffer.getContentEpoch();
885
- if (self.cached_measure_result) |result| {
886
- if (self.cached_measure_epoch == epoch and self.cached_measure_buffer == self.text_buffer) {
887
- if (self.cached_measure_width) |cached_width| {
888
- if (cached_width == width and self.cached_measure_wrap_mode == self.wrap_mode) {
889
- return result;
890
- }
891
- }
892
- }
893
- }
894
-
895
- // No-wrap path avoids allocations by using marker-based line widths.
896
- if (width == 0 or self.wrap_mode == .none) {
897
- const line_count = self.text_buffer.lineCount();
898
- var width_cols_max: u32 = 0;
899
- var row: u32 = 0;
900
- while (row < line_count) : (row += 1) {
901
- width_cols_max = @max(width_cols_max, self.text_buffer.lineWidthAt(row));
902
- }
903
-
904
- const result = MeasureResult{
905
- .line_count = line_count,
906
- .width_cols_max = width_cols_max,
907
- };
908
-
909
- self.cached_measure_width = width;
910
- self.cached_measure_wrap_mode = self.wrap_mode;
911
- self.cached_measure_result = result;
912
- self.cached_measure_epoch = epoch;
913
- self.cached_measure_buffer = self.text_buffer;
914
-
915
- return result;
916
- }
917
-
918
- // Reuse arena capacity to avoid allocation overhead during streaming.
919
- _ = self.measure_arena.reset(.retain_capacity);
920
- const measure_allocator = self.measure_arena.allocator();
921
-
922
- // Create temporary output structures
923
- var temp_virtual_lines = std.ArrayListUnmanaged(VirtualLine){};
924
- var temp_line_starts = std.ArrayListUnmanaged(u32){};
925
- var temp_line_widths = std.ArrayListUnmanaged(u32){};
926
- var temp_line_sources = std.ArrayListUnmanaged(u32){};
927
- var temp_line_wrap_indices = std.ArrayListUnmanaged(u32){};
928
- var temp_line_first_vline = std.ArrayListUnmanaged(u32){};
929
- var temp_line_vline_counts = std.ArrayListUnmanaged(u32){};
930
-
931
- const output = VirtualLineOutput{
932
- .virtual_lines = &temp_virtual_lines,
933
- .cached_line_starts = &temp_line_starts,
934
- .cached_line_widths = &temp_line_widths,
935
- .cached_line_sources = &temp_line_sources,
936
- .cached_line_wrap_indices = &temp_line_wrap_indices,
937
- .cached_line_first_vline = &temp_line_first_vline,
938
- .cached_line_vline_counts = &temp_line_vline_counts,
939
- };
940
-
941
- // Use width for wrap calculation
942
- const wrap_width_for_measure = if (self.wrap_mode != .none and width > 0) width else null;
943
-
944
- // Call generic calculation with temporary structures
945
- calculateVirtualLinesGeneric(
946
- self.text_buffer,
947
- self.wrap_mode,
948
- wrap_width_for_measure,
949
- measure_allocator,
950
- output,
951
- );
952
-
953
- // Calculate max width from temp structures
954
- var width_cols_max: u32 = 0;
955
- for (temp_line_widths.items) |w| {
956
- width_cols_max = @max(width_cols_max, w);
957
- }
958
-
959
- const result = MeasureResult{
960
- .line_count = @intCast(temp_virtual_lines.items.len),
961
- .width_cols_max = width_cols_max,
962
- };
963
-
964
- self.cached_measure_width = width;
965
- self.cached_measure_wrap_mode = self.wrap_mode;
966
- self.cached_measure_result = result;
967
- self.cached_measure_epoch = epoch;
968
- self.cached_measure_buffer = self.text_buffer;
969
-
970
- return result;
971
- }
972
-
973
- /// Generic virtual line calculation that writes to provided output structures
974
- fn calculateVirtualLinesGeneric(
975
- text_buffer: *UnifiedTextBuffer,
976
- wrap_mode: WrapMode,
977
- wrap_width: ?u32,
978
- allocator: Allocator,
979
- output: VirtualLineOutput,
980
- ) void {
981
- if (wrap_mode == .none or wrap_width == null) {
982
- // No wrapping - create 1:1 mapping to real lines
983
- const Context = struct {
984
- text_buffer: *UnifiedTextBuffer,
985
- allocator: Allocator,
986
- output: VirtualLineOutput,
987
- current_vline: ?VirtualLine = null,
988
-
989
- fn segment_callback(ctx_ptr: *anyopaque, line_idx: u32, chunk: *const TextChunk, _: u32) void {
990
- _ = line_idx;
991
- const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
992
-
993
- if (ctx.current_vline) |*vline| {
994
- vline.chunks.append(ctx.allocator, VirtualChunk{
995
- .grapheme_start = 0,
996
- .width = chunk.width,
997
- .chunk = chunk,
998
- }) catch {};
999
- }
1000
- }
1001
-
1002
- fn line_end_callback(ctx_ptr: *anyopaque, line_info: iter_mod.LineInfo) void {
1003
- const ctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
1004
-
1005
- const first_vline_idx: u32 = @intCast(ctx.output.virtual_lines.items.len);
1006
- ctx.output.cached_line_first_vline.append(ctx.allocator, first_vline_idx) catch {};
1007
- ctx.output.cached_line_vline_counts.append(ctx.allocator, 1) catch {};
1008
-
1009
- var vline = if (ctx.current_vline) |v| v else VirtualLine.init();
1010
- vline.width_cols = line_info.width_cols;
1011
- vline.col_offset = line_info.col_offset;
1012
- vline.source_line = line_info.line_idx;
1013
- vline.source_col_offset = 0;
1014
-
1015
- ctx.output.virtual_lines.append(ctx.allocator, vline) catch {};
1016
- ctx.output.cached_line_starts.append(ctx.allocator, vline.col_offset) catch {};
1017
- ctx.output.cached_line_widths.append(ctx.allocator, vline.width_cols) catch {};
1018
- ctx.output.cached_line_sources.append(ctx.allocator, @intCast(line_info.line_idx)) catch {};
1019
- ctx.output.cached_line_wrap_indices.append(ctx.allocator, 0) catch {};
1020
-
1021
- ctx.current_vline = VirtualLine.init();
1022
- }
1023
- };
1024
-
1025
- var ctx = Context{
1026
- .text_buffer = text_buffer,
1027
- .allocator = allocator,
1028
- .output = output,
1029
- .current_vline = VirtualLine.init(),
1030
- };
1031
-
1032
- text_buffer.walkLinesAndSegments(&ctx, Context.segment_callback, Context.line_end_callback);
1033
- } else {
1034
- const wrap_w = wrap_width.?;
1035
-
1036
- const WrapContext = struct {
1037
- text_buffer: *UnifiedTextBuffer,
1038
- allocator: Allocator,
1039
- output: VirtualLineOutput,
1040
- wrap_mode: WrapMode,
1041
- wrap_w: u32,
1042
- global_char_offset: u32 = 0,
1043
- line_idx: u32 = 0,
1044
- line_col_offset: u32 = 0,
1045
- line_position: u32 = 0,
1046
- current_vline: VirtualLine = VirtualLine.init(),
1047
- chunk_idx_in_line: u32 = 0,
1048
- current_line_first_vline_idx: u32 = 0,
1049
- current_line_vline_count: u32 = 0,
1050
-
1051
- last_wrap_chunk_count: u32 = 0,
1052
- last_wrap_line_position: u32 = 0,
1053
- last_wrap_global_offset: u32 = 0,
1054
-
1055
- fn commitVirtualLine(wctx: *@This()) void {
1056
- wctx.current_vline.width_cols = wctx.line_position;
1057
- wctx.current_vline.source_line = wctx.line_idx;
1058
- wctx.current_vline.source_col_offset = wctx.line_col_offset;
1059
- wctx.output.virtual_lines.append(wctx.allocator, wctx.current_vline) catch {};
1060
- wctx.output.cached_line_starts.append(wctx.allocator, wctx.current_vline.col_offset) catch {};
1061
- wctx.output.cached_line_widths.append(wctx.allocator, wctx.current_vline.width_cols) catch {};
1062
- wctx.output.cached_line_sources.append(wctx.allocator, wctx.line_idx) catch {};
1063
- wctx.output.cached_line_wrap_indices.append(wctx.allocator, wctx.current_line_vline_count) catch {};
1064
-
1065
- wctx.current_line_vline_count += 1;
1066
-
1067
- wctx.line_col_offset += wctx.line_position;
1068
- wctx.current_vline = VirtualLine.init();
1069
- wctx.current_vline.col_offset = wctx.global_char_offset;
1070
- wctx.line_position = 0;
1071
-
1072
- wctx.last_wrap_chunk_count = 0;
1073
- wctx.last_wrap_line_position = 0;
1074
- wctx.last_wrap_global_offset = 0;
1075
- }
1076
-
1077
- fn addVirtualChunk(wctx: *@This(), chunk: *const TextChunk, _: u32, start: u32, width_param: u32) void {
1078
- wctx.current_vline.chunks.append(wctx.allocator, VirtualChunk{
1079
- .grapheme_start = start,
1080
- .width = width_param,
1081
- .chunk = chunk,
1082
- }) catch {};
1083
- wctx.global_char_offset += width_param;
1084
- wctx.line_position += width_param;
1085
- }
1086
-
1087
- fn segment_callback(ctx_ptr: *anyopaque, _: u32, chunk: *const TextChunk, chunk_idx_in_line: u32) void {
1088
- const wctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
1089
- wctx.chunk_idx_in_line = chunk_idx_in_line;
1090
-
1091
- if (wctx.wrap_mode == .word) {
1092
- const chunk_bytes = chunk.getBytes(wctx.text_buffer.memRegistry());
1093
- const wrap_offsets = wctx.text_buffer.getWrapOffsetsFor(chunk) catch &[_]utf8.WrapBreak{};
1094
- const is_ascii_only = (chunk.flags & TextChunk.Flags.ASCII_ONLY) != 0;
1095
- const graphemes: []const GraphemeInfo = if (is_ascii_only)
1096
- &[_]GraphemeInfo{}
1097
- else
1098
- chunk.getGraphemes(wctx.text_buffer.memRegistry(), wctx.text_buffer.getAllocator(), wctx.text_buffer.tabWidth(), wctx.text_buffer.widthMethod()) catch &[_]GraphemeInfo{};
1099
- var grapheme_idx: usize = 0;
1100
- var col_delta: i64 = 0;
1101
-
1102
- // char_offset tracks COLUMN position within the chunk (not grapheme count)
1103
- // chunk.width is also in columns. The loop processes the chunk column by column.
1104
- var char_offset: u32 = 0; // Column offset within chunk
1105
- var byte_offset: u32 = 0;
1106
- var wrap_idx: usize = 0;
1107
-
1108
- while (char_offset < chunk.width) {
1109
- const remaining_in_chunk = chunk.width - char_offset;
1110
- const remaining_on_line = if (wctx.line_position < wctx.wrap_w) wctx.wrap_w - wctx.line_position else 0;
1111
-
1112
- var last_wrap_that_fits: ?u32 = null;
1113
- var saved_wrap_idx = wrap_idx;
1114
- while (wrap_idx < wrap_offsets.len) : (wrap_idx += 1) {
1115
- const wrap_break = wrap_offsets[wrap_idx];
1116
-
1117
- const break_info = iter_mod.charOffsetToColumn(wrap_break.char_offset, graphemes, &grapheme_idx, &col_delta);
1118
- const break_col = break_info.col;
1119
-
1120
- // Skip breaks that are before our current column position in the chunk
1121
- if (break_col < char_offset) continue;
1122
-
1123
- // width_to_boundary: columns needed to reach and include this break
1124
- // break_col is the column where the break character starts (relative to chunk)
1125
- // char_offset is our current column position (relative to chunk)
1126
- // To include the break character, we need: break_col - char_offset + width
1127
- const width_to_boundary = break_col - char_offset + break_info.width;
1128
- if (width_to_boundary > remaining_on_line or width_to_boundary > remaining_in_chunk) {
1129
- break;
1130
- }
1131
- last_wrap_that_fits = width_to_boundary;
1132
- saved_wrap_idx = wrap_idx + 1;
1133
- }
1134
- wrap_idx = saved_wrap_idx;
1135
-
1136
- var to_add: u32 = 0;
1137
- var has_wrap_after: bool = false;
1138
-
1139
- if (remaining_in_chunk <= remaining_on_line) {
1140
- if (last_wrap_that_fits) |boundary_w| {
1141
- const would_fill_line = wctx.line_position + remaining_in_chunk >= wctx.wrap_w;
1142
- if (would_fill_line and boundary_w < remaining_in_chunk) {
1143
- to_add = boundary_w;
1144
- has_wrap_after = true;
1145
- } else {
1146
- to_add = remaining_in_chunk;
1147
- has_wrap_after = true;
1148
- }
1149
- } else {
1150
- to_add = remaining_in_chunk;
1151
- }
1152
- } else if (last_wrap_that_fits) |boundary_w| {
1153
- to_add = boundary_w;
1154
- has_wrap_after = true;
1155
- } else if (wctx.line_position == 0) {
1156
- // Use tracked byte_offset instead of recalculating from scratch (avoids O(n²))
1157
- const remaining_bytes = chunk_bytes[byte_offset..];
1158
- const wrap_result = utf8.findWrapPosByWidth(remaining_bytes, remaining_on_line, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1159
- to_add = wrap_result.columns_used;
1160
- byte_offset += wrap_result.byte_offset;
1161
- if (to_add == 0) {
1162
- to_add = 1;
1163
- const single_result = utf8.findWrapPosByWidth(remaining_bytes, 1, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1164
- byte_offset += single_result.byte_offset;
1165
- }
1166
- } else if (wctx.last_wrap_chunk_count > 0 and
1167
- wctx.last_wrap_chunk_count <= wctx.current_vline.chunks.items.len)
1168
- {
1169
- var accumulated_width: u32 = 0;
1170
- for (wctx.current_vline.chunks.items[0..wctx.last_wrap_chunk_count]) |vchunk| {
1171
- accumulated_width += vchunk.width;
1172
- }
1173
-
1174
- const chunks_after_wrap = wctx.current_vline.chunks.items[wctx.last_wrap_chunk_count..];
1175
- var chunks_to_move_count = chunks_after_wrap.len;
1176
- var split_chunk: ?VirtualChunk = null;
1177
-
1178
- if (accumulated_width > wctx.last_wrap_line_position) {
1179
- const last_chunk_idx = wctx.last_wrap_chunk_count - 1;
1180
- const last_chunk = wctx.current_vline.chunks.items[last_chunk_idx];
1181
- const overhang = accumulated_width - wctx.last_wrap_line_position;
1182
-
1183
- split_chunk = VirtualChunk{
1184
- .grapheme_start = last_chunk.grapheme_start + last_chunk.width - overhang,
1185
- .width = overhang,
1186
- .chunk = last_chunk.chunk,
1187
- };
1188
-
1189
- wctx.current_vline.chunks.items[last_chunk_idx].width -= overhang;
1190
-
1191
- chunks_to_move_count += 1;
1192
- }
1193
-
1194
- const saved_chunks_result = wctx.allocator.alloc(VirtualChunk, chunks_to_move_count);
1195
- if (saved_chunks_result) |saved_chunks| {
1196
- var saved_idx: usize = 0;
1197
-
1198
- if (split_chunk) |sc| {
1199
- saved_chunks[saved_idx] = sc;
1200
- saved_idx += 1;
1201
- }
1202
-
1203
- @memcpy(saved_chunks[saved_idx..], chunks_after_wrap);
1204
-
1205
- wctx.line_position = wctx.last_wrap_line_position;
1206
- wctx.global_char_offset = wctx.last_wrap_global_offset;
1207
- wctx.current_vline.chunks.items.len = wctx.last_wrap_chunk_count;
1208
-
1209
- commitVirtualLine(wctx);
1210
-
1211
- for (saved_chunks) |vchunk| {
1212
- wctx.current_vline.chunks.append(wctx.allocator, vchunk) catch {};
1213
- wctx.global_char_offset += vchunk.width;
1214
- wctx.line_position += vchunk.width;
1215
- }
1216
- } else |_| {
1217
- commitVirtualLine(wctx);
1218
- }
1219
-
1220
- continue;
1221
- } else {
1222
- commitVirtualLine(wctx);
1223
- if (char_offset > 0) {
1224
- const pos_result = utf8.findPosByWidth(chunk_bytes, char_offset, wctx.text_buffer.tabWidth(), is_ascii_only, false, wctx.text_buffer.widthMethod());
1225
- byte_offset = pos_result.byte_offset;
1226
- }
1227
- const remaining_bytes = chunk_bytes[byte_offset..];
1228
- const wrap_result = utf8.findWrapPosByWidth(remaining_bytes, wctx.wrap_w, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1229
- to_add = wrap_result.columns_used;
1230
- byte_offset += wrap_result.byte_offset;
1231
- if (to_add == 0) {
1232
- to_add = 1;
1233
- const single_result = utf8.findWrapPosByWidth(remaining_bytes, 1, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1234
- byte_offset += single_result.byte_offset;
1235
- }
1236
- }
1237
-
1238
- if (to_add > 0) {
1239
- const position_before_add = wctx.line_position;
1240
- const offset_before_add = wctx.global_char_offset;
1241
-
1242
- addVirtualChunk(wctx, chunk, chunk_idx_in_line, char_offset, to_add);
1243
- char_offset += to_add;
1244
-
1245
- if (has_wrap_after) {
1246
- const wrap_pos_in_added = if (last_wrap_that_fits) |boundary_w|
1247
- @min(boundary_w, to_add)
1248
- else
1249
- to_add;
1250
-
1251
- wctx.last_wrap_chunk_count = @intCast(wctx.current_vline.chunks.items.len);
1252
- wctx.last_wrap_line_position = position_before_add + wrap_pos_in_added;
1253
- wctx.last_wrap_global_offset = offset_before_add + wrap_pos_in_added;
1254
- }
1255
-
1256
- if (wctx.line_position >= wctx.wrap_w and char_offset < chunk.width) {
1257
- if (has_wrap_after or wctx.last_wrap_chunk_count > 0) {
1258
- commitVirtualLine(wctx);
1259
- }
1260
- }
1261
- }
1262
- }
1263
- } else {
1264
- const chunk_bytes = chunk.getBytes(wctx.text_buffer.memRegistry());
1265
- const is_ascii_only = (chunk.flags & TextChunk.Flags.ASCII_ONLY) != 0;
1266
- var byte_offset: usize = 0;
1267
- var char_offset: u32 = 0;
1268
-
1269
- while (char_offset < chunk.width) {
1270
- const remaining_width = if (wctx.line_position < wctx.wrap_w) wctx.wrap_w - wctx.line_position else 0;
1271
-
1272
- if (remaining_width == 0) {
1273
- if (wctx.line_position > 0) {
1274
- commitVirtualLine(wctx);
1275
- continue;
1276
- }
1277
- const remaining_bytes = chunk_bytes[byte_offset..];
1278
- const force_result = utf8.findWrapPosByWidth(remaining_bytes, 1, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1279
- if (force_result.grapheme_count > 0) {
1280
- addVirtualChunk(wctx, chunk, chunk_idx_in_line, char_offset, force_result.columns_used);
1281
- char_offset += force_result.columns_used;
1282
- byte_offset += force_result.byte_offset;
1283
- } else {
1284
- break;
1285
- }
1286
- continue;
1287
- }
1288
-
1289
- const remaining_bytes = chunk_bytes[byte_offset..];
1290
- const wrap_result = utf8.findWrapPosByWidth(
1291
- remaining_bytes,
1292
- remaining_width,
1293
- wctx.text_buffer.tabWidth(),
1294
- is_ascii_only,
1295
- wctx.text_buffer.widthMethod(),
1296
- );
1297
-
1298
- if (wrap_result.grapheme_count == 0) {
1299
- if (wctx.line_position > 0) {
1300
- commitVirtualLine(wctx);
1301
- continue;
1302
- }
1303
- const force_result = utf8.findWrapPosByWidth(remaining_bytes, 1000, wctx.text_buffer.tabWidth(), is_ascii_only, wctx.text_buffer.widthMethod());
1304
- if (force_result.grapheme_count > 0) {
1305
- addVirtualChunk(wctx, chunk, chunk_idx_in_line, char_offset, force_result.columns_used);
1306
- char_offset += force_result.columns_used;
1307
- byte_offset += force_result.byte_offset;
1308
- if (char_offset < chunk.width) {
1309
- commitVirtualLine(wctx);
1310
- }
1311
- }
1312
- break;
1313
- }
1314
-
1315
- addVirtualChunk(wctx, chunk, chunk_idx_in_line, char_offset, wrap_result.columns_used);
1316
- char_offset += wrap_result.columns_used;
1317
- byte_offset += wrap_result.byte_offset;
1318
-
1319
- if (wctx.line_position >= wctx.wrap_w and char_offset < chunk.width) {
1320
- commitVirtualLine(wctx);
1321
- }
1322
- }
1323
- }
1324
- }
1325
-
1326
- fn line_end_callback(ctx_ptr: *anyopaque, line_info: iter_mod.LineInfo) void {
1327
- const wctx = @as(*@This(), @ptrCast(@alignCast(ctx_ptr)));
1328
-
1329
- if (wctx.current_vline.chunks.items.len > 0 or line_info.width_cols == 0) {
1330
- wctx.current_vline.width_cols = wctx.line_position;
1331
- wctx.current_vline.source_line = wctx.line_idx;
1332
- wctx.current_vline.source_col_offset = wctx.line_col_offset;
1333
- wctx.output.virtual_lines.append(wctx.allocator, wctx.current_vline) catch {};
1334
- wctx.output.cached_line_starts.append(wctx.allocator, wctx.current_vline.col_offset) catch {};
1335
- wctx.output.cached_line_widths.append(wctx.allocator, wctx.current_vline.width_cols) catch {};
1336
- wctx.output.cached_line_sources.append(wctx.allocator, wctx.line_idx) catch {};
1337
- wctx.output.cached_line_wrap_indices.append(wctx.allocator, wctx.current_line_vline_count) catch {};
1338
- wctx.current_line_vline_count += 1;
1339
- }
1340
-
1341
- wctx.output.cached_line_first_vline.append(wctx.allocator, wctx.current_line_first_vline_idx) catch {};
1342
- wctx.output.cached_line_vline_counts.append(wctx.allocator, wctx.current_line_vline_count) catch {};
1343
-
1344
- wctx.global_char_offset += 1;
1345
-
1346
- wctx.line_idx += 1;
1347
- wctx.line_col_offset = 0;
1348
- wctx.line_position = 0;
1349
- wctx.current_vline = VirtualLine.init();
1350
- wctx.current_vline.col_offset = wctx.global_char_offset;
1351
- wctx.last_wrap_chunk_count = 0;
1352
- wctx.last_wrap_line_position = 0;
1353
- wctx.last_wrap_global_offset = 0;
1354
- wctx.chunk_idx_in_line = 0;
1355
- wctx.current_line_first_vline_idx = @intCast(wctx.output.virtual_lines.items.len);
1356
- wctx.current_line_vline_count = 0;
1357
- }
1358
- };
1359
-
1360
- var wrap_ctx = WrapContext{
1361
- .text_buffer = text_buffer,
1362
- .allocator = allocator,
1363
- .output = output,
1364
- .wrap_mode = wrap_mode,
1365
- .wrap_w = wrap_w,
1366
- };
1367
-
1368
- text_buffer.walkLinesAndSegments(&wrap_ctx, WrapContext.segment_callback, WrapContext.line_end_callback);
1369
- }
1370
- }
1371
- };