@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,666 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const text_buffer = @import("../text-buffer.zig");
|
|
3
|
+
const gp = @import("../grapheme.zig");
|
|
4
|
+
const link = @import("../link.zig");
|
|
5
|
+
const ss = @import("../syntax-style.zig");
|
|
6
|
+
|
|
7
|
+
const TextBuffer = text_buffer.UnifiedTextBuffer;
|
|
8
|
+
const RGBA = text_buffer.RGBA;
|
|
9
|
+
const Highlight = text_buffer.Highlight;
|
|
10
|
+
|
|
11
|
+
test "TextBuffer coords - addHighlightByCoords" {
|
|
12
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
13
|
+
defer gp.deinitGlobalPool();
|
|
14
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
15
|
+
defer link.deinitGlobalLinkPool();
|
|
16
|
+
|
|
17
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
18
|
+
defer tb.deinit();
|
|
19
|
+
|
|
20
|
+
try tb.setText("Hello\nWorld");
|
|
21
|
+
|
|
22
|
+
try tb.addHighlightByCoords(0, 1, 0, 5, 1, 1, 0);
|
|
23
|
+
|
|
24
|
+
const highlights = tb.getLineHighlights(0);
|
|
25
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
26
|
+
try std.testing.expectEqual(@as(u32, 1), highlights[0].col_start);
|
|
27
|
+
try std.testing.expectEqual(@as(u32, 5), highlights[0].col_end);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test "TextBuffer coords - addHighlightByCoords multi-line" {
|
|
31
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
32
|
+
defer gp.deinitGlobalPool();
|
|
33
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
34
|
+
defer link.deinitGlobalLinkPool();
|
|
35
|
+
|
|
36
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
37
|
+
defer tb.deinit();
|
|
38
|
+
|
|
39
|
+
try tb.setText("Hello\nWorld");
|
|
40
|
+
|
|
41
|
+
try tb.addHighlightByCoords(0, 3, 1, 3, 1, 1, 0);
|
|
42
|
+
|
|
43
|
+
const line0_highlights = tb.getLineHighlights(0);
|
|
44
|
+
const line1_highlights = tb.getLineHighlights(1);
|
|
45
|
+
|
|
46
|
+
try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
|
|
47
|
+
try std.testing.expectEqual(@as(usize, 1), line1_highlights.len);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ===== Highlight System Tests =====
|
|
51
|
+
|
|
52
|
+
test "TextBuffer highlights - add single highlight to line" {
|
|
53
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
54
|
+
defer gp.deinitGlobalPool();
|
|
55
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
56
|
+
defer link.deinitGlobalLinkPool();
|
|
57
|
+
|
|
58
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
59
|
+
defer tb.deinit();
|
|
60
|
+
|
|
61
|
+
try tb.setText("Hello World");
|
|
62
|
+
|
|
63
|
+
try tb.addHighlight(0, 0, 5, 1, 0, 0);
|
|
64
|
+
|
|
65
|
+
const highlights = tb.getLineHighlights(0);
|
|
66
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
67
|
+
try std.testing.expectEqual(@as(u32, 0), highlights[0].col_start);
|
|
68
|
+
try std.testing.expectEqual(@as(u32, 5), highlights[0].col_end);
|
|
69
|
+
try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
test "TextBuffer highlights - add multiple highlights to same line" {
|
|
73
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
74
|
+
defer gp.deinitGlobalPool();
|
|
75
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
76
|
+
defer link.deinitGlobalLinkPool();
|
|
77
|
+
|
|
78
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
79
|
+
defer tb.deinit();
|
|
80
|
+
|
|
81
|
+
try tb.setText("Hello World");
|
|
82
|
+
|
|
83
|
+
try tb.addHighlight(0, 0, 5, 1, 0, 0);
|
|
84
|
+
try tb.addHighlight(0, 6, 11, 2, 0, 0);
|
|
85
|
+
|
|
86
|
+
const highlights = tb.getLineHighlights(0);
|
|
87
|
+
try std.testing.expectEqual(@as(usize, 2), highlights.len);
|
|
88
|
+
try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
|
|
89
|
+
try std.testing.expectEqual(@as(u32, 2), highlights[1].style_id);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
test "TextBuffer highlights - add highlights to multiple lines" {
|
|
93
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
94
|
+
defer gp.deinitGlobalPool();
|
|
95
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
96
|
+
defer link.deinitGlobalLinkPool();
|
|
97
|
+
|
|
98
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
99
|
+
defer tb.deinit();
|
|
100
|
+
|
|
101
|
+
try tb.setText("Line 1\nLine 2\nLine 3");
|
|
102
|
+
|
|
103
|
+
try tb.addHighlight(0, 0, 6, 1, 0, 0);
|
|
104
|
+
try tb.addHighlight(1, 0, 6, 2, 0, 0);
|
|
105
|
+
try tb.addHighlight(2, 0, 6, 3, 0, 0);
|
|
106
|
+
|
|
107
|
+
try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(0).len);
|
|
108
|
+
try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(1).len);
|
|
109
|
+
try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(2).len);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
test "TextBuffer highlights - remove highlights by reference" {
|
|
113
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
114
|
+
defer gp.deinitGlobalPool();
|
|
115
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
116
|
+
defer link.deinitGlobalLinkPool();
|
|
117
|
+
|
|
118
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
119
|
+
defer tb.deinit();
|
|
120
|
+
|
|
121
|
+
try tb.setText("Line 1\nLine 2");
|
|
122
|
+
|
|
123
|
+
try tb.addHighlight(0, 0, 3, 1, 0, 100);
|
|
124
|
+
try tb.addHighlight(0, 3, 6, 2, 0, 200);
|
|
125
|
+
try tb.addHighlight(1, 0, 6, 3, 0, 100);
|
|
126
|
+
|
|
127
|
+
tb.removeHighlightsByRef(100);
|
|
128
|
+
|
|
129
|
+
const line0_highlights = tb.getLineHighlights(0);
|
|
130
|
+
const line1_highlights = tb.getLineHighlights(1);
|
|
131
|
+
|
|
132
|
+
try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
|
|
133
|
+
try std.testing.expectEqual(@as(u32, 2), line0_highlights[0].style_id);
|
|
134
|
+
try std.testing.expectEqual(@as(usize, 0), line1_highlights.len);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
test "TextBuffer highlights - clear line highlights" {
|
|
138
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
139
|
+
defer gp.deinitGlobalPool();
|
|
140
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
141
|
+
defer link.deinitGlobalLinkPool();
|
|
142
|
+
|
|
143
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
144
|
+
defer tb.deinit();
|
|
145
|
+
|
|
146
|
+
try tb.setText("Line 1\nLine 2");
|
|
147
|
+
|
|
148
|
+
try tb.addHighlight(0, 0, 6, 1, 0, 0);
|
|
149
|
+
try tb.addHighlight(0, 6, 10, 2, 0, 0);
|
|
150
|
+
|
|
151
|
+
tb.clearLineHighlights(0);
|
|
152
|
+
|
|
153
|
+
const highlights = tb.getLineHighlights(0);
|
|
154
|
+
try std.testing.expectEqual(@as(usize, 0), highlights.len);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
test "TextBuffer highlights - clear all highlights" {
|
|
158
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
159
|
+
defer gp.deinitGlobalPool();
|
|
160
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
161
|
+
defer link.deinitGlobalLinkPool();
|
|
162
|
+
|
|
163
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
164
|
+
defer tb.deinit();
|
|
165
|
+
|
|
166
|
+
try tb.setText("Line 1\nLine 2\nLine 3");
|
|
167
|
+
|
|
168
|
+
try tb.addHighlight(0, 0, 6, 1, 0, 0);
|
|
169
|
+
try tb.addHighlight(1, 0, 6, 2, 0, 0);
|
|
170
|
+
try tb.addHighlight(2, 0, 6, 3, 0, 0);
|
|
171
|
+
|
|
172
|
+
tb.clearAllHighlights();
|
|
173
|
+
|
|
174
|
+
try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(0).len);
|
|
175
|
+
try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(1).len);
|
|
176
|
+
try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(2).len);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test "TextBuffer highlights - get highlights from non-existent line" {
|
|
180
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
181
|
+
defer gp.deinitGlobalPool();
|
|
182
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
183
|
+
defer link.deinitGlobalLinkPool();
|
|
184
|
+
|
|
185
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
186
|
+
defer tb.deinit();
|
|
187
|
+
|
|
188
|
+
try tb.setText("Line 1");
|
|
189
|
+
|
|
190
|
+
// Get highlights from line that doesn't have any
|
|
191
|
+
const highlights = tb.getLineHighlights(10);
|
|
192
|
+
try std.testing.expectEqual(@as(usize, 0), highlights.len);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
test "TextBuffer highlights - overlapping highlights" {
|
|
196
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
197
|
+
defer gp.deinitGlobalPool();
|
|
198
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
199
|
+
defer link.deinitGlobalLinkPool();
|
|
200
|
+
|
|
201
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
202
|
+
defer tb.deinit();
|
|
203
|
+
|
|
204
|
+
try tb.setText("Hello World");
|
|
205
|
+
|
|
206
|
+
try tb.addHighlight(0, 0, 8, 1, 0, 0);
|
|
207
|
+
try tb.addHighlight(0, 5, 11, 2, 0, 0);
|
|
208
|
+
|
|
209
|
+
const highlights = tb.getLineHighlights(0);
|
|
210
|
+
try std.testing.expectEqual(@as(usize, 2), highlights.len);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
test "TextBuffer highlights - reset clears highlights" {
|
|
214
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
215
|
+
defer gp.deinitGlobalPool();
|
|
216
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
217
|
+
defer link.deinitGlobalLinkPool();
|
|
218
|
+
|
|
219
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
220
|
+
defer tb.deinit();
|
|
221
|
+
|
|
222
|
+
try tb.setText("Hello World");
|
|
223
|
+
try tb.addHighlight(0, 0, 5, 1, 0, 0);
|
|
224
|
+
|
|
225
|
+
tb.reset();
|
|
226
|
+
|
|
227
|
+
const highlights = tb.getLineHighlights(0);
|
|
228
|
+
try std.testing.expectEqual(@as(usize, 0), highlights.len);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
test "TextBuffer highlights - setSyntaxStyle and getSyntaxStyle" {
|
|
232
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
233
|
+
defer gp.deinitGlobalPool();
|
|
234
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
235
|
+
defer link.deinitGlobalLinkPool();
|
|
236
|
+
|
|
237
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
238
|
+
defer tb.deinit();
|
|
239
|
+
|
|
240
|
+
var syntax_style = try ss.SyntaxStyle.init(std.testing.allocator);
|
|
241
|
+
defer syntax_style.deinit();
|
|
242
|
+
|
|
243
|
+
try std.testing.expect(tb.getSyntaxStyle() == null);
|
|
244
|
+
|
|
245
|
+
tb.setSyntaxStyle(syntax_style);
|
|
246
|
+
try std.testing.expect(tb.getSyntaxStyle() != null);
|
|
247
|
+
|
|
248
|
+
tb.setSyntaxStyle(null);
|
|
249
|
+
try std.testing.expect(tb.getSyntaxStyle() == null);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
test "TextBuffer highlights - integration with SyntaxStyle" {
|
|
253
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
254
|
+
defer gp.deinitGlobalPool();
|
|
255
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
256
|
+
defer link.deinitGlobalLinkPool();
|
|
257
|
+
|
|
258
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
259
|
+
defer tb.deinit();
|
|
260
|
+
|
|
261
|
+
var syntax_style = try ss.SyntaxStyle.init(std.testing.allocator);
|
|
262
|
+
defer syntax_style.deinit();
|
|
263
|
+
|
|
264
|
+
const keyword_id = try syntax_style.registerStyle("keyword", RGBA{ 1.0, 0.0, 0.0, 1.0 }, null, 0);
|
|
265
|
+
const string_id = try syntax_style.registerStyle("string", RGBA{ 0.0, 1.0, 0.0, 1.0 }, null, 0);
|
|
266
|
+
const comment_id = try syntax_style.registerStyle("comment", RGBA{ 0.5, 0.5, 0.5, 1.0 }, null, 0);
|
|
267
|
+
|
|
268
|
+
try tb.setText("function hello() // comment");
|
|
269
|
+
tb.setSyntaxStyle(syntax_style);
|
|
270
|
+
|
|
271
|
+
try tb.addHighlight(0, 0, 8, keyword_id, 1, 0);
|
|
272
|
+
try tb.addHighlight(0, 9, 14, string_id, 1, 0);
|
|
273
|
+
try tb.addHighlight(0, 17, 27, comment_id, 1, 0);
|
|
274
|
+
|
|
275
|
+
const highlights = tb.getLineHighlights(0);
|
|
276
|
+
try std.testing.expectEqual(@as(usize, 3), highlights.len);
|
|
277
|
+
|
|
278
|
+
const style = tb.getSyntaxStyle().?;
|
|
279
|
+
try std.testing.expect(style.resolveById(keyword_id) != null);
|
|
280
|
+
try std.testing.expect(style.resolveById(string_id) != null);
|
|
281
|
+
try std.testing.expect(style.resolveById(comment_id) != null);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
test "TextBuffer highlights - style spans computed correctly" {
|
|
285
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
286
|
+
defer gp.deinitGlobalPool();
|
|
287
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
288
|
+
defer link.deinitGlobalLinkPool();
|
|
289
|
+
|
|
290
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
291
|
+
defer tb.deinit();
|
|
292
|
+
|
|
293
|
+
try tb.setText("0123456789");
|
|
294
|
+
|
|
295
|
+
try tb.addHighlight(0, 0, 3, 1, 1, 0);
|
|
296
|
+
try tb.addHighlight(0, 5, 8, 2, 1, 0);
|
|
297
|
+
|
|
298
|
+
const spans = tb.getLineSpans(0);
|
|
299
|
+
try std.testing.expect(spans.len > 0);
|
|
300
|
+
|
|
301
|
+
// Should have spans for: [0-3 style:1], [3-5 style:0/default], [5-8 style:2], ...
|
|
302
|
+
var found_style1 = false;
|
|
303
|
+
var found_style2 = false;
|
|
304
|
+
for (spans) |span| {
|
|
305
|
+
if (span.style_id == 1) found_style1 = true;
|
|
306
|
+
if (span.style_id == 2) found_style2 = true;
|
|
307
|
+
}
|
|
308
|
+
try std.testing.expect(found_style1);
|
|
309
|
+
try std.testing.expect(found_style2);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
test "TextBuffer highlights - priority handling in spans" {
|
|
313
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
314
|
+
defer gp.deinitGlobalPool();
|
|
315
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
316
|
+
defer link.deinitGlobalLinkPool();
|
|
317
|
+
|
|
318
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
319
|
+
defer tb.deinit();
|
|
320
|
+
|
|
321
|
+
try tb.setText("0123456789");
|
|
322
|
+
|
|
323
|
+
try tb.addHighlight(0, 0, 8, 1, 1, 0);
|
|
324
|
+
try tb.addHighlight(0, 3, 6, 2, 5, 0);
|
|
325
|
+
|
|
326
|
+
const spans = tb.getLineSpans(0);
|
|
327
|
+
try std.testing.expect(spans.len > 0);
|
|
328
|
+
|
|
329
|
+
// In range 3-6, style 2 should win due to higher priority
|
|
330
|
+
var found_high_priority = false;
|
|
331
|
+
for (spans) |span| {
|
|
332
|
+
if (span.col >= 3 and span.col < 6 and span.style_id == 2) {
|
|
333
|
+
found_high_priority = true;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
try std.testing.expect(found_high_priority);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ===== Character Range Highlight Tests =====
|
|
340
|
+
|
|
341
|
+
test "TextBuffer char range highlights - single line highlight" {
|
|
342
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
343
|
+
defer gp.deinitGlobalPool();
|
|
344
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
345
|
+
defer link.deinitGlobalLinkPool();
|
|
346
|
+
|
|
347
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
348
|
+
defer tb.deinit();
|
|
349
|
+
|
|
350
|
+
try tb.setText("Hello World");
|
|
351
|
+
|
|
352
|
+
try tb.addHighlightByCharRange(0, 5, 1, 1, 0);
|
|
353
|
+
|
|
354
|
+
const highlights = tb.getLineHighlights(0);
|
|
355
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
356
|
+
try std.testing.expectEqual(@as(u32, 0), highlights[0].col_start);
|
|
357
|
+
try std.testing.expectEqual(@as(u32, 5), highlights[0].col_end);
|
|
358
|
+
try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
test "TextBuffer char range highlights - multi-line highlight" {
|
|
362
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
363
|
+
defer gp.deinitGlobalPool();
|
|
364
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
365
|
+
defer link.deinitGlobalLinkPool();
|
|
366
|
+
|
|
367
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
368
|
+
defer tb.deinit();
|
|
369
|
+
|
|
370
|
+
// "Hello" = 5 chars (0-4, newlines not counted in offsets)
|
|
371
|
+
// "World" = 5 chars (5-9, newlines not counted in offsets)
|
|
372
|
+
// "Test" = 4 chars (10-13, newlines not counted in offsets)
|
|
373
|
+
try tb.setText("Hello\nWorld\nTest");
|
|
374
|
+
|
|
375
|
+
// Highlight from middle of line 0 to middle of line 1 (chars 3-9, not counting newlines)
|
|
376
|
+
// char 3 = 'l' in "Hello", char 9 = 'd' in "World" (last char)
|
|
377
|
+
try tb.addHighlightByCharRange(3, 9, 1, 1, 0);
|
|
378
|
+
|
|
379
|
+
const line0_highlights = tb.getLineHighlights(0);
|
|
380
|
+
const line1_highlights = tb.getLineHighlights(1);
|
|
381
|
+
|
|
382
|
+
try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
|
|
383
|
+
try std.testing.expectEqual(@as(usize, 1), line1_highlights.len);
|
|
384
|
+
|
|
385
|
+
// Line 0: highlight from col 3 to end (col 5)
|
|
386
|
+
try std.testing.expectEqual(@as(u32, 3), line0_highlights[0].col_start);
|
|
387
|
+
try std.testing.expectEqual(@as(u32, 5), line0_highlights[0].col_end);
|
|
388
|
+
|
|
389
|
+
// Line 1: highlight from start (col 0) to col 4 (chars 5,6,7,8 = cols 0,1,2,3)
|
|
390
|
+
try std.testing.expectEqual(@as(u32, 0), line1_highlights[0].col_start);
|
|
391
|
+
try std.testing.expectEqual(@as(u32, 4), line1_highlights[0].col_end);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
test "TextBuffer char range highlights - spanning three lines" {
|
|
395
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
396
|
+
defer gp.deinitGlobalPool();
|
|
397
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
398
|
+
defer link.deinitGlobalLinkPool();
|
|
399
|
+
|
|
400
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
401
|
+
defer tb.deinit();
|
|
402
|
+
|
|
403
|
+
try tb.setText("Line1\nLine2\nLine3");
|
|
404
|
+
|
|
405
|
+
try tb.addHighlightByCharRange(3, 13, 1, 1, 0);
|
|
406
|
+
|
|
407
|
+
const line0_highlights = tb.getLineHighlights(0);
|
|
408
|
+
const line1_highlights = tb.getLineHighlights(1);
|
|
409
|
+
const line2_highlights = tb.getLineHighlights(2);
|
|
410
|
+
|
|
411
|
+
try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
|
|
412
|
+
try std.testing.expectEqual(@as(usize, 1), line1_highlights.len);
|
|
413
|
+
try std.testing.expectEqual(@as(usize, 1), line2_highlights.len);
|
|
414
|
+
|
|
415
|
+
try std.testing.expectEqual(@as(u32, 3), line0_highlights[0].col_start);
|
|
416
|
+
|
|
417
|
+
try std.testing.expectEqual(@as(u32, 0), line1_highlights[0].col_start);
|
|
418
|
+
|
|
419
|
+
try std.testing.expectEqual(@as(u32, 0), line2_highlights[0].col_start);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
test "TextBuffer char range highlights - exact line boundaries" {
|
|
423
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
424
|
+
defer gp.deinitGlobalPool();
|
|
425
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
426
|
+
defer link.deinitGlobalLinkPool();
|
|
427
|
+
|
|
428
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
429
|
+
defer tb.deinit();
|
|
430
|
+
|
|
431
|
+
try tb.setText("AAAA\nBBBB\nCCCC");
|
|
432
|
+
|
|
433
|
+
// Highlight entire first line (chars 0-4, excluding newline)
|
|
434
|
+
try tb.addHighlightByCharRange(0, 4, 1, 1, 0);
|
|
435
|
+
|
|
436
|
+
const line0_highlights = tb.getLineHighlights(0);
|
|
437
|
+
try std.testing.expectEqual(@as(usize, 1), line0_highlights.len);
|
|
438
|
+
try std.testing.expectEqual(@as(u32, 0), line0_highlights[0].col_start);
|
|
439
|
+
try std.testing.expectEqual(@as(u32, 4), line0_highlights[0].col_end);
|
|
440
|
+
|
|
441
|
+
// Line 1 should have no highlights
|
|
442
|
+
const line1_highlights = tb.getLineHighlights(1);
|
|
443
|
+
try std.testing.expectEqual(@as(usize, 0), line1_highlights.len);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
test "TextBuffer char range highlights - empty range" {
|
|
447
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
448
|
+
defer gp.deinitGlobalPool();
|
|
449
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
450
|
+
defer link.deinitGlobalLinkPool();
|
|
451
|
+
|
|
452
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
453
|
+
defer tb.deinit();
|
|
454
|
+
|
|
455
|
+
try tb.setText("Hello World");
|
|
456
|
+
|
|
457
|
+
// Empty range (start == end) should add no highlights
|
|
458
|
+
try tb.addHighlightByCharRange(5, 5, 1, 1, 0);
|
|
459
|
+
|
|
460
|
+
const highlights = tb.getLineHighlights(0);
|
|
461
|
+
try std.testing.expectEqual(@as(usize, 0), highlights.len);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
test "TextBuffer char range highlights - invalid range" {
|
|
465
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
466
|
+
defer gp.deinitGlobalPool();
|
|
467
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
468
|
+
defer link.deinitGlobalLinkPool();
|
|
469
|
+
|
|
470
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
471
|
+
defer tb.deinit();
|
|
472
|
+
|
|
473
|
+
try tb.setText("Hello World");
|
|
474
|
+
|
|
475
|
+
// Invalid range (start > end) should add no highlights
|
|
476
|
+
try tb.addHighlightByCharRange(10, 5, 1, 1, 0);
|
|
477
|
+
|
|
478
|
+
const highlights = tb.getLineHighlights(0);
|
|
479
|
+
try std.testing.expectEqual(@as(usize, 0), highlights.len);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
test "TextBuffer char range highlights - out of bounds range" {
|
|
483
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
484
|
+
defer gp.deinitGlobalPool();
|
|
485
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
486
|
+
defer link.deinitGlobalLinkPool();
|
|
487
|
+
|
|
488
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
489
|
+
defer tb.deinit();
|
|
490
|
+
|
|
491
|
+
try tb.setText("Hello");
|
|
492
|
+
|
|
493
|
+
// Range extends beyond text length - should handle gracefully
|
|
494
|
+
try tb.addHighlightByCharRange(3, 100, 1, 1, 0);
|
|
495
|
+
|
|
496
|
+
const highlights = tb.getLineHighlights(0);
|
|
497
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
498
|
+
try std.testing.expectEqual(@as(u32, 3), highlights[0].col_start);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
test "TextBuffer char range highlights - multiple non-overlapping ranges" {
|
|
502
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
503
|
+
defer gp.deinitGlobalPool();
|
|
504
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
505
|
+
defer link.deinitGlobalLinkPool();
|
|
506
|
+
|
|
507
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
508
|
+
defer tb.deinit();
|
|
509
|
+
|
|
510
|
+
try tb.setText("function hello() { return 42; }");
|
|
511
|
+
|
|
512
|
+
try tb.addHighlightByCharRange(0, 8, 1, 1, 0);
|
|
513
|
+
try tb.addHighlightByCharRange(9, 14, 2, 1, 0);
|
|
514
|
+
try tb.addHighlightByCharRange(19, 25, 3, 1, 0);
|
|
515
|
+
|
|
516
|
+
const highlights = tb.getLineHighlights(0);
|
|
517
|
+
try std.testing.expectEqual(@as(usize, 3), highlights.len);
|
|
518
|
+
try std.testing.expectEqual(@as(u32, 1), highlights[0].style_id);
|
|
519
|
+
try std.testing.expectEqual(@as(u32, 2), highlights[1].style_id);
|
|
520
|
+
try std.testing.expectEqual(@as(u32, 3), highlights[2].style_id);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
test "TextBuffer char range highlights - with reference ID for removal" {
|
|
524
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
525
|
+
defer gp.deinitGlobalPool();
|
|
526
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
527
|
+
defer link.deinitGlobalLinkPool();
|
|
528
|
+
|
|
529
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
530
|
+
defer tb.deinit();
|
|
531
|
+
|
|
532
|
+
try tb.setText("Line1\nLine2\nLine3");
|
|
533
|
+
|
|
534
|
+
try tb.addHighlightByCharRange(0, 5, 1, 1, 100);
|
|
535
|
+
try tb.addHighlightByCharRange(6, 11, 2, 1, 100);
|
|
536
|
+
|
|
537
|
+
try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(0).len);
|
|
538
|
+
try std.testing.expectEqual(@as(usize, 1), tb.getLineHighlights(1).len);
|
|
539
|
+
|
|
540
|
+
tb.removeHighlightsByRef(100);
|
|
541
|
+
try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(0).len);
|
|
542
|
+
try std.testing.expectEqual(@as(usize, 0), tb.getLineHighlights(1).len);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
test "TextBuffer char range highlights - priority handling" {
|
|
546
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
547
|
+
defer gp.deinitGlobalPool();
|
|
548
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
549
|
+
defer link.deinitGlobalLinkPool();
|
|
550
|
+
|
|
551
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
552
|
+
defer tb.deinit();
|
|
553
|
+
|
|
554
|
+
try tb.setText("0123456789");
|
|
555
|
+
|
|
556
|
+
try tb.addHighlightByCharRange(0, 8, 1, 1, 0);
|
|
557
|
+
try tb.addHighlightByCharRange(3, 6, 2, 5, 0);
|
|
558
|
+
|
|
559
|
+
const spans = tb.getLineSpans(0);
|
|
560
|
+
try std.testing.expect(spans.len > 0);
|
|
561
|
+
|
|
562
|
+
// Higher priority should win in overlap region
|
|
563
|
+
var found_high_priority = false;
|
|
564
|
+
for (spans) |span| {
|
|
565
|
+
if (span.col >= 3 and span.col < 6 and span.style_id == 2) {
|
|
566
|
+
found_high_priority = true;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
try std.testing.expect(found_high_priority);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
test "TextBuffer char range highlights - unicode text" {
|
|
573
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
574
|
+
defer gp.deinitGlobalPool();
|
|
575
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
576
|
+
defer link.deinitGlobalLinkPool();
|
|
577
|
+
|
|
578
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
579
|
+
defer tb.deinit();
|
|
580
|
+
|
|
581
|
+
try tb.setText("Hello 世界 🌟");
|
|
582
|
+
|
|
583
|
+
const text_len = tb.getLength();
|
|
584
|
+
try tb.addHighlightByCharRange(0, text_len, 1, 1, 0);
|
|
585
|
+
|
|
586
|
+
const highlights = tb.getLineHighlights(0);
|
|
587
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
test "TextBuffer char range highlights - preserved after setText" {
|
|
591
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
592
|
+
defer gp.deinitGlobalPool();
|
|
593
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
594
|
+
defer link.deinitGlobalLinkPool();
|
|
595
|
+
|
|
596
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
597
|
+
defer tb.deinit();
|
|
598
|
+
|
|
599
|
+
try tb.setText("Hello World");
|
|
600
|
+
try tb.addHighlightByCharRange(0, 5, 1, 1, 0);
|
|
601
|
+
|
|
602
|
+
// Set new text - with clear() highlights are now preserved
|
|
603
|
+
try tb.setText("New Text");
|
|
604
|
+
|
|
605
|
+
const highlights = tb.getLineHighlights(0);
|
|
606
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
607
|
+
|
|
608
|
+
// To clear highlights, caller must explicitly call clearAllHighlights
|
|
609
|
+
tb.clearAllHighlights();
|
|
610
|
+
const cleared_highlights = tb.getLineHighlights(0);
|
|
611
|
+
try std.testing.expectEqual(@as(usize, 0), cleared_highlights.len);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
test "TextBuffer char range highlights - multi-width chars before highlight" {
|
|
615
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
616
|
+
defer gp.deinitGlobalPool();
|
|
617
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
618
|
+
defer link.deinitGlobalLinkPool();
|
|
619
|
+
|
|
620
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
621
|
+
defer tb.deinit();
|
|
622
|
+
|
|
623
|
+
try tb.setText("前后端分离 @git-committer");
|
|
624
|
+
try tb.addHighlightByCharRange(11, 25, 1, 1, 0);
|
|
625
|
+
|
|
626
|
+
const highlights = tb.getLineHighlights(0);
|
|
627
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
628
|
+
try std.testing.expectEqual(@as(u32, 11), highlights[0].col_start);
|
|
629
|
+
try std.testing.expectEqual(@as(u32, 25), highlights[0].col_end);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
test "TextBuffer char range highlights - multi-width chars between highlights" {
|
|
633
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
634
|
+
defer gp.deinitGlobalPool();
|
|
635
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
636
|
+
defer link.deinitGlobalLinkPool();
|
|
637
|
+
|
|
638
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
639
|
+
defer tb.deinit();
|
|
640
|
+
|
|
641
|
+
try tb.setText("abc前后端def");
|
|
642
|
+
try tb.addHighlightByCharRange(9, 12, 1, 1, 0);
|
|
643
|
+
|
|
644
|
+
const highlights = tb.getLineHighlights(0);
|
|
645
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
646
|
+
try std.testing.expectEqual(@as(u32, 9), highlights[0].col_start);
|
|
647
|
+
try std.testing.expectEqual(@as(u32, 12), highlights[0].col_end);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
test "TextBuffer char range highlights - emoji grapheme clusters" {
|
|
651
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
652
|
+
defer gp.deinitGlobalPool();
|
|
653
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
654
|
+
defer link.deinitGlobalLinkPool();
|
|
655
|
+
|
|
656
|
+
var tb = try TextBuffer.init(std.testing.allocator, pool, link_pool, .unicode);
|
|
657
|
+
defer tb.deinit();
|
|
658
|
+
|
|
659
|
+
try tb.setText("前🌟test");
|
|
660
|
+
try tb.addHighlightByCharRange(4, 8, 1, 1, 0);
|
|
661
|
+
|
|
662
|
+
const highlights = tb.getLineHighlights(0);
|
|
663
|
+
try std.testing.expectEqual(@as(usize, 1), highlights.len);
|
|
664
|
+
try std.testing.expectEqual(@as(u32, 4), highlights[0].col_start);
|
|
665
|
+
try std.testing.expectEqual(@as(u32, 8), highlights[0].col_end);
|
|
666
|
+
}
|