@fairyhunter13/opentui-core 0.1.112 → 0.1.114
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.
- package/dev/keypress-debug-renderer.ts +148 -0
- package/dev/keypress-debug.ts +43 -0
- package/dev/print-env-vars.ts +32 -0
- package/dev/test-tmux-graphics-334.sh +68 -0
- package/dev/thai-debug-test.ts +68 -0
- package/docs/development.md +144 -0
- package/package.json +63 -51
- package/scripts/build.ts +400 -0
- package/scripts/publish.ts +60 -0
- package/src/3d/SpriteResourceManager.ts +286 -0
- package/src/3d/SpriteUtils.ts +70 -0
- package/src/3d/TextureUtils.ts +196 -0
- package/src/3d/ThreeRenderable.ts +197 -0
- package/src/3d/WGPURenderer.ts +294 -0
- package/src/3d/animation/ExplodingSpriteEffect.ts +513 -0
- package/src/3d/animation/PhysicsExplodingSpriteEffect.ts +429 -0
- package/src/3d/animation/SpriteAnimator.ts +633 -0
- package/src/3d/animation/SpriteParticleGenerator.ts +435 -0
- package/src/3d/canvas.ts +464 -0
- package/src/3d/index.ts +12 -0
- package/src/3d/physics/PlanckPhysicsAdapter.ts +72 -0
- package/src/3d/physics/RapierPhysicsAdapter.ts +66 -0
- package/src/3d/physics/physics-interface.ts +31 -0
- package/src/3d/shaders/supersampling.wgsl +201 -0
- package/src/3d.ts +3 -0
- package/src/NativeSpanFeed.ts +300 -0
- package/src/Renderable.ts +1704 -0
- package/src/__snapshots__/buffer.test.ts.snap +28 -0
- package/src/animation/Timeline.test.ts +2709 -0
- package/src/animation/Timeline.ts +598 -0
- package/src/ansi.ts +18 -0
- package/src/benchmark/attenuation-benchmark.ts +81 -0
- package/src/benchmark/colormatrix-benchmark.ts +128 -0
- package/src/benchmark/gain-benchmark.ts +80 -0
- package/src/benchmark/latest-all-bench-run.json +707 -0
- package/src/benchmark/latest-async-bench-run.json +336 -0
- package/src/benchmark/latest-default-bench-run.json +657 -0
- package/src/benchmark/latest-large-bench-run.json +707 -0
- package/src/benchmark/latest-quick-bench-run.json +207 -0
- package/src/benchmark/markdown-benchmark.ts +1796 -0
- package/src/benchmark/native-span-feed-async-benchmark.ts +355 -0
- package/src/benchmark/native-span-feed-benchmark.md +56 -0
- package/src/benchmark/native-span-feed-benchmark.ts +596 -0
- package/src/benchmark/native-span-feed-compare.ts +280 -0
- package/src/benchmark/renderer-benchmark.ts +754 -0
- package/src/benchmark/text-table-benchmark.ts +948 -0
- package/src/buffer.test.ts +291 -0
- package/src/buffer.ts +554 -0
- package/src/console.test.ts +612 -0
- package/src/console.ts +1254 -0
- package/src/edit-buffer.test.ts +1769 -0
- package/src/edit-buffer.ts +411 -0
- package/src/editor-view.test.ts +1032 -0
- package/src/editor-view.ts +284 -0
- package/src/examples/ascii-font-selection-demo.ts +245 -0
- package/src/examples/assets/Water_2_M_Normal.jpg +0 -0
- package/src/examples/assets/concrete.png +0 -0
- package/src/examples/assets/crate.png +0 -0
- package/src/examples/assets/crate_emissive.png +0 -0
- package/src/examples/assets/forrest_background.png +0 -0
- package/src/examples/assets/hast-example.json +1018 -0
- package/src/examples/assets/heart.png +0 -0
- package/src/examples/assets/main_char_heavy_attack.png +0 -0
- package/src/examples/assets/main_char_idle.png +0 -0
- package/src/examples/assets/main_char_jump_end.png +0 -0
- package/src/examples/assets/main_char_jump_landing.png +0 -0
- package/src/examples/assets/main_char_jump_start.png +0 -0
- package/src/examples/assets/main_char_run_loop.png +0 -0
- package/src/examples/assets/roughness_map.jpg +0 -0
- package/src/examples/build.ts +115 -0
- package/src/examples/code-demo.ts +924 -0
- package/src/examples/console-demo.ts +358 -0
- package/src/examples/core-plugin-slots-demo.ts +759 -0
- package/src/examples/diff-demo.ts +701 -0
- package/src/examples/draggable-three-demo.ts +259 -0
- package/src/examples/editor-demo.ts +322 -0
- package/src/examples/extmarks-demo.ts +196 -0
- package/src/examples/focus-restore-demo.ts +310 -0
- package/src/examples/fonts.ts +245 -0
- package/src/examples/fractal-shader-demo.ts +268 -0
- package/src/examples/framebuffer-demo.ts +674 -0
- package/src/examples/full-unicode-demo.ts +241 -0
- package/src/examples/golden-star-demo.ts +933 -0
- package/src/examples/grayscale-buffer-demo.ts +249 -0
- package/src/examples/hast-syntax-highlighting-demo.ts +129 -0
- package/src/examples/index.ts +926 -0
- package/src/examples/input-demo.ts +377 -0
- package/src/examples/input-select-layout-demo.ts +425 -0
- package/src/examples/install.sh +143 -0
- package/src/examples/keypress-debug-demo.ts +452 -0
- package/src/examples/lib/HexList.ts +122 -0
- package/src/examples/lib/PaletteGrid.ts +125 -0
- package/src/examples/lib/standalone-keys.ts +25 -0
- package/src/examples/lib/tab-controller.ts +243 -0
- package/src/examples/lights-phong-demo.ts +290 -0
- package/src/examples/link-demo.ts +220 -0
- package/src/examples/live-state-demo.ts +480 -0
- package/src/examples/markdown-demo.ts +725 -0
- package/src/examples/mouse-interaction-demo.ts +428 -0
- package/src/examples/nested-zindex-demo.ts +357 -0
- package/src/examples/opacity-example.ts +235 -0
- package/src/examples/opentui-demo.ts +1057 -0
- package/src/examples/physx-planck-2d-demo.ts +623 -0
- package/src/examples/physx-rapier-2d-demo.ts +655 -0
- package/src/examples/relative-positioning-demo.ts +323 -0
- package/src/examples/scroll-example.ts +214 -0
- package/src/examples/scrollbox-mouse-test.ts +112 -0
- package/src/examples/scrollbox-overlay-hit-test.ts +206 -0
- package/src/examples/select-demo.ts +237 -0
- package/src/examples/shader-cube-demo.ts +1015 -0
- package/src/examples/simple-layout-example.ts +591 -0
- package/src/examples/slider-demo.ts +617 -0
- package/src/examples/split-mode-demo.ts +453 -0
- package/src/examples/sprite-animation-demo.ts +443 -0
- package/src/examples/sprite-particle-generator-demo.ts +486 -0
- package/src/examples/static-sprite-demo.ts +193 -0
- package/src/examples/sticky-scroll-example.ts +308 -0
- package/src/examples/styled-text-demo.ts +282 -0
- package/src/examples/tab-select-demo.ts +219 -0
- package/src/examples/terminal-title.ts +29 -0
- package/src/examples/terminal.ts +305 -0
- package/src/examples/text-node-demo.ts +416 -0
- package/src/examples/text-selection-demo.ts +377 -0
- package/src/examples/text-table-demo.ts +503 -0
- package/src/examples/text-truncation-demo.ts +481 -0
- package/src/examples/text-wrap.ts +757 -0
- package/src/examples/texture-loading-demo.ts +259 -0
- package/src/examples/timeline-example.ts +670 -0
- package/src/examples/transparency-demo.ts +400 -0
- package/src/examples/vnode-composition-demo.ts +404 -0
- package/src/examples/wide-grapheme-overlay-demo.ts +280 -0
- package/src/index.ts +24 -0
- package/src/lib/KeyHandler.integration.test.ts +292 -0
- package/src/lib/KeyHandler.stopPropagation.test.ts +289 -0
- package/src/lib/KeyHandler.test.ts +662 -0
- package/src/lib/KeyHandler.ts +222 -0
- package/src/lib/RGBA.test.ts +984 -0
- package/src/lib/RGBA.ts +204 -0
- package/src/lib/ascii.font.ts +330 -0
- package/src/lib/border.test.ts +83 -0
- package/src/lib/border.ts +170 -0
- package/src/lib/bunfs.test.ts +27 -0
- package/src/lib/bunfs.ts +18 -0
- package/src/lib/clipboard.test.ts +41 -0
- package/src/lib/clipboard.ts +47 -0
- package/src/lib/clock.ts +35 -0
- package/src/lib/data-paths.test.ts +133 -0
- package/src/lib/data-paths.ts +109 -0
- package/src/lib/debounce.ts +106 -0
- package/src/lib/detect-links.test.ts +98 -0
- package/src/lib/detect-links.ts +56 -0
- package/src/lib/env.test.ts +228 -0
- package/src/lib/env.ts +209 -0
- package/src/lib/extmarks-history.ts +51 -0
- package/src/lib/extmarks-multiwidth.test.ts +322 -0
- package/src/lib/extmarks.test.ts +3457 -0
- package/src/lib/extmarks.ts +843 -0
- package/src/lib/fonts/block.json +405 -0
- package/src/lib/fonts/grid.json +265 -0
- package/src/lib/fonts/huge.json +741 -0
- package/src/lib/fonts/pallet.json +314 -0
- package/src/lib/fonts/shade.json +591 -0
- package/src/lib/fonts/slick.json +321 -0
- package/src/lib/fonts/tiny.json +69 -0
- package/src/lib/hast-styled-text.ts +59 -0
- package/src/lib/index.ts +21 -0
- package/src/lib/keymapping.test.ts +317 -0
- package/src/lib/keymapping.ts +115 -0
- package/src/lib/objects-in-viewport.test.ts +787 -0
- package/src/lib/objects-in-viewport.ts +153 -0
- package/src/lib/output.capture.ts +58 -0
- package/src/lib/parse.keypress-kitty.protocol.test.ts +340 -0
- package/src/lib/parse.keypress-kitty.test.ts +663 -0
- package/src/lib/parse.keypress-kitty.ts +439 -0
- package/src/lib/parse.keypress.test.ts +1849 -0
- package/src/lib/parse.keypress.ts +397 -0
- package/src/lib/parse.mouse.test.ts +552 -0
- package/src/lib/parse.mouse.ts +232 -0
- package/src/lib/paste.ts +16 -0
- package/src/lib/queue.ts +65 -0
- package/src/lib/renderable.validations.test.ts +87 -0
- package/src/lib/renderable.validations.ts +83 -0
- package/src/lib/scroll-acceleration.ts +98 -0
- package/src/lib/selection.ts +240 -0
- package/src/lib/singleton.ts +28 -0
- package/src/lib/stdin-parser.test.ts +2290 -0
- package/src/lib/stdin-parser.ts +1810 -0
- package/src/lib/styled-text.ts +178 -0
- package/src/lib/terminal-capability-detection.test.ts +202 -0
- package/src/lib/terminal-capability-detection.ts +79 -0
- package/src/lib/terminal-palette.test.ts +878 -0
- package/src/lib/terminal-palette.ts +383 -0
- package/src/lib/tree-sitter/assets/README.md +118 -0
- package/src/lib/tree-sitter/assets/update.ts +334 -0
- package/src/lib/tree-sitter/assets.d.ts +9 -0
- package/src/lib/tree-sitter/cache.test.ts +273 -0
- package/src/lib/tree-sitter/client.test.ts +1165 -0
- package/src/lib/tree-sitter/client.ts +607 -0
- package/src/lib/tree-sitter/default-parsers.ts +86 -0
- package/src/lib/tree-sitter/download-utils.ts +148 -0
- package/src/lib/tree-sitter/index.ts +28 -0
- package/src/lib/tree-sitter/parser.worker.ts +1042 -0
- package/src/lib/tree-sitter/parsers-config.ts +81 -0
- package/src/lib/tree-sitter/resolve-ft.test.ts +55 -0
- package/src/lib/tree-sitter/resolve-ft.ts +189 -0
- package/src/lib/tree-sitter/types.ts +82 -0
- package/src/lib/tree-sitter-styled-text.test.ts +1253 -0
- package/src/lib/tree-sitter-styled-text.ts +306 -0
- package/src/lib/validate-dir-name.ts +55 -0
- package/src/lib/yoga.options.test.ts +628 -0
- package/src/lib/yoga.options.ts +346 -0
- package/src/plugins/core-slot.ts +579 -0
- package/src/plugins/registry.ts +402 -0
- package/src/plugins/types.ts +46 -0
- package/src/post/effects.ts +930 -0
- package/src/post/filters.ts +489 -0
- package/src/post/matrices.ts +288 -0
- package/src/renderables/ASCIIFont.ts +219 -0
- package/src/renderables/Box.test.ts +205 -0
- package/src/renderables/Box.ts +326 -0
- package/src/renderables/Code.test.ts +2062 -0
- package/src/renderables/Code.ts +357 -0
- package/src/renderables/Diff.regression.test.ts +226 -0
- package/src/renderables/Diff.test.ts +3101 -0
- package/src/renderables/Diff.ts +1211 -0
- package/src/renderables/EditBufferRenderable.test.ts +288 -0
- package/src/renderables/EditBufferRenderable.ts +1166 -0
- package/src/renderables/FrameBuffer.ts +47 -0
- package/src/renderables/Input.test.ts +1228 -0
- package/src/renderables/Input.ts +247 -0
- package/src/renderables/LineNumberRenderable.ts +724 -0
- package/src/renderables/Markdown.ts +1393 -0
- package/src/renderables/ScrollBar.ts +422 -0
- package/src/renderables/ScrollBox.ts +883 -0
- package/src/renderables/Select.test.ts +1033 -0
- package/src/renderables/Select.ts +524 -0
- package/src/renderables/Slider.test.ts +456 -0
- package/src/renderables/Slider.ts +342 -0
- package/src/renderables/TabSelect.test.ts +197 -0
- package/src/renderables/TabSelect.ts +455 -0
- package/src/renderables/Text.selection-buffer.test.ts +123 -0
- package/src/renderables/Text.test.ts +2660 -0
- package/src/renderables/Text.ts +147 -0
- package/src/renderables/TextBufferRenderable.ts +518 -0
- package/src/renderables/TextNode.test.ts +1058 -0
- package/src/renderables/TextNode.ts +325 -0
- package/src/renderables/TextTable.test.ts +1421 -0
- package/src/renderables/TextTable.ts +1344 -0
- package/src/renderables/Textarea.ts +430 -0
- package/src/renderables/TimeToFirstDraw.ts +89 -0
- package/src/renderables/__snapshots__/Code.test.ts.snap +13 -0
- package/src/renderables/__snapshots__/Diff.test.ts.snap +785 -0
- package/src/renderables/__snapshots__/Text.test.ts.snap +421 -0
- package/src/renderables/__snapshots__/TextTable.test.ts.snap +215 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox-simple.test.ts +144 -0
- package/src/renderables/__tests__/LineNumberRenderable.scrollbox.test.ts +816 -0
- package/src/renderables/__tests__/LineNumberRenderable.test.ts +1865 -0
- package/src/renderables/__tests__/LineNumberRenderable.wrapping.test.ts +85 -0
- package/src/renderables/__tests__/Markdown.code-colors.test.ts +242 -0
- package/src/renderables/__tests__/Markdown.test.ts +2518 -0
- package/src/renderables/__tests__/MultiRenderable.selection.test.ts +87 -0
- package/src/renderables/__tests__/Textarea.buffer.test.ts +682 -0
- package/src/renderables/__tests__/Textarea.destroyed-events.test.ts +675 -0
- package/src/renderables/__tests__/Textarea.editing.test.ts +2041 -0
- package/src/renderables/__tests__/Textarea.error-handling.test.ts +35 -0
- package/src/renderables/__tests__/Textarea.events.test.ts +738 -0
- package/src/renderables/__tests__/Textarea.highlights.test.ts +590 -0
- package/src/renderables/__tests__/Textarea.keybinding.test.ts +3149 -0
- package/src/renderables/__tests__/Textarea.paste.test.ts +357 -0
- package/src/renderables/__tests__/Textarea.rendering.test.ts +1866 -0
- package/src/renderables/__tests__/Textarea.scroll.test.ts +733 -0
- package/src/renderables/__tests__/Textarea.selection.test.ts +1590 -0
- package/src/renderables/__tests__/Textarea.stress.test.ts +670 -0
- package/src/renderables/__tests__/Textarea.undo-redo.test.ts +383 -0
- package/src/renderables/__tests__/Textarea.visual-lines.test.ts +310 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.code.test.ts.snap +221 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox-simple.test.ts.snap +89 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.scrollbox.test.ts.snap +457 -0
- package/src/renderables/__tests__/__snapshots__/LineNumberRenderable.test.ts.snap +158 -0
- package/src/renderables/__tests__/__snapshots__/Textarea.rendering.test.ts.snap +387 -0
- package/src/renderables/__tests__/markdown-parser.test.ts +217 -0
- package/src/renderables/__tests__/renderable-test-utils.ts +60 -0
- package/src/renderables/composition/README.md +8 -0
- package/src/renderables/composition/VRenderable.ts +32 -0
- package/src/renderables/composition/constructs.ts +127 -0
- package/src/renderables/composition/vnode.ts +289 -0
- package/src/renderables/index.ts +23 -0
- package/src/renderables/markdown-parser.ts +66 -0
- package/src/renderer.ts +2681 -0
- package/src/runtime-plugin-support.ts +39 -0
- package/src/runtime-plugin.ts +615 -0
- package/src/syntax-style.test.ts +841 -0
- package/src/syntax-style.ts +257 -0
- package/src/testing/README.md +210 -0
- package/src/testing/capture-spans.test.ts +194 -0
- package/src/testing/integration.test.ts +276 -0
- package/src/testing/manual-clock.ts +117 -0
- package/src/testing/mock-keys.test.ts +1378 -0
- package/src/testing/mock-keys.ts +457 -0
- package/src/testing/mock-mouse.test.ts +218 -0
- package/src/testing/mock-mouse.ts +247 -0
- package/src/testing/mock-tree-sitter-client.ts +73 -0
- package/src/testing/spy.ts +13 -0
- package/src/testing/test-recorder.test.ts +415 -0
- package/src/testing/test-recorder.ts +145 -0
- package/src/testing/test-renderer.ts +132 -0
- package/src/testing.ts +7 -0
- package/src/tests/__snapshots__/absolute-positioning.snapshot.test.ts.snap +481 -0
- package/src/tests/__snapshots__/renderable.snapshot.test.ts.snap +19 -0
- package/src/tests/__snapshots__/scrollbox.test.ts.snap +29 -0
- package/src/tests/absolute-positioning.snapshot.test.ts +638 -0
- package/src/tests/allocator-stats.test.ts +38 -0
- package/src/tests/destroy-during-render.test.ts +200 -0
- package/src/tests/destroy-on-exit.fixture.ts +36 -0
- package/src/tests/destroy-on-exit.test.ts +41 -0
- package/src/tests/hover-cursor.test.ts +98 -0
- package/src/tests/native-span-feed-async.test.ts +173 -0
- package/src/tests/native-span-feed-close.test.ts +120 -0
- package/src/tests/native-span-feed-coverage.test.ts +227 -0
- package/src/tests/native-span-feed-edge-cases.test.ts +352 -0
- package/src/tests/native-span-feed-use-after-free.test.ts +45 -0
- package/src/tests/opacity.test.ts +123 -0
- package/src/tests/renderable.snapshot.test.ts +524 -0
- package/src/tests/renderable.test.ts +1281 -0
- package/src/tests/renderer.clock.test.ts +158 -0
- package/src/tests/renderer.console-startup.test.ts +185 -0
- package/src/tests/renderer.control.test.ts +425 -0
- package/src/tests/renderer.core-slot-binding.test.ts +952 -0
- package/src/tests/renderer.cursor.test.ts +26 -0
- package/src/tests/renderer.destroy-during-render.test.ts +147 -0
- package/src/tests/renderer.focus-restore.test.ts +257 -0
- package/src/tests/renderer.focus.test.ts +294 -0
- package/src/tests/renderer.idle.test.ts +219 -0
- package/src/tests/renderer.input.test.ts +2237 -0
- package/src/tests/renderer.kitty-flags.test.ts +195 -0
- package/src/tests/renderer.mouse.test.ts +1274 -0
- package/src/tests/renderer.palette.test.ts +629 -0
- package/src/tests/renderer.selection.test.ts +49 -0
- package/src/tests/renderer.slot-registry.test.ts +684 -0
- package/src/tests/renderer.useMouse.test.ts +47 -0
- package/src/tests/runtime-plugin-node-modules-cycle.fixture.ts +76 -0
- package/src/tests/runtime-plugin-node-modules-mjs.fixture.ts +43 -0
- package/src/tests/runtime-plugin-node-modules-no-bare-rewrite.fixture.ts +67 -0
- package/src/tests/runtime-plugin-node-modules-package-type-cache.fixture.ts +72 -0
- package/src/tests/runtime-plugin-node-modules-runtime-specifier.fixture.ts +44 -0
- package/src/tests/runtime-plugin-node-modules-scoped-package-bare-rewrite.fixture.ts +85 -0
- package/src/tests/runtime-plugin-path-alias.fixture.ts +43 -0
- package/src/tests/runtime-plugin-resolve-roots.fixture.ts +65 -0
- package/src/tests/runtime-plugin-support.fixture.ts +11 -0
- package/src/tests/runtime-plugin-support.test.ts +19 -0
- package/src/tests/runtime-plugin-windows-file-url.fixture.ts +30 -0
- package/src/tests/runtime-plugin.fixture.ts +40 -0
- package/src/tests/runtime-plugin.test.ts +354 -0
- package/src/tests/scrollbox-culling-bug.test.ts +114 -0
- package/src/tests/scrollbox-hitgrid-resize.test.ts +136 -0
- package/src/tests/scrollbox-hitgrid.test.ts +909 -0
- package/src/tests/scrollbox.test.ts +1530 -0
- package/src/tests/wrap-resize-perf.test.ts +276 -0
- package/src/tests/yoga-setters.test.ts +921 -0
- package/src/text-buffer-view.test.ts +705 -0
- package/src/text-buffer-view.ts +189 -0
- package/src/text-buffer.test.ts +347 -0
- package/src/text-buffer.ts +250 -0
- package/src/types.ts +161 -0
- package/src/utils.ts +88 -0
- package/src/zig/ansi.zig +268 -0
- package/src/zig/bench/README.md +50 -0
- package/src/zig/bench/buffer-draw-text-buffer_bench.zig +887 -0
- package/src/zig/bench/edit-buffer_bench.zig +476 -0
- package/src/zig/bench/native-span-feed_bench.zig +100 -0
- package/src/zig/bench/rope-markers_bench.zig +713 -0
- package/src/zig/bench/rope_bench.zig +514 -0
- package/src/zig/bench/styled-text_bench.zig +470 -0
- package/src/zig/bench/text-buffer-coords_bench.zig +362 -0
- package/src/zig/bench/text-buffer-view_bench.zig +459 -0
- package/src/zig/bench/text-chunk-graphemes_bench.zig +273 -0
- package/src/zig/bench/utf8_bench.zig +799 -0
- package/src/zig/bench-utils.zig +431 -0
- package/src/zig/bench.zig +217 -0
- package/src/zig/buffer-methods.zig +211 -0
- package/src/zig/buffer.zig +2281 -0
- package/src/zig/build.zig +289 -0
- package/src/zig/build.zig.zon +16 -0
- package/src/zig/edit-buffer.zig +825 -0
- package/src/zig/editor-view.zig +802 -0
- package/src/zig/event-bus.zig +13 -0
- package/src/zig/event-emitter.zig +65 -0
- package/src/zig/file-logger.zig +92 -0
- package/src/zig/grapheme.zig +599 -0
- package/src/zig/lib.zig +1854 -0
- package/src/zig/link.zig +333 -0
- package/src/zig/logger.zig +43 -0
- package/src/zig/mem-registry.zig +125 -0
- package/src/zig/native-span-feed-bench-lib.zig +7 -0
- package/src/zig/native-span-feed.zig +708 -0
- package/src/zig/renderer.zig +1393 -0
- package/src/zig/rope.zig +1220 -0
- package/src/zig/syntax-style.zig +161 -0
- package/src/zig/terminal.zig +987 -0
- package/src/zig/test.zig +72 -0
- package/src/zig/tests/README.md +18 -0
- package/src/zig/tests/buffer-methods_test.zig +1109 -0
- package/src/zig/tests/buffer_test.zig +2557 -0
- package/src/zig/tests/edit-buffer-history_test.zig +271 -0
- package/src/zig/tests/edit-buffer_test.zig +1689 -0
- package/src/zig/tests/editor-view_test.zig +3299 -0
- package/src/zig/tests/event-emitter_test.zig +249 -0
- package/src/zig/tests/grapheme_test.zig +1304 -0
- package/src/zig/tests/link_test.zig +190 -0
- package/src/zig/tests/mem-registry_test.zig +473 -0
- package/src/zig/tests/memory_leak_regression_test.zig +159 -0
- package/src/zig/tests/native-span-feed_test.zig +1264 -0
- package/src/zig/tests/renderer_test.zig +1017 -0
- package/src/zig/tests/rope-nested_test.zig +712 -0
- package/src/zig/tests/rope_fuzz_test.zig +238 -0
- package/src/zig/tests/rope_test.zig +2362 -0
- package/src/zig/tests/segment-merge.test.zig +148 -0
- package/src/zig/tests/syntax-style_test.zig +557 -0
- package/src/zig/tests/terminal_test.zig +754 -0
- package/src/zig/tests/text-buffer-drawing_test.zig +3237 -0
- package/src/zig/tests/text-buffer-highlights_test.zig +666 -0
- package/src/zig/tests/text-buffer-iterators_test.zig +776 -0
- package/src/zig/tests/text-buffer-segment_test.zig +320 -0
- package/src/zig/tests/text-buffer-selection_test.zig +1035 -0
- package/src/zig/tests/text-buffer-selection_viewport_test.zig +358 -0
- package/src/zig/tests/text-buffer-view_test.zig +3649 -0
- package/src/zig/tests/text-buffer_test.zig +2191 -0
- package/src/zig/tests/unicode-width-map.zon +3909 -0
- package/src/zig/tests/utf8_no_zwj_test.zig +260 -0
- package/src/zig/tests/utf8_test.zig +4057 -0
- package/src/zig/tests/utf8_wcwidth_cursor_test.zig +267 -0
- package/src/zig/tests/utf8_wcwidth_test.zig +357 -0
- package/src/zig/tests/word-wrap-editing_test.zig +498 -0
- package/src/zig/tests/wrap-cache-perf_test.zig +113 -0
- package/src/zig/text-buffer-iterators.zig +499 -0
- package/src/zig/text-buffer-segment.zig +404 -0
- package/src/zig/text-buffer-view.zig +1371 -0
- package/src/zig/text-buffer.zig +1180 -0
- package/src/zig/utf8.zig +1948 -0
- package/src/zig/utils.zig +9 -0
- package/src/zig-structs.ts +261 -0
- package/src/zig.ts +3884 -0
- package/tsconfig.build.json +24 -0
- package/tsconfig.json +27 -0
- package/3d/SpriteResourceManager.d.ts +0 -74
- package/3d/SpriteUtils.d.ts +0 -13
- package/3d/TextureUtils.d.ts +0 -24
- package/3d/ThreeRenderable.d.ts +0 -40
- package/3d/WGPURenderer.d.ts +0 -61
- package/3d/animation/ExplodingSpriteEffect.d.ts +0 -71
- package/3d/animation/PhysicsExplodingSpriteEffect.d.ts +0 -76
- package/3d/animation/SpriteAnimator.d.ts +0 -124
- package/3d/animation/SpriteParticleGenerator.d.ts +0 -62
- package/3d/canvas.d.ts +0 -44
- package/3d/index.d.ts +0 -12
- package/3d/physics/PlanckPhysicsAdapter.d.ts +0 -19
- package/3d/physics/RapierPhysicsAdapter.d.ts +0 -19
- package/3d/physics/physics-interface.d.ts +0 -27
- package/3d.d.ts +0 -2
- package/3d.js +0 -34041
- package/3d.js.map +0 -155
- package/LICENSE +0 -21
- package/NativeSpanFeed.d.ts +0 -41
- package/Renderable.d.ts +0 -334
- package/animation/Timeline.d.ts +0 -126
- package/ansi.d.ts +0 -13
- package/buffer.d.ts +0 -111
- package/console.d.ts +0 -144
- package/edit-buffer.d.ts +0 -98
- package/editor-view.d.ts +0 -73
- package/index-8fks7yv1.js +0 -411
- package/index-8fks7yv1.js.map +0 -10
- package/index-egy5e2rs.js +0 -12267
- package/index-egy5e2rs.js.map +0 -42
- package/index-tse8gzh0.js +0 -20614
- package/index-tse8gzh0.js.map +0 -67
- package/index.d.ts +0 -23
- package/index.js +0 -478
- package/index.js.map +0 -9
- package/lib/KeyHandler.d.ts +0 -61
- package/lib/RGBA.d.ts +0 -25
- package/lib/ascii.font.d.ts +0 -508
- package/lib/border.d.ts +0 -51
- package/lib/bunfs.d.ts +0 -7
- package/lib/clipboard.d.ts +0 -17
- package/lib/clock.d.ts +0 -15
- package/lib/data-paths.d.ts +0 -26
- package/lib/debounce.d.ts +0 -42
- package/lib/detect-links.d.ts +0 -6
- package/lib/env.d.ts +0 -42
- package/lib/extmarks-history.d.ts +0 -17
- package/lib/extmarks.d.ts +0 -89
- package/lib/hast-styled-text.d.ts +0 -17
- package/lib/index.d.ts +0 -21
- package/lib/keymapping.d.ts +0 -25
- package/lib/objects-in-viewport.d.ts +0 -24
- package/lib/output.capture.d.ts +0 -24
- package/lib/parse.keypress-kitty.d.ts +0 -2
- package/lib/parse.keypress.d.ts +0 -26
- package/lib/parse.mouse.d.ts +0 -30
- package/lib/paste.d.ts +0 -7
- package/lib/queue.d.ts +0 -15
- package/lib/renderable.validations.d.ts +0 -12
- package/lib/scroll-acceleration.d.ts +0 -43
- package/lib/selection.d.ts +0 -63
- package/lib/singleton.d.ts +0 -7
- package/lib/stdin-parser.d.ts +0 -87
- package/lib/styled-text.d.ts +0 -63
- package/lib/terminal-capability-detection.d.ts +0 -30
- package/lib/terminal-palette.d.ts +0 -50
- package/lib/tree-sitter/assets/update.d.ts +0 -11
- package/lib/tree-sitter/client.d.ts +0 -47
- package/lib/tree-sitter/default-parsers.d.ts +0 -2
- package/lib/tree-sitter/download-utils.d.ts +0 -21
- package/lib/tree-sitter/index.d.ts +0 -8
- package/lib/tree-sitter/parser.worker.d.ts +0 -1
- package/lib/tree-sitter/parsers-config.d.ts +0 -53
- package/lib/tree-sitter/resolve-ft.d.ts +0 -5
- package/lib/tree-sitter/types.d.ts +0 -82
- package/lib/tree-sitter-styled-text.d.ts +0 -14
- package/lib/validate-dir-name.d.ts +0 -1
- package/lib/yoga.options.d.ts +0 -32
- package/parser.worker.js +0 -899
- package/parser.worker.js.map +0 -12
- package/plugins/core-slot.d.ts +0 -72
- package/plugins/registry.d.ts +0 -42
- package/plugins/types.d.ts +0 -34
- package/post/effects.d.ts +0 -147
- package/post/filters.d.ts +0 -65
- package/post/matrices.d.ts +0 -20
- package/renderables/ASCIIFont.d.ts +0 -52
- package/renderables/Box.d.ts +0 -81
- package/renderables/Code.d.ts +0 -78
- package/renderables/Diff.d.ts +0 -142
- package/renderables/EditBufferRenderable.d.ts +0 -237
- package/renderables/FrameBuffer.d.ts +0 -16
- package/renderables/Input.d.ts +0 -67
- package/renderables/LineNumberRenderable.d.ts +0 -78
- package/renderables/Markdown.d.ts +0 -185
- package/renderables/ScrollBar.d.ts +0 -77
- package/renderables/ScrollBox.d.ts +0 -124
- package/renderables/Select.d.ts +0 -115
- package/renderables/Slider.d.ts +0 -47
- package/renderables/TabSelect.d.ts +0 -96
- package/renderables/Text.d.ts +0 -36
- package/renderables/TextBufferRenderable.d.ts +0 -105
- package/renderables/TextNode.d.ts +0 -91
- package/renderables/TextTable.d.ts +0 -140
- package/renderables/Textarea.d.ts +0 -63
- package/renderables/TimeToFirstDraw.d.ts +0 -24
- package/renderables/__tests__/renderable-test-utils.d.ts +0 -12
- package/renderables/composition/VRenderable.d.ts +0 -16
- package/renderables/composition/constructs.d.ts +0 -35
- package/renderables/composition/vnode.d.ts +0 -46
- package/renderables/index.d.ts +0 -23
- package/renderables/markdown-parser.d.ts +0 -10
- package/renderer.d.ts +0 -419
- package/runtime-plugin-support.d.ts +0 -3
- package/runtime-plugin-support.js +0 -29
- package/runtime-plugin-support.js.map +0 -10
- package/runtime-plugin.d.ts +0 -16
- package/runtime-plugin.js +0 -16
- package/runtime-plugin.js.map +0 -9
- package/syntax-style.d.ts +0 -54
- package/testing/manual-clock.d.ts +0 -17
- package/testing/mock-keys.d.ts +0 -81
- package/testing/mock-mouse.d.ts +0 -38
- package/testing/mock-tree-sitter-client.d.ts +0 -23
- package/testing/spy.d.ts +0 -7
- package/testing/test-recorder.d.ts +0 -61
- package/testing/test-renderer.d.ts +0 -23
- package/testing.d.ts +0 -6
- package/testing.js +0 -697
- package/testing.js.map +0 -15
- package/text-buffer-view.d.ts +0 -42
- package/text-buffer.d.ts +0 -67
- package/types.d.ts +0 -139
- package/utils.d.ts +0 -14
- package/zig-structs.d.ts +0 -155
- package/zig.d.ts +0 -353
- /package/{assets → src/lib/tree-sitter/assets}/javascript/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/javascript/tree-sitter-javascript.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/injections.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown/tree-sitter-markdown.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/markdown_inline/tree-sitter-markdown_inline.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/typescript/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/typescript/tree-sitter-typescript.wasm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/zig/highlights.scm +0 -0
- /package/{assets → src/lib/tree-sitter/assets}/zig/tree-sitter-zig.wasm +0 -0
|
@@ -0,0 +1,1371 @@
|
|
|
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
|
+
};
|