@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,802 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const Allocator = std.mem.Allocator;
|
|
3
|
+
const tb = @import("text-buffer.zig");
|
|
4
|
+
const tbv = @import("text-buffer-view.zig");
|
|
5
|
+
const eb = @import("edit-buffer.zig");
|
|
6
|
+
const iter_mod = @import("text-buffer-iterators.zig");
|
|
7
|
+
const gp = @import("grapheme.zig");
|
|
8
|
+
const ss = @import("syntax-style.zig");
|
|
9
|
+
const event_emitter = @import("event-emitter.zig");
|
|
10
|
+
const logger = @import("logger.zig");
|
|
11
|
+
|
|
12
|
+
const EditBuffer = eb.EditBuffer;
|
|
13
|
+
|
|
14
|
+
// Use the unified types to match EditBuffer
|
|
15
|
+
const UnifiedTextBuffer = tb.UnifiedTextBuffer;
|
|
16
|
+
const UnifiedTextBufferView = tbv.UnifiedTextBufferView;
|
|
17
|
+
const VirtualLine = tbv.VirtualLine;
|
|
18
|
+
|
|
19
|
+
pub const EditorViewError = error{
|
|
20
|
+
OutOfMemory,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/// VisualCursor represents a cursor position with both visual and logical coordinates.
|
|
24
|
+
/// Visual coordinates (visual_row, visual_col) are VIEWPORT-RELATIVE.
|
|
25
|
+
/// This means visual_row=0 is the first visible line in the viewport, not the first line in the document.
|
|
26
|
+
/// Logical coordinates (logical_row, logical_col) are document-absolute.
|
|
27
|
+
pub const VisualCursor = struct {
|
|
28
|
+
visual_row: u32, // Viewport-relative row (0 = top of viewport)
|
|
29
|
+
visual_col: u32, // Viewport-relative column (0 = left edge of viewport when not wrapping)
|
|
30
|
+
logical_row: u32, // Document-absolute row
|
|
31
|
+
logical_col: u32, // Document-absolute column
|
|
32
|
+
offset: u32, // Global display-width offset from buffer start
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/// EditorView wraps a TextBufferView and manages viewport state for efficient rendering
|
|
36
|
+
/// It also holds a reference to an EditBuffer for cursor/editing operations
|
|
37
|
+
pub const EditorView = struct {
|
|
38
|
+
text_buffer_view: *UnifiedTextBufferView,
|
|
39
|
+
edit_buffer: *EditBuffer, // Reference to the EditBuffer (not owned)
|
|
40
|
+
scroll_margin: f32, // Fraction of viewport height (0.0-0.5) to keep cursor away from edges
|
|
41
|
+
desired_visual_col: ?u32, // Preserved visual column for visual up/down navigation
|
|
42
|
+
selection_follow_cursor: bool, // Keep viewport synced during selection
|
|
43
|
+
cursor_changed_listener: event_emitter.EventEmitter(eb.EditBufferEvent).Listener,
|
|
44
|
+
|
|
45
|
+
placeholder_buffer: ?*UnifiedTextBuffer,
|
|
46
|
+
placeholder_syntax_style: ?*ss.SyntaxStyle,
|
|
47
|
+
placeholder_active: bool,
|
|
48
|
+
|
|
49
|
+
// Memory management
|
|
50
|
+
global_allocator: Allocator,
|
|
51
|
+
|
|
52
|
+
fn onCursorChanged(ctx: *anyopaque) void {
|
|
53
|
+
const self: *EditorView = @ptrCast(@alignCast(ctx));
|
|
54
|
+
self.desired_visual_col = null;
|
|
55
|
+
self.updatePlaceholderVisibility();
|
|
56
|
+
|
|
57
|
+
const has_selection = self.text_buffer_view.selection != null;
|
|
58
|
+
if (!has_selection or self.selection_follow_cursor) {
|
|
59
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
60
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
61
|
+
self.ensureCursorVisible(vcursor.visual_row);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
pub fn init(global_allocator: Allocator, edit_buffer: *EditBuffer, viewport_width: u32, viewport_height: u32) EditorViewError!*EditorView {
|
|
66
|
+
const self = global_allocator.create(EditorView) catch return EditorViewError.OutOfMemory;
|
|
67
|
+
errdefer global_allocator.destroy(self);
|
|
68
|
+
|
|
69
|
+
const text_buffer = edit_buffer.getTextBuffer();
|
|
70
|
+
const text_buffer_view = UnifiedTextBufferView.init(global_allocator, text_buffer) catch return EditorViewError.OutOfMemory;
|
|
71
|
+
errdefer text_buffer_view.deinit();
|
|
72
|
+
|
|
73
|
+
self.* = .{
|
|
74
|
+
.text_buffer_view = text_buffer_view,
|
|
75
|
+
.edit_buffer = edit_buffer,
|
|
76
|
+
.scroll_margin = 0.15, // Default 15% margin
|
|
77
|
+
.desired_visual_col = null,
|
|
78
|
+
.selection_follow_cursor = false,
|
|
79
|
+
.cursor_changed_listener = .{
|
|
80
|
+
.ctx = undefined, // Will be set below
|
|
81
|
+
.handle = onCursorChanged,
|
|
82
|
+
},
|
|
83
|
+
.placeholder_buffer = null,
|
|
84
|
+
.placeholder_syntax_style = null,
|
|
85
|
+
.placeholder_active = false,
|
|
86
|
+
.global_allocator = global_allocator,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
self.cursor_changed_listener.ctx = self;
|
|
90
|
+
|
|
91
|
+
edit_buffer.events.on(.cursorChanged, self.cursor_changed_listener) catch return EditorViewError.OutOfMemory;
|
|
92
|
+
|
|
93
|
+
text_buffer_view.setViewport(tbv.Viewport{
|
|
94
|
+
.x = 0,
|
|
95
|
+
.y = 0,
|
|
96
|
+
.width = viewport_width,
|
|
97
|
+
.height = viewport_height,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return self;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
pub fn deinit(self: *EditorView) void {
|
|
104
|
+
self.edit_buffer.events.off(.cursorChanged, self.cursor_changed_listener);
|
|
105
|
+
|
|
106
|
+
if (self.placeholder_syntax_style) |style| {
|
|
107
|
+
style.deinit();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (self.placeholder_buffer) |placeholder| {
|
|
111
|
+
placeholder.deinit();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
self.text_buffer_view.deinit();
|
|
115
|
+
self.global_allocator.destroy(self);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Set the viewport. If wrapping is enabled and viewport width differs from current wrap width,
|
|
119
|
+
/// this will trigger a reflow by updating the TextBufferView's wrap width.
|
|
120
|
+
/// moveCursor: if true, moves cursor to stay within viewport bounds (prevents viewport reset)
|
|
121
|
+
pub fn setViewport(self: *EditorView, vp: ?tbv.Viewport, moveCursor: bool) void {
|
|
122
|
+
self.text_buffer_view.setViewport(vp);
|
|
123
|
+
|
|
124
|
+
if (moveCursor) {
|
|
125
|
+
self.makeCursorVisible();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
pub fn getViewport(self: *const EditorView) ?tbv.Viewport {
|
|
130
|
+
return self.text_buffer_view.getViewport();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Move the cursor to be within the current viewport if it's outside.
|
|
134
|
+
/// Unlike ensureCursorVisible, this moves the cursor, not the viewport.
|
|
135
|
+
/// Respects scroll margins to prevent immediate re-scrolling by ensureCursorVisible.
|
|
136
|
+
pub fn makeCursorVisible(self: *EditorView) void {
|
|
137
|
+
const vp = self.text_buffer_view.getViewport() orelse return;
|
|
138
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
139
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
140
|
+
|
|
141
|
+
const viewport_height = vp.height;
|
|
142
|
+
const margin_lines = @max(1, @as(u32, @intFromFloat(@as(f32, @floatFromInt(viewport_height)) * self.scroll_margin)));
|
|
143
|
+
|
|
144
|
+
const cursor_above_viewport = vcursor.visual_row < vp.y;
|
|
145
|
+
const cursor_below_viewport = vcursor.visual_row >= vp.y + vp.height;
|
|
146
|
+
const cursor_too_close_to_top = vcursor.visual_row < vp.y + margin_lines;
|
|
147
|
+
const cursor_too_close_to_bottom = vcursor.visual_row >= vp.y + vp.height - margin_lines;
|
|
148
|
+
|
|
149
|
+
if (cursor_above_viewport or cursor_below_viewport or cursor_too_close_to_top or cursor_too_close_to_bottom) {
|
|
150
|
+
const target_visual_row = if (cursor_above_viewport or cursor_too_close_to_top)
|
|
151
|
+
vp.y + margin_lines
|
|
152
|
+
else
|
|
153
|
+
vp.y + vp.height - margin_lines - 1;
|
|
154
|
+
|
|
155
|
+
self.text_buffer_view.updateVirtualLines();
|
|
156
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
157
|
+
if (target_visual_row < vlines.len) {
|
|
158
|
+
const target_vline = &vlines[target_visual_row];
|
|
159
|
+
const target_logical_row = @as(u32, @intCast(target_vline.source_line));
|
|
160
|
+
|
|
161
|
+
const line_width = iter_mod.lineWidthAt(self.edit_buffer.tb.rope(), target_logical_row);
|
|
162
|
+
const target_col = @min(cursor.col, line_width);
|
|
163
|
+
|
|
164
|
+
if (self.edit_buffer.cursors.items.len > 0) {
|
|
165
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), target_logical_row, target_col) orelse return;
|
|
166
|
+
self.edit_buffer.cursors.items[0] = .{
|
|
167
|
+
.row = target_logical_row,
|
|
168
|
+
.col = target_col,
|
|
169
|
+
.desired_col = target_col,
|
|
170
|
+
.offset = offset,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// Set the scroll margin as a fraction of viewport height (0.0 to 0.5)
|
|
178
|
+
/// The cursor will stay at least this many lines from the top/bottom edges when scrolling
|
|
179
|
+
pub fn setScrollMargin(self: *EditorView, margin: f32) void {
|
|
180
|
+
self.scroll_margin = @max(0.0, @min(0.5, margin));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
pub fn setSelectionFollowCursor(self: *EditorView, enabled: bool) void {
|
|
184
|
+
self.selection_follow_cursor = enabled;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Ensure the cursor is visible within the viewport, adjusting viewport.y and viewport.x if needed
|
|
188
|
+
/// cursor_line: The virtual line index where the cursor is located
|
|
189
|
+
pub fn ensureCursorVisible(self: *EditorView, cursor_line: u32) void {
|
|
190
|
+
const vp = self.text_buffer_view.getViewport() orelse return;
|
|
191
|
+
|
|
192
|
+
const viewport_height = vp.height;
|
|
193
|
+
const viewport_width = vp.width;
|
|
194
|
+
if (viewport_height == 0 or viewport_width == 0) return;
|
|
195
|
+
|
|
196
|
+
const raw_margin_lines = @max(1, @as(u32, @intFromFloat(@as(f32, @floatFromInt(viewport_height)) * self.scroll_margin)));
|
|
197
|
+
const max_margin_lines = if (viewport_height > 1) (viewport_height - 1) / 2 else 0;
|
|
198
|
+
const margin_lines = @min(raw_margin_lines, max_margin_lines);
|
|
199
|
+
|
|
200
|
+
const raw_margin_cols = @max(1, @as(u32, @intFromFloat(@as(f32, @floatFromInt(viewport_width)) * self.scroll_margin)));
|
|
201
|
+
const max_margin_cols = if (viewport_width > 1) (viewport_width - 1) / 2 else 0;
|
|
202
|
+
const margin_cols = @min(raw_margin_cols, max_margin_cols);
|
|
203
|
+
|
|
204
|
+
const total_lines = self.text_buffer_view.getVirtualLineCount();
|
|
205
|
+
const max_offset_y = if (total_lines > viewport_height) total_lines - viewport_height else 0;
|
|
206
|
+
|
|
207
|
+
var new_offset_y = vp.y;
|
|
208
|
+
var new_offset_x = vp.x;
|
|
209
|
+
|
|
210
|
+
if (cursor_line < vp.y + margin_lines) {
|
|
211
|
+
if (cursor_line >= margin_lines) {
|
|
212
|
+
new_offset_y = cursor_line - margin_lines;
|
|
213
|
+
} else {
|
|
214
|
+
new_offset_y = 0;
|
|
215
|
+
}
|
|
216
|
+
} else if (cursor_line >= vp.y + viewport_height - margin_lines) {
|
|
217
|
+
const desired_offset = cursor_line + margin_lines - viewport_height + 1;
|
|
218
|
+
new_offset_y = @min(desired_offset, max_offset_y);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (self.text_buffer_view.wrap_mode == .none) {
|
|
222
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
223
|
+
const cursor_col = cursor.col;
|
|
224
|
+
|
|
225
|
+
if (cursor_col < vp.x + margin_cols) {
|
|
226
|
+
if (cursor_col >= margin_cols) {
|
|
227
|
+
new_offset_x = cursor_col - margin_cols;
|
|
228
|
+
} else {
|
|
229
|
+
new_offset_x = 0;
|
|
230
|
+
}
|
|
231
|
+
} else if (cursor_col >= vp.x + viewport_width - margin_cols) {
|
|
232
|
+
new_offset_x = cursor_col + margin_cols - viewport_width + 1;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (new_offset_y != vp.y or new_offset_x != vp.x) {
|
|
237
|
+
self.text_buffer_view.setViewport(tbv.Viewport{
|
|
238
|
+
.x = new_offset_x,
|
|
239
|
+
.y = new_offset_y,
|
|
240
|
+
.width = vp.width,
|
|
241
|
+
.height = vp.height,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/// Always ensures cursor visibility since cursor movements don't mark buffer dirty
|
|
247
|
+
/// Note: With eager viewport updates in onCursorChanged, this is mainly for rendering methods
|
|
248
|
+
pub fn updateBeforeRender(self: *EditorView) void {
|
|
249
|
+
self.updatePlaceholderVisibility();
|
|
250
|
+
|
|
251
|
+
const has_selection = self.text_buffer_view.selection != null;
|
|
252
|
+
|
|
253
|
+
if (!has_selection or self.selection_follow_cursor) {
|
|
254
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
255
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
256
|
+
self.ensureCursorVisible(vcursor.visual_row);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// Automatically ensures cursor is visible before rendering
|
|
261
|
+
pub fn getVirtualLines(self: *EditorView) []const VirtualLine {
|
|
262
|
+
self.updateBeforeRender();
|
|
263
|
+
return self.text_buffer_view.getVirtualLines();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// Automatically ensures cursor is visible before rendering
|
|
267
|
+
pub fn getCachedLineInfo(self: *EditorView) tbv.LineInfo {
|
|
268
|
+
self.updateBeforeRender();
|
|
269
|
+
return self.text_buffer_view.getCachedLineInfo();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
pub fn getLogicalLineInfo(self: *EditorView) tbv.LineInfo {
|
|
273
|
+
self.updatePlaceholderVisibility();
|
|
274
|
+
self.text_buffer_view.virtual_lines_dirty = true;
|
|
275
|
+
const line_info = self.text_buffer_view.getLogicalLineInfo();
|
|
276
|
+
return line_info;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
pub fn getTextBufferView(self: *EditorView) *UnifiedTextBufferView {
|
|
280
|
+
return self.text_buffer_view;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
pub fn getTotalVirtualLineCount(self: *EditorView) u32 {
|
|
284
|
+
return self.text_buffer_view.getVirtualLineCount();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
pub fn getVirtualLineSpans(self: *const EditorView, vline_idx: usize) tbv.VirtualLineSpanInfo {
|
|
288
|
+
return self.text_buffer_view.getVirtualLineSpans(vline_idx);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
pub fn getTextBuffer(self: *const EditorView) *UnifiedTextBuffer {
|
|
292
|
+
return self.text_buffer_view.text_buffer;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
pub fn getSelection(self: *const EditorView) ?tb.TextSelection {
|
|
296
|
+
return self.text_buffer_view.selection;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
pub fn setSelection(self: *EditorView, start: u32, end: u32, bgColor: ?tb.RGBA, fgColor: ?tb.RGBA) void {
|
|
300
|
+
self.text_buffer_view.setSelection(start, end, bgColor, fgColor);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
pub fn updateSelection(self: *EditorView, end: u32, bgColor: ?tb.RGBA, fgColor: ?tb.RGBA) void {
|
|
304
|
+
self.text_buffer_view.updateSelection(end, bgColor, fgColor);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
pub fn resetSelection(self: *EditorView) void {
|
|
308
|
+
self.text_buffer_view.resetSelection();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
pub fn setLocalSelection(self: *EditorView, anchorX: i32, anchorY: i32, focusX: i32, focusY: i32, bgColor: ?tb.RGBA, fgColor: ?tb.RGBA, updateCursor: bool) bool {
|
|
312
|
+
const changed = self.text_buffer_view.setLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor);
|
|
313
|
+
|
|
314
|
+
if (changed and updateCursor) {
|
|
315
|
+
self.updateCursorToSelectionFocus(focusX, focusY);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return changed;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
pub fn updateLocalSelection(self: *EditorView, anchorX: i32, anchorY: i32, focusX: i32, focusY: i32, bgColor: ?tb.RGBA, fgColor: ?tb.RGBA, updateCursor: bool) bool {
|
|
322
|
+
const changed = self.text_buffer_view.updateLocalSelection(anchorX, anchorY, focusX, focusY, bgColor, fgColor);
|
|
323
|
+
|
|
324
|
+
if (changed and updateCursor) {
|
|
325
|
+
self.updateCursorToSelectionFocus(focusX, focusY);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return changed;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
pub fn resetLocalSelection(self: *EditorView) void {
|
|
332
|
+
self.text_buffer_view.resetLocalSelection();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/// Updates the cursor position to match the selection focus position.
|
|
336
|
+
/// Does NOT trigger viewport scrolling - TypeScript layer handles that.
|
|
337
|
+
fn updateCursorToSelectionFocus(self: *EditorView, _: i32, _: i32) void {
|
|
338
|
+
const selection = self.text_buffer_view.getSelection() orelse return;
|
|
339
|
+
|
|
340
|
+
const focus_offset = if (self.text_buffer_view.selection_anchor_offset) |anchor| blk: {
|
|
341
|
+
if (anchor == selection.start) {
|
|
342
|
+
break :blk selection.end;
|
|
343
|
+
} else {
|
|
344
|
+
break :blk selection.start;
|
|
345
|
+
}
|
|
346
|
+
} else blk: {
|
|
347
|
+
break :blk selection.end;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const focus_coords = iter_mod.offsetToCoords(self.edit_buffer.tb.rope(), focus_offset) orelse return;
|
|
351
|
+
|
|
352
|
+
const line_count = iter_mod.getLineCount(self.edit_buffer.tb.rope());
|
|
353
|
+
if (focus_coords.row >= line_count) return;
|
|
354
|
+
|
|
355
|
+
const line_width = iter_mod.lineWidthAt(self.edit_buffer.tb.rope(), focus_coords.row);
|
|
356
|
+
if (focus_coords.col > line_width) return;
|
|
357
|
+
|
|
358
|
+
// Update cursor to focus position
|
|
359
|
+
if (self.edit_buffer.cursors.items.len > 0) {
|
|
360
|
+
self.edit_buffer.cursors.items[0] = .{
|
|
361
|
+
.row = focus_coords.row,
|
|
362
|
+
.col = focus_coords.col,
|
|
363
|
+
.desired_col = focus_coords.col,
|
|
364
|
+
.offset = focus_offset,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
pub fn getSelectedTextIntoBuffer(self: *EditorView, out_buffer: []u8) usize {
|
|
370
|
+
return self.text_buffer_view.getSelectedTextIntoBuffer(out_buffer);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
pub fn packSelectionInfo(self: *const EditorView) u64 {
|
|
374
|
+
return self.text_buffer_view.packSelectionInfo();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/// This is a convenience method that preserves existing offset
|
|
378
|
+
/// After resize, ensures cursor is visible and clamps viewport offset to valid range
|
|
379
|
+
pub fn setViewportSize(self: *EditorView, width: u32, height: u32) void {
|
|
380
|
+
self.text_buffer_view.setViewportSize(width, height);
|
|
381
|
+
|
|
382
|
+
const vp = self.text_buffer_view.getViewport() orelse return;
|
|
383
|
+
const total_lines = self.text_buffer_view.getVirtualLineCount();
|
|
384
|
+
const max_offset_y = if (total_lines > vp.height) total_lines - vp.height else 0;
|
|
385
|
+
|
|
386
|
+
var new_offset_x = vp.x;
|
|
387
|
+
if (self.text_buffer_view.wrap_mode == .none) {
|
|
388
|
+
const max_line_width = iter_mod.getMaxLineWidth(self.edit_buffer.tb.rope());
|
|
389
|
+
const max_offset_x = if (max_line_width > vp.width) max_line_width - vp.width else 0;
|
|
390
|
+
if (vp.x > max_offset_x) {
|
|
391
|
+
new_offset_x = max_offset_x;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (vp.y > max_offset_y or new_offset_x != vp.x) {
|
|
396
|
+
self.text_buffer_view.setViewport(tbv.Viewport{
|
|
397
|
+
.x = new_offset_x,
|
|
398
|
+
.y = @min(vp.y, max_offset_y),
|
|
399
|
+
.width = vp.width,
|
|
400
|
+
.height = vp.height,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
405
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
406
|
+
self.ensureCursorVisible(vcursor.visual_row);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
pub fn setWrapMode(self: *EditorView, mode: tb.WrapMode) void {
|
|
410
|
+
self.text_buffer_view.setWrapMode(mode);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
pub fn getPrimaryCursor(self: *const EditorView) eb.Cursor {
|
|
414
|
+
return self.edit_buffer.getPrimaryCursor();
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
pub fn getCursor(self: *const EditorView, idx: usize) ?eb.Cursor {
|
|
418
|
+
return self.edit_buffer.getCursor(idx);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
pub fn getText(self: *EditorView, out_buffer: []u8) usize {
|
|
422
|
+
return self.edit_buffer.getText(out_buffer);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/// Get the EditBuffer for direct access when needed
|
|
426
|
+
pub fn getEditBuffer(self: *EditorView) *EditBuffer {
|
|
427
|
+
return self.edit_buffer;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ============================================================================
|
|
431
|
+
// VisualCursor - Wrapping-aware cursor translation
|
|
432
|
+
// ============================================================================
|
|
433
|
+
|
|
434
|
+
/// Returns viewport-relative visual coordinates for external API consumers
|
|
435
|
+
pub fn getVisualCursor(self: *EditorView) VisualCursor {
|
|
436
|
+
self.updateBeforeRender();
|
|
437
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
438
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
439
|
+
|
|
440
|
+
// Convert absolute visual coordinates to viewport-relative for the API
|
|
441
|
+
const vp = self.text_buffer_view.getViewport() orelse return vcursor;
|
|
442
|
+
|
|
443
|
+
const viewport_relative_row = if (vcursor.visual_row >= vp.y) vcursor.visual_row - vp.y else 0;
|
|
444
|
+
const viewport_relative_col = if (self.text_buffer_view.wrap_mode == .none)
|
|
445
|
+
(if (vcursor.visual_col >= vp.x) vcursor.visual_col - vp.x else 0)
|
|
446
|
+
else
|
|
447
|
+
vcursor.visual_col;
|
|
448
|
+
|
|
449
|
+
return VisualCursor{
|
|
450
|
+
.visual_row = viewport_relative_row,
|
|
451
|
+
.visual_col = viewport_relative_col,
|
|
452
|
+
.logical_row = vcursor.logical_row,
|
|
453
|
+
.logical_col = vcursor.logical_col,
|
|
454
|
+
.offset = vcursor.offset,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/// This accounts for line wrapping by finding which virtual line contains the logical position
|
|
459
|
+
/// Returns absolute visual coordinates (document-absolute, not viewport-relative)
|
|
460
|
+
pub fn logicalToVisualCursor(self: *EditorView, logical_row: u32, logical_col: u32) VisualCursor {
|
|
461
|
+
// Clamp logical coordinates to valid buffer ranges
|
|
462
|
+
const line_count = iter_mod.getLineCount(self.edit_buffer.tb.rope());
|
|
463
|
+
const clamped_row = if (line_count > 0) @min(logical_row, line_count - 1) else 0;
|
|
464
|
+
|
|
465
|
+
const line_width = iter_mod.lineWidthAt(self.edit_buffer.tb.rope(), clamped_row);
|
|
466
|
+
const clamped_col = @min(logical_col, line_width);
|
|
467
|
+
|
|
468
|
+
const visual_row_idx = self.text_buffer_view.findVisualLineIndex(clamped_row, clamped_col);
|
|
469
|
+
|
|
470
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
471
|
+
if (vlines.len == 0 or visual_row_idx >= vlines.len) {
|
|
472
|
+
// Fallback for edge cases
|
|
473
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), clamped_row, clamped_col) orelse 0;
|
|
474
|
+
return VisualCursor{
|
|
475
|
+
.visual_row = 0,
|
|
476
|
+
.visual_col = 0,
|
|
477
|
+
.logical_row = clamped_row,
|
|
478
|
+
.logical_col = clamped_col,
|
|
479
|
+
.offset = offset,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const vline = &vlines[visual_row_idx];
|
|
484
|
+
const vline_start_col = vline.source_col_offset;
|
|
485
|
+
|
|
486
|
+
// Calculate visual column within this virtual line
|
|
487
|
+
const visual_col = if (clamped_col >= vline_start_col)
|
|
488
|
+
clamped_col - vline_start_col
|
|
489
|
+
else
|
|
490
|
+
0;
|
|
491
|
+
|
|
492
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), clamped_row, clamped_col) orelse 0;
|
|
493
|
+
|
|
494
|
+
return VisualCursor{
|
|
495
|
+
.visual_row = visual_row_idx,
|
|
496
|
+
.visual_col = visual_col,
|
|
497
|
+
.logical_row = clamped_row,
|
|
498
|
+
.logical_col = clamped_col,
|
|
499
|
+
.offset = offset,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/// Input visual coordinates are absolute (document-absolute)
|
|
504
|
+
/// Returns a VisualCursor with absolute visual coordinates
|
|
505
|
+
pub fn visualToLogicalCursor(self: *EditorView, visual_row: u32, visual_col: u32) ?VisualCursor {
|
|
506
|
+
self.text_buffer_view.updateVirtualLines();
|
|
507
|
+
|
|
508
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
509
|
+
if (visual_row >= vlines.len) return null;
|
|
510
|
+
|
|
511
|
+
const vline = &vlines[visual_row];
|
|
512
|
+
const clamped_visual_col = @min(visual_col, vline.width_cols);
|
|
513
|
+
const logical_col = vline.source_col_offset + clamped_visual_col;
|
|
514
|
+
const logical_row = @as(u32, @intCast(vline.source_line));
|
|
515
|
+
|
|
516
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), logical_row, logical_col) orelse 0;
|
|
517
|
+
|
|
518
|
+
return VisualCursor{
|
|
519
|
+
.visual_row = visual_row,
|
|
520
|
+
.visual_col = clamped_visual_col,
|
|
521
|
+
.logical_row = logical_row,
|
|
522
|
+
.logical_col = logical_col,
|
|
523
|
+
.offset = offset,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
pub fn moveUpVisual(self: *EditorView) void {
|
|
528
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
529
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
530
|
+
|
|
531
|
+
if (vcursor.visual_row == 0) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const target_visual_row = vcursor.visual_row - 1;
|
|
536
|
+
|
|
537
|
+
// This persists across empty/narrow lines to restore column when possible
|
|
538
|
+
if (self.desired_visual_col == null) {
|
|
539
|
+
self.desired_visual_col = vcursor.visual_col;
|
|
540
|
+
}
|
|
541
|
+
const desired_visual_col = self.desired_visual_col.?;
|
|
542
|
+
|
|
543
|
+
if (self.visualToLogicalCursor(target_visual_row, desired_visual_col)) |new_vcursor| {
|
|
544
|
+
if (self.edit_buffer.cursors.items.len > 0) {
|
|
545
|
+
self.edit_buffer.cursors.items[0] = .{
|
|
546
|
+
.row = new_vcursor.logical_row,
|
|
547
|
+
.col = new_vcursor.logical_col,
|
|
548
|
+
.desired_col = new_vcursor.logical_col,
|
|
549
|
+
.offset = new_vcursor.offset,
|
|
550
|
+
};
|
|
551
|
+
self.ensureCursorVisible(new_vcursor.visual_row);
|
|
552
|
+
|
|
553
|
+
// Restore desired_visual_col after the cursor change event resets it
|
|
554
|
+
self.desired_visual_col = desired_visual_col;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
pub fn moveDownVisual(self: *EditorView) void {
|
|
560
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
561
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
562
|
+
|
|
563
|
+
self.text_buffer_view.updateVirtualLines();
|
|
564
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
565
|
+
|
|
566
|
+
if (vcursor.visual_row + 1 >= vlines.len) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const target_visual_row = vcursor.visual_row + 1;
|
|
571
|
+
|
|
572
|
+
// This persists across empty/narrow lines to restore column when possible
|
|
573
|
+
if (self.desired_visual_col == null) {
|
|
574
|
+
self.desired_visual_col = vcursor.visual_col;
|
|
575
|
+
}
|
|
576
|
+
const desired_visual_col = self.desired_visual_col.?;
|
|
577
|
+
|
|
578
|
+
if (self.visualToLogicalCursor(target_visual_row, desired_visual_col)) |new_vcursor| {
|
|
579
|
+
if (self.edit_buffer.cursors.items.len > 0) {
|
|
580
|
+
self.edit_buffer.cursors.items[0] = .{
|
|
581
|
+
.row = new_vcursor.logical_row,
|
|
582
|
+
.col = new_vcursor.logical_col,
|
|
583
|
+
.desired_col = new_vcursor.logical_col,
|
|
584
|
+
.offset = new_vcursor.offset,
|
|
585
|
+
};
|
|
586
|
+
self.ensureCursorVisible(new_vcursor.visual_row);
|
|
587
|
+
|
|
588
|
+
// Restore desired_visual_col after the cursor change event resets it
|
|
589
|
+
self.desired_visual_col = desired_visual_col;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
pub fn deleteSelectedText(self: *EditorView) !void {
|
|
595
|
+
const selection = self.text_buffer_view.getSelection() orelse {
|
|
596
|
+
return;
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
const start_coords = iter_mod.offsetToCoords(self.edit_buffer.tb.rope(), selection.start) orelse {
|
|
600
|
+
return;
|
|
601
|
+
};
|
|
602
|
+
const end_coords = iter_mod.offsetToCoords(self.edit_buffer.tb.rope(), selection.end) orelse {
|
|
603
|
+
return;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
const start_cursor = eb.Cursor{
|
|
607
|
+
.row = start_coords.row,
|
|
608
|
+
.col = start_coords.col,
|
|
609
|
+
.desired_col = start_coords.col,
|
|
610
|
+
};
|
|
611
|
+
const end_cursor = eb.Cursor{
|
|
612
|
+
.row = end_coords.row,
|
|
613
|
+
.col = end_coords.col,
|
|
614
|
+
.desired_col = end_coords.col,
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
try self.edit_buffer.deleteRange(start_cursor, end_cursor);
|
|
618
|
+
self.text_buffer_view.resetLocalSelection();
|
|
619
|
+
self.updateBeforeRender();
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
pub fn setCursorByOffset(self: *EditorView, offset: u32) !void {
|
|
623
|
+
try self.edit_buffer.setCursorByOffset(offset);
|
|
624
|
+
self.updateBeforeRender();
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
pub fn getNextWordBoundary(self: *EditorView) VisualCursor {
|
|
628
|
+
const logical_cursor = self.edit_buffer.getNextWordBoundary();
|
|
629
|
+
return self.logicalToVisualCursor(logical_cursor.row, logical_cursor.col);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
pub fn getPrevWordBoundary(self: *EditorView) VisualCursor {
|
|
633
|
+
const logical_cursor = self.edit_buffer.getPrevWordBoundary();
|
|
634
|
+
return self.logicalToVisualCursor(logical_cursor.row, logical_cursor.col);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
pub fn getEOL(self: *EditorView) VisualCursor {
|
|
638
|
+
const logical_cursor = self.edit_buffer.getEOL();
|
|
639
|
+
return self.logicalToVisualCursor(logical_cursor.row, logical_cursor.col);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/// Get the start of the current visual line (SOL = Start Of Line)
|
|
643
|
+
/// Returns a cursor at column 0 of the current visual line
|
|
644
|
+
pub fn getVisualSOL(self: *EditorView) VisualCursor {
|
|
645
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
646
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
647
|
+
|
|
648
|
+
self.text_buffer_view.updateVirtualLines();
|
|
649
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
650
|
+
|
|
651
|
+
if (vcursor.visual_row >= vlines.len) {
|
|
652
|
+
// Fallback: return cursor at column 0 of current logical line
|
|
653
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), cursor.row, 0) orelse 0;
|
|
654
|
+
return VisualCursor{
|
|
655
|
+
.visual_row = vcursor.visual_row,
|
|
656
|
+
.visual_col = 0,
|
|
657
|
+
.logical_row = cursor.row,
|
|
658
|
+
.logical_col = 0,
|
|
659
|
+
.offset = offset,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const vline = &vlines[vcursor.visual_row];
|
|
664
|
+
const logical_col = vline.source_col_offset; // Start column of this visual line
|
|
665
|
+
const logical_row = @as(u32, @intCast(vline.source_line));
|
|
666
|
+
const offset = iter_mod.coordsToOffset(self.edit_buffer.tb.rope(), logical_row, logical_col) orelse 0;
|
|
667
|
+
|
|
668
|
+
return VisualCursor{
|
|
669
|
+
.visual_row = vcursor.visual_row,
|
|
670
|
+
.visual_col = 0,
|
|
671
|
+
.logical_row = logical_row,
|
|
672
|
+
.logical_col = logical_col,
|
|
673
|
+
.offset = offset,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/// Get the end of the current visual line (EOL = End Of Line)
|
|
678
|
+
/// Returns a cursor at the last position of the current visual line
|
|
679
|
+
/// For wrapped lines, this is the position just before the wrap boundary to ensure
|
|
680
|
+
/// the cursor stays on the current visual line when used with setCursor()
|
|
681
|
+
pub fn getVisualEOL(self: *EditorView) VisualCursor {
|
|
682
|
+
const cursor = self.edit_buffer.getPrimaryCursor();
|
|
683
|
+
const vcursor = self.logicalToVisualCursor(cursor.row, cursor.col);
|
|
684
|
+
|
|
685
|
+
self.text_buffer_view.updateVirtualLines();
|
|
686
|
+
const vlines = self.text_buffer_view.virtual_lines.items;
|
|
687
|
+
|
|
688
|
+
if (vcursor.visual_row >= vlines.len) {
|
|
689
|
+
// Fallback: return end of current logical line
|
|
690
|
+
const logical_cursor = self.edit_buffer.getEOL();
|
|
691
|
+
return self.logicalToVisualCursor(logical_cursor.row, logical_cursor.col);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const vline = &vlines[vcursor.visual_row];
|
|
695
|
+
const logical_row = @as(u32, @intCast(vline.source_line));
|
|
696
|
+
|
|
697
|
+
// Determine the logical column at the end of this visual line
|
|
698
|
+
var logical_col: u32 = undefined;
|
|
699
|
+
if (vcursor.visual_row + 1 < vlines.len) {
|
|
700
|
+
const next_vline = &vlines[vcursor.visual_row + 1];
|
|
701
|
+
if (next_vline.source_line == vline.source_line) {
|
|
702
|
+
// Next visual line is a continuation of the same logical line
|
|
703
|
+
// The wrap boundary is at next_vline.source_col_offset
|
|
704
|
+
// To stay on the current visual line, we need to be one position BEFORE the boundary
|
|
705
|
+
// However, if width is 0, just use the start position
|
|
706
|
+
if (vline.width_cols > 0) {
|
|
707
|
+
logical_col = vline.source_col_offset + vline.width_cols - 1;
|
|
708
|
+
} else {
|
|
709
|
+
logical_col = vline.source_col_offset;
|
|
710
|
+
}
|
|
711
|
+
} else {
|
|
712
|
+
// Next visual line is a different logical line, so we're at the end
|
|
713
|
+
logical_col = iter_mod.lineWidthAt(self.edit_buffer.tb.rope(), logical_row);
|
|
714
|
+
}
|
|
715
|
+
} else {
|
|
716
|
+
// This is the last visual line, use end of logical line
|
|
717
|
+
logical_col = iter_mod.lineWidthAt(self.edit_buffer.tb.rope(), logical_row);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
return self.logicalToVisualCursor(logical_row, logical_col);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// ============================================================================
|
|
724
|
+
// Placeholder - Visual Only
|
|
725
|
+
// ============================================================================
|
|
726
|
+
|
|
727
|
+
pub fn setPlaceholderStyledText(self: *EditorView, chunks: []const tb.StyledChunk) !void {
|
|
728
|
+
if (chunks.len == 0) {
|
|
729
|
+
if (self.placeholder_syntax_style) |style| {
|
|
730
|
+
style.deinit();
|
|
731
|
+
self.placeholder_syntax_style = null;
|
|
732
|
+
}
|
|
733
|
+
if (self.placeholder_buffer) |placeholder| {
|
|
734
|
+
placeholder.deinit();
|
|
735
|
+
self.placeholder_buffer = null;
|
|
736
|
+
}
|
|
737
|
+
if (self.placeholder_active) {
|
|
738
|
+
self.text_buffer_view.switchToOriginalBuffer();
|
|
739
|
+
self.placeholder_active = false;
|
|
740
|
+
}
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (self.placeholder_buffer == null) {
|
|
745
|
+
self.placeholder_buffer = try UnifiedTextBuffer.init(
|
|
746
|
+
self.global_allocator,
|
|
747
|
+
self.edit_buffer.tb.pool,
|
|
748
|
+
self.edit_buffer.tb.link_pool,
|
|
749
|
+
self.edit_buffer.tb.width_method,
|
|
750
|
+
);
|
|
751
|
+
const syntax_style = try ss.SyntaxStyle.init(self.global_allocator);
|
|
752
|
+
self.placeholder_syntax_style = syntax_style;
|
|
753
|
+
const placeholder = self.placeholder_buffer.?;
|
|
754
|
+
placeholder.setSyntaxStyle(syntax_style);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const placeholder = self.placeholder_buffer.?;
|
|
758
|
+
|
|
759
|
+
try placeholder.setStyledText(chunks);
|
|
760
|
+
|
|
761
|
+
if (self.placeholder_active) {
|
|
762
|
+
self.text_buffer_view.virtual_lines_dirty = true;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
self.updatePlaceholderVisibility();
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
fn shouldShowPlaceholder(self: *const EditorView) bool {
|
|
769
|
+
const rope_len = self.edit_buffer.tb.rope().totalWeight();
|
|
770
|
+
return rope_len == 0 and self.placeholder_buffer != null;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
fn updatePlaceholderVisibility(self: *EditorView) void {
|
|
774
|
+
const should_show = self.shouldShowPlaceholder();
|
|
775
|
+
|
|
776
|
+
if (should_show and !self.placeholder_active) {
|
|
777
|
+
if (self.placeholder_buffer) |placeholder| {
|
|
778
|
+
self.text_buffer_view.switchToBuffer(placeholder);
|
|
779
|
+
self.placeholder_active = true;
|
|
780
|
+
}
|
|
781
|
+
} else if (!should_show and self.placeholder_active) {
|
|
782
|
+
self.text_buffer_view.switchToOriginalBuffer();
|
|
783
|
+
self.placeholder_active = false;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
pub fn setTabIndicator(self: *EditorView, indicator: ?u32) void {
|
|
788
|
+
self.text_buffer_view.setTabIndicator(indicator);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
pub fn getTabIndicator(self: *const EditorView) ?u32 {
|
|
792
|
+
return self.text_buffer_view.getTabIndicator();
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
pub fn setTabIndicatorColor(self: *EditorView, color: ?tb.RGBA) void {
|
|
796
|
+
self.text_buffer_view.setTabIndicatorColor(color);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
pub fn getTabIndicatorColor(self: *const EditorView) ?tb.RGBA {
|
|
800
|
+
return self.text_buffer_view.getTabIndicatorColor();
|
|
801
|
+
}
|
|
802
|
+
};
|