@xincli/opentui-core 0.4.6 → 0.4.7

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