@fairyhunter13/opentui-core 0.1.113 → 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 +62 -53
- 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-9vwc3fg6.js +0 -12260
- package/index-9vwc3fg6.js.map +0 -42
- package/index-dcj62y8t.js +0 -20614
- package/index-dcj62y8t.js.map +0 -67
- package/index-f7n39gpy.js +0 -411
- package/index-f7n39gpy.js.map +0 -10
- 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,1689 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const edit_buffer = @import("../edit-buffer.zig");
|
|
3
|
+
const text_buffer = @import("../text-buffer.zig");
|
|
4
|
+
const text_buffer_view = @import("../text-buffer-view.zig");
|
|
5
|
+
const gp = @import("../grapheme.zig");
|
|
6
|
+
const link = @import("../link.zig");
|
|
7
|
+
const iter_mod = @import("../text-buffer-iterators.zig");
|
|
8
|
+
|
|
9
|
+
const EditBuffer = edit_buffer.EditBuffer;
|
|
10
|
+
const TextBufferView = text_buffer_view.TextBufferView;
|
|
11
|
+
const Cursor = edit_buffer.Cursor;
|
|
12
|
+
|
|
13
|
+
test "EditBuffer - init and deinit" {
|
|
14
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
15
|
+
defer gp.deinitGlobalPool();
|
|
16
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
17
|
+
defer link.deinitGlobalLinkPool();
|
|
18
|
+
|
|
19
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
20
|
+
defer eb.deinit();
|
|
21
|
+
|
|
22
|
+
try std.testing.expectEqual(@as(u32, 0), eb.getTextBuffer().getLength());
|
|
23
|
+
const cursor = eb.getCursor(0);
|
|
24
|
+
try std.testing.expect(cursor != null);
|
|
25
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.?.row);
|
|
26
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.?.col);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test "EditBuffer - next word boundary basic" {
|
|
30
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
31
|
+
defer gp.deinitGlobalPool();
|
|
32
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
33
|
+
defer link.deinitGlobalLinkPool();
|
|
34
|
+
|
|
35
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
36
|
+
defer eb.deinit();
|
|
37
|
+
|
|
38
|
+
try eb.insertText("Hello World");
|
|
39
|
+
try eb.setCursor(0, 0);
|
|
40
|
+
|
|
41
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
42
|
+
try std.testing.expectEqual(@as(u32, 0), next_cursor.row);
|
|
43
|
+
try std.testing.expectEqual(@as(u32, 6), next_cursor.col);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test "EditBuffer - prev word boundary basic" {
|
|
47
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
48
|
+
defer gp.deinitGlobalPool();
|
|
49
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
50
|
+
defer link.deinitGlobalLinkPool();
|
|
51
|
+
|
|
52
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
53
|
+
defer eb.deinit();
|
|
54
|
+
|
|
55
|
+
try eb.insertText("Hello World");
|
|
56
|
+
try eb.setCursor(0, 7);
|
|
57
|
+
|
|
58
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
59
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor.row);
|
|
60
|
+
try std.testing.expectEqual(@as(u32, 6), prev_cursor.col);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test "EditBuffer - next word boundary across line" {
|
|
64
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
65
|
+
defer gp.deinitGlobalPool();
|
|
66
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
67
|
+
defer link.deinitGlobalLinkPool();
|
|
68
|
+
|
|
69
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
70
|
+
defer eb.deinit();
|
|
71
|
+
|
|
72
|
+
try eb.insertText("Hello\nWorld");
|
|
73
|
+
try eb.setCursor(0, 5);
|
|
74
|
+
|
|
75
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
76
|
+
try std.testing.expectEqual(@as(u32, 1), next_cursor.row);
|
|
77
|
+
try std.testing.expectEqual(@as(u32, 0), next_cursor.col);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test "EditBuffer - prev word boundary across line" {
|
|
81
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
82
|
+
defer gp.deinitGlobalPool();
|
|
83
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
84
|
+
defer link.deinitGlobalLinkPool();
|
|
85
|
+
|
|
86
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
87
|
+
defer eb.deinit();
|
|
88
|
+
|
|
89
|
+
try eb.insertText("Hello\nWorld");
|
|
90
|
+
try eb.setCursor(1, 0);
|
|
91
|
+
|
|
92
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
93
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor.row);
|
|
94
|
+
try std.testing.expectEqual(@as(u32, 5), prev_cursor.col);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
test "EditBuffer - hyphen word boundary" {
|
|
98
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
99
|
+
defer gp.deinitGlobalPool();
|
|
100
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
101
|
+
defer link.deinitGlobalLinkPool();
|
|
102
|
+
|
|
103
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
104
|
+
defer eb.deinit();
|
|
105
|
+
|
|
106
|
+
try eb.insertText("self-contained");
|
|
107
|
+
try eb.setCursor(0, 0);
|
|
108
|
+
|
|
109
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
110
|
+
try std.testing.expectEqual(@as(u32, 0), next_cursor.row);
|
|
111
|
+
try std.testing.expectEqual(@as(u32, 5), next_cursor.col);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
test "EditBuffer - multiple word boundaries" {
|
|
115
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
116
|
+
defer gp.deinitGlobalPool();
|
|
117
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
118
|
+
defer link.deinitGlobalLinkPool();
|
|
119
|
+
|
|
120
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
121
|
+
defer eb.deinit();
|
|
122
|
+
|
|
123
|
+
try eb.insertText("The quick brown fox");
|
|
124
|
+
try eb.setCursor(0, 0);
|
|
125
|
+
|
|
126
|
+
var cursor = eb.getNextWordBoundary();
|
|
127
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
128
|
+
|
|
129
|
+
try eb.setCursor(cursor.row, cursor.col);
|
|
130
|
+
cursor = eb.getNextWordBoundary();
|
|
131
|
+
try std.testing.expectEqual(@as(u32, 10), cursor.col);
|
|
132
|
+
|
|
133
|
+
try eb.setCursor(cursor.row, cursor.col);
|
|
134
|
+
cursor = eb.getNextWordBoundary();
|
|
135
|
+
try std.testing.expectEqual(@as(u32, 16), cursor.col);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
test "EditBuffer - word boundary at end of line" {
|
|
139
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
140
|
+
defer gp.deinitGlobalPool();
|
|
141
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
142
|
+
defer link.deinitGlobalLinkPool();
|
|
143
|
+
|
|
144
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
145
|
+
defer eb.deinit();
|
|
146
|
+
|
|
147
|
+
try eb.insertText("Hello");
|
|
148
|
+
try eb.setCursor(0, 5);
|
|
149
|
+
|
|
150
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
151
|
+
try std.testing.expectEqual(@as(u32, 0), next_cursor.row);
|
|
152
|
+
try std.testing.expectEqual(@as(u32, 5), next_cursor.col);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
test "EditBuffer - word boundary at start of line" {
|
|
156
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
157
|
+
defer gp.deinitGlobalPool();
|
|
158
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
159
|
+
defer link.deinitGlobalLinkPool();
|
|
160
|
+
|
|
161
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
162
|
+
defer eb.deinit();
|
|
163
|
+
|
|
164
|
+
try eb.insertText("Hello");
|
|
165
|
+
try eb.setCursor(0, 0);
|
|
166
|
+
|
|
167
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
168
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor.row);
|
|
169
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor.col);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
test "EditBuffer - getEOL basic" {
|
|
173
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
174
|
+
defer gp.deinitGlobalPool();
|
|
175
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
176
|
+
defer link.deinitGlobalLinkPool();
|
|
177
|
+
|
|
178
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
179
|
+
defer eb.deinit();
|
|
180
|
+
|
|
181
|
+
try eb.insertText("Hello World");
|
|
182
|
+
try eb.setCursor(0, 0);
|
|
183
|
+
|
|
184
|
+
const eol_cursor = eb.getEOL();
|
|
185
|
+
try std.testing.expectEqual(@as(u32, 0), eol_cursor.row);
|
|
186
|
+
try std.testing.expectEqual(@as(u32, 11), eol_cursor.col);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
test "EditBuffer - getEOL at end of line" {
|
|
190
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
191
|
+
defer gp.deinitGlobalPool();
|
|
192
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
193
|
+
defer link.deinitGlobalLinkPool();
|
|
194
|
+
|
|
195
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
196
|
+
defer eb.deinit();
|
|
197
|
+
|
|
198
|
+
try eb.insertText("Hello");
|
|
199
|
+
try eb.setCursor(0, 5);
|
|
200
|
+
|
|
201
|
+
const eol_cursor = eb.getEOL();
|
|
202
|
+
try std.testing.expectEqual(@as(u32, 0), eol_cursor.row);
|
|
203
|
+
try std.testing.expectEqual(@as(u32, 5), eol_cursor.col);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
test "EditBuffer - getEOL multi-line" {
|
|
207
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
208
|
+
defer gp.deinitGlobalPool();
|
|
209
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
210
|
+
defer link.deinitGlobalLinkPool();
|
|
211
|
+
|
|
212
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
213
|
+
defer eb.deinit();
|
|
214
|
+
|
|
215
|
+
try eb.insertText("Hello\nWorld\nTest");
|
|
216
|
+
try eb.setCursor(1, 0);
|
|
217
|
+
|
|
218
|
+
const eol_cursor = eb.getEOL();
|
|
219
|
+
try std.testing.expectEqual(@as(u32, 1), eol_cursor.row);
|
|
220
|
+
try std.testing.expectEqual(@as(u32, 5), eol_cursor.col);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
test "EditBuffer - getEOL empty line" {
|
|
224
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
225
|
+
defer gp.deinitGlobalPool();
|
|
226
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
227
|
+
defer link.deinitGlobalLinkPool();
|
|
228
|
+
|
|
229
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
230
|
+
defer eb.deinit();
|
|
231
|
+
|
|
232
|
+
try eb.insertText("Hello\n\nWorld");
|
|
233
|
+
try eb.setCursor(1, 0);
|
|
234
|
+
|
|
235
|
+
const eol_cursor = eb.getEOL();
|
|
236
|
+
try std.testing.expectEqual(@as(u32, 1), eol_cursor.row);
|
|
237
|
+
try std.testing.expectEqual(@as(u32, 0), eol_cursor.col);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
test "EditBuffer - word boundary with tabs" {
|
|
241
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
242
|
+
defer gp.deinitGlobalPool();
|
|
243
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
244
|
+
defer link.deinitGlobalLinkPool();
|
|
245
|
+
|
|
246
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
247
|
+
defer eb.deinit();
|
|
248
|
+
|
|
249
|
+
try eb.insertText("Hello\tWorld");
|
|
250
|
+
|
|
251
|
+
try eb.setCursor(0, 12);
|
|
252
|
+
|
|
253
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
254
|
+
try std.testing.expectEqual(@as(u32, 7), prev_cursor.col);
|
|
255
|
+
|
|
256
|
+
try eb.setCursor(0, 0);
|
|
257
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
258
|
+
try std.testing.expectEqual(@as(u32, 7), next_cursor.col);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
test "EditBuffer - word boundary with CJK graphemes" {
|
|
262
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
263
|
+
defer gp.deinitGlobalPool();
|
|
264
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
265
|
+
defer link.deinitGlobalLinkPool();
|
|
266
|
+
|
|
267
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
268
|
+
defer eb.deinit();
|
|
269
|
+
|
|
270
|
+
// "你" = 2 cols, " " = 1 col, "好" = 2 cols
|
|
271
|
+
try eb.insertText("你 好");
|
|
272
|
+
try eb.setCursor(0, 0);
|
|
273
|
+
|
|
274
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
275
|
+
try std.testing.expectEqual(@as(u32, 3), next_cursor.col);
|
|
276
|
+
|
|
277
|
+
try eb.setCursor(0, 5);
|
|
278
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
279
|
+
try std.testing.expectEqual(@as(u32, 3), prev_cursor.col);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
test "EditBuffer - word boundary mixed CJK and ASCII transition" {
|
|
283
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
284
|
+
defer gp.deinitGlobalPool();
|
|
285
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
286
|
+
defer link.deinitGlobalLinkPool();
|
|
287
|
+
|
|
288
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
289
|
+
defer eb.deinit();
|
|
290
|
+
|
|
291
|
+
try eb.setText("日本語abc");
|
|
292
|
+
|
|
293
|
+
const eol = eb.getEOL();
|
|
294
|
+
try std.testing.expect(eol.col >= 3);
|
|
295
|
+
|
|
296
|
+
try eb.setCursor(0, 0);
|
|
297
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
298
|
+
try std.testing.expectEqual(eol.col - 3, next_cursor.col);
|
|
299
|
+
|
|
300
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
301
|
+
const next_cursor2 = eb.getNextWordBoundary();
|
|
302
|
+
try std.testing.expectEqual(eol.col, next_cursor2.col);
|
|
303
|
+
|
|
304
|
+
try eb.setCursor(0, eol.col);
|
|
305
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
306
|
+
try std.testing.expectEqual(eol.col - 3, prev_cursor.col);
|
|
307
|
+
|
|
308
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
309
|
+
const prev_cursor2 = eb.getPrevWordBoundary();
|
|
310
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
test "EditBuffer - word boundary keeps Hangul run grouped" {
|
|
314
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
315
|
+
defer gp.deinitGlobalPool();
|
|
316
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
317
|
+
defer link.deinitGlobalLinkPool();
|
|
318
|
+
|
|
319
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
320
|
+
defer eb.deinit();
|
|
321
|
+
|
|
322
|
+
try eb.setText("테스트test");
|
|
323
|
+
|
|
324
|
+
const eol = eb.getEOL();
|
|
325
|
+
try std.testing.expect(eol.col >= 4);
|
|
326
|
+
|
|
327
|
+
try eb.setCursor(0, 0);
|
|
328
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
329
|
+
try std.testing.expectEqual(eol.col - 4, next_cursor.col);
|
|
330
|
+
|
|
331
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
332
|
+
const next_cursor2 = eb.getNextWordBoundary();
|
|
333
|
+
try std.testing.expectEqual(eol.col, next_cursor2.col);
|
|
334
|
+
|
|
335
|
+
try eb.setCursor(0, eol.col);
|
|
336
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
337
|
+
try std.testing.expectEqual(eol.col - 4, prev_cursor.col);
|
|
338
|
+
|
|
339
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
340
|
+
const prev_cursor2 = eb.getPrevWordBoundary();
|
|
341
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
test "EditBuffer - word boundary respects CJK punctuation before ASCII" {
|
|
345
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
346
|
+
defer gp.deinitGlobalPool();
|
|
347
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
348
|
+
defer link.deinitGlobalLinkPool();
|
|
349
|
+
|
|
350
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
351
|
+
defer eb.deinit();
|
|
352
|
+
|
|
353
|
+
try eb.setText("日本語。abc");
|
|
354
|
+
|
|
355
|
+
const eol = eb.getEOL();
|
|
356
|
+
try std.testing.expect(eol.col >= 5);
|
|
357
|
+
|
|
358
|
+
try eb.setCursor(0, 0);
|
|
359
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
360
|
+
try std.testing.expectEqual(eol.col - 3, next_cursor.col);
|
|
361
|
+
|
|
362
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
363
|
+
const next_cursor2 = eb.getNextWordBoundary();
|
|
364
|
+
try std.testing.expectEqual(eol.col, next_cursor2.col);
|
|
365
|
+
|
|
366
|
+
try eb.setCursor(0, eol.col);
|
|
367
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
368
|
+
try std.testing.expectEqual(eol.col - 3, prev_cursor.col);
|
|
369
|
+
|
|
370
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
371
|
+
const prev_cursor2 = eb.getPrevWordBoundary();
|
|
372
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
test "EditBuffer - word boundary with compat ideograph and ASCII" {
|
|
376
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
377
|
+
defer gp.deinitGlobalPool();
|
|
378
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
379
|
+
defer link.deinitGlobalLinkPool();
|
|
380
|
+
|
|
381
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
382
|
+
defer eb.deinit();
|
|
383
|
+
|
|
384
|
+
try eb.setText("丽abc");
|
|
385
|
+
|
|
386
|
+
const eol = eb.getEOL();
|
|
387
|
+
try std.testing.expect(eol.col >= 3);
|
|
388
|
+
|
|
389
|
+
try eb.setCursor(0, 0);
|
|
390
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
391
|
+
try std.testing.expectEqual(eol.col - 3, next_cursor.col);
|
|
392
|
+
|
|
393
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
394
|
+
const next_cursor2 = eb.getNextWordBoundary();
|
|
395
|
+
try std.testing.expectEqual(eol.col, next_cursor2.col);
|
|
396
|
+
|
|
397
|
+
try eb.setCursor(0, eol.col);
|
|
398
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
399
|
+
try std.testing.expectEqual(eol.col - 3, prev_cursor.col);
|
|
400
|
+
|
|
401
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
402
|
+
const prev_cursor2 = eb.getPrevWordBoundary();
|
|
403
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
test "EditBuffer - word boundary single-character script transitions" {
|
|
407
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
408
|
+
defer gp.deinitGlobalPool();
|
|
409
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
410
|
+
defer link.deinitGlobalLinkPool();
|
|
411
|
+
|
|
412
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
413
|
+
defer eb.deinit();
|
|
414
|
+
|
|
415
|
+
try eb.setText("a日");
|
|
416
|
+
|
|
417
|
+
var eol = eb.getEOL();
|
|
418
|
+
try std.testing.expectEqual(@as(u32, 3), eol.col);
|
|
419
|
+
|
|
420
|
+
try eb.setCursor(0, 0);
|
|
421
|
+
var next_cursor = eb.getNextWordBoundary();
|
|
422
|
+
try std.testing.expectEqual(@as(u32, 1), next_cursor.col);
|
|
423
|
+
|
|
424
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
425
|
+
var next_cursor2 = eb.getNextWordBoundary();
|
|
426
|
+
try std.testing.expectEqual(@as(u32, 3), next_cursor2.col);
|
|
427
|
+
|
|
428
|
+
try eb.setCursor(0, eol.col);
|
|
429
|
+
var prev_cursor = eb.getPrevWordBoundary();
|
|
430
|
+
try std.testing.expectEqual(@as(u32, 1), prev_cursor.col);
|
|
431
|
+
|
|
432
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
433
|
+
var prev_cursor2 = eb.getPrevWordBoundary();
|
|
434
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
435
|
+
|
|
436
|
+
try eb.setText("日a");
|
|
437
|
+
|
|
438
|
+
eol = eb.getEOL();
|
|
439
|
+
try std.testing.expectEqual(@as(u32, 3), eol.col);
|
|
440
|
+
|
|
441
|
+
try eb.setCursor(0, 0);
|
|
442
|
+
next_cursor = eb.getNextWordBoundary();
|
|
443
|
+
try std.testing.expectEqual(@as(u32, 2), next_cursor.col);
|
|
444
|
+
|
|
445
|
+
try eb.setCursor(next_cursor.row, next_cursor.col);
|
|
446
|
+
next_cursor2 = eb.getNextWordBoundary();
|
|
447
|
+
try std.testing.expectEqual(@as(u32, 3), next_cursor2.col);
|
|
448
|
+
|
|
449
|
+
try eb.setCursor(0, eol.col);
|
|
450
|
+
prev_cursor = eb.getPrevWordBoundary();
|
|
451
|
+
try std.testing.expectEqual(@as(u32, 2), prev_cursor.col);
|
|
452
|
+
|
|
453
|
+
try eb.setCursor(prev_cursor.row, prev_cursor.col);
|
|
454
|
+
prev_cursor2 = eb.getPrevWordBoundary();
|
|
455
|
+
try std.testing.expectEqual(@as(u32, 0), prev_cursor2.col);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
test "EditBuffer - word boundary with emoji" {
|
|
459
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
460
|
+
defer gp.deinitGlobalPool();
|
|
461
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
462
|
+
defer link.deinitGlobalLinkPool();
|
|
463
|
+
|
|
464
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
465
|
+
defer eb.deinit();
|
|
466
|
+
|
|
467
|
+
// "🌟" = 2 cols, " " = 1 col, "ok" = 2 cols
|
|
468
|
+
try eb.insertText("🌟 ok");
|
|
469
|
+
try eb.setCursor(0, 0);
|
|
470
|
+
|
|
471
|
+
const next_cursor = eb.getNextWordBoundary();
|
|
472
|
+
try std.testing.expectEqual(@as(u32, 3), next_cursor.col);
|
|
473
|
+
|
|
474
|
+
try eb.setCursor(0, 5);
|
|
475
|
+
const prev_cursor = eb.getPrevWordBoundary();
|
|
476
|
+
try std.testing.expectEqual(@as(u32, 3), prev_cursor.col);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
test "EditBuffer - moveRight past tab at start of line" {
|
|
480
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
481
|
+
defer gp.deinitGlobalPool();
|
|
482
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
483
|
+
defer link.deinitGlobalLinkPool();
|
|
484
|
+
|
|
485
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
486
|
+
defer eb.deinit();
|
|
487
|
+
|
|
488
|
+
try eb.insertText("\tHello");
|
|
489
|
+
try eb.setCursor(0, 0);
|
|
490
|
+
|
|
491
|
+
eb.moveRight();
|
|
492
|
+
const cursor = eb.getCursor(0).?;
|
|
493
|
+
try std.testing.expect(cursor.col > 0);
|
|
494
|
+
|
|
495
|
+
eb.moveRight();
|
|
496
|
+
const cursor2 = eb.getCursor(0).?;
|
|
497
|
+
try std.testing.expect(cursor2.col > cursor.col);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
test "EditBuffer - moveRight after typing before tab" {
|
|
501
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
502
|
+
defer gp.deinitGlobalPool();
|
|
503
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
504
|
+
defer link.deinitGlobalLinkPool();
|
|
505
|
+
|
|
506
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
507
|
+
defer eb.deinit();
|
|
508
|
+
|
|
509
|
+
try eb.insertText("\tWorld");
|
|
510
|
+
try eb.setCursor(0, 0);
|
|
511
|
+
try eb.insertText("Hi");
|
|
512
|
+
|
|
513
|
+
const cursor_after_insert = eb.getCursor(0).?;
|
|
514
|
+
try std.testing.expectEqual(@as(u32, 0), cursor_after_insert.row);
|
|
515
|
+
|
|
516
|
+
eb.moveRight();
|
|
517
|
+
const cursor_after_move1 = eb.getCursor(0).?;
|
|
518
|
+
try std.testing.expect(cursor_after_move1.col > cursor_after_insert.col);
|
|
519
|
+
|
|
520
|
+
eb.moveRight();
|
|
521
|
+
const cursor_after_move2 = eb.getCursor(0).?;
|
|
522
|
+
try std.testing.expect(cursor_after_move2.col > cursor_after_move1.col);
|
|
523
|
+
|
|
524
|
+
eb.moveRight();
|
|
525
|
+
const cursor_after_move3 = eb.getCursor(0).?;
|
|
526
|
+
try std.testing.expect(cursor_after_move3.col > cursor_after_move2.col);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
test "EditBuffer - moveRight between two tabs" {
|
|
530
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
531
|
+
defer gp.deinitGlobalPool();
|
|
532
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
533
|
+
defer link.deinitGlobalLinkPool();
|
|
534
|
+
|
|
535
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
536
|
+
defer eb.deinit();
|
|
537
|
+
|
|
538
|
+
try eb.insertText("\t\tHello");
|
|
539
|
+
try eb.setCursor(0, 0);
|
|
540
|
+
|
|
541
|
+
var prev_col: u32 = 0;
|
|
542
|
+
var i: u32 = 0;
|
|
543
|
+
while (i < 10) : (i += 1) {
|
|
544
|
+
eb.moveRight();
|
|
545
|
+
const cursor = eb.getCursor(0).?;
|
|
546
|
+
try std.testing.expect(cursor.col >= prev_col);
|
|
547
|
+
prev_col = cursor.col;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
test "EditBuffer - type and move around single tab" {
|
|
552
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
553
|
+
defer gp.deinitGlobalPool();
|
|
554
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
555
|
+
defer link.deinitGlobalLinkPool();
|
|
556
|
+
|
|
557
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
558
|
+
defer eb.deinit();
|
|
559
|
+
|
|
560
|
+
try eb.insertText("\t");
|
|
561
|
+
try eb.setCursor(0, 0);
|
|
562
|
+
try eb.insertText("a");
|
|
563
|
+
|
|
564
|
+
var buffer: [100]u8 = undefined;
|
|
565
|
+
_ = eb.getText(&buffer);
|
|
566
|
+
|
|
567
|
+
const cursor1 = eb.getCursor(0).?;
|
|
568
|
+
try std.testing.expectEqual(@as(u32, 0), cursor1.row);
|
|
569
|
+
_ = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
570
|
+
|
|
571
|
+
_ = eb.tb.getGraphemeWidthAt(0, cursor1.col);
|
|
572
|
+
|
|
573
|
+
eb.moveRight();
|
|
574
|
+
const cursor2 = eb.getCursor(0).?;
|
|
575
|
+
const line_width2 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
576
|
+
const gw2 = eb.tb.getGraphemeWidthAt(0, cursor2.col);
|
|
577
|
+
try std.testing.expect(cursor2.col > cursor1.col);
|
|
578
|
+
|
|
579
|
+
// After moving right once, we're at the end of the line (col=3, line_width=3)
|
|
580
|
+
// We can't move any further
|
|
581
|
+
try std.testing.expectEqual(line_width2, cursor2.col);
|
|
582
|
+
try std.testing.expectEqual(@as(u32, 0), gw2); // No grapheme to move to
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
test "EditBuffer - insert text between tabs and move right" {
|
|
586
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
587
|
+
defer gp.deinitGlobalPool();
|
|
588
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
589
|
+
defer link.deinitGlobalLinkPool();
|
|
590
|
+
|
|
591
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
592
|
+
defer eb.deinit();
|
|
593
|
+
|
|
594
|
+
try eb.insertText("\t\tx");
|
|
595
|
+
try eb.setCursor(0, 0);
|
|
596
|
+
|
|
597
|
+
eb.moveRight();
|
|
598
|
+
_ = eb.getCursor(0).?;
|
|
599
|
+
|
|
600
|
+
try eb.insertText("A");
|
|
601
|
+
const after_insert = eb.getCursor(0).?;
|
|
602
|
+
|
|
603
|
+
eb.moveRight();
|
|
604
|
+
const after_move1 = eb.getCursor(0).?;
|
|
605
|
+
try std.testing.expect(after_move1.col > after_insert.col);
|
|
606
|
+
|
|
607
|
+
eb.moveRight();
|
|
608
|
+
const after_move2 = eb.getCursor(0).?;
|
|
609
|
+
try std.testing.expect(after_move2.col > after_move1.col);
|
|
610
|
+
|
|
611
|
+
eb.moveRight();
|
|
612
|
+
const after_move3 = eb.getCursor(0).?;
|
|
613
|
+
// Should reach append position (line_width) and stay there
|
|
614
|
+
try std.testing.expectEqual(after_move2.col, after_move3.col);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
test "EditBuffer - insert after tab and move around" {
|
|
618
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
619
|
+
defer gp.deinitGlobalPool();
|
|
620
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
621
|
+
defer link.deinitGlobalLinkPool();
|
|
622
|
+
|
|
623
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
624
|
+
defer eb.deinit();
|
|
625
|
+
|
|
626
|
+
try eb.insertText("\t");
|
|
627
|
+
const tab_width = eb.getCursor(0).?.col;
|
|
628
|
+
|
|
629
|
+
try eb.insertText("x");
|
|
630
|
+
const after_x = eb.getCursor(0).?;
|
|
631
|
+
|
|
632
|
+
eb.moveLeft();
|
|
633
|
+
const before_x = eb.getCursor(0).?;
|
|
634
|
+
try std.testing.expectEqual(tab_width, before_x.col);
|
|
635
|
+
|
|
636
|
+
eb.moveRight();
|
|
637
|
+
const back_at_x = eb.getCursor(0).?;
|
|
638
|
+
try std.testing.expectEqual(after_x.col, back_at_x.col);
|
|
639
|
+
|
|
640
|
+
// Already at append position (after 'x'), can't move further on single line
|
|
641
|
+
eb.moveRight();
|
|
642
|
+
const still_at_x = eb.getCursor(0).?;
|
|
643
|
+
try std.testing.expectEqual(back_at_x.col, still_at_x.col);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
test "EditBuffer - cursor stuck after typing around tab" {
|
|
647
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
648
|
+
defer gp.deinitGlobalPool();
|
|
649
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
650
|
+
defer link.deinitGlobalLinkPool();
|
|
651
|
+
|
|
652
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
653
|
+
defer eb.deinit();
|
|
654
|
+
|
|
655
|
+
try eb.insertText("hello\tworld");
|
|
656
|
+
try eb.setCursor(0, 5);
|
|
657
|
+
|
|
658
|
+
eb.moveRight();
|
|
659
|
+
const pos1 = eb.getCursor(0).?;
|
|
660
|
+
|
|
661
|
+
eb.moveRight();
|
|
662
|
+
const pos2 = eb.getCursor(0).?;
|
|
663
|
+
try std.testing.expect(pos2.col > pos1.col);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
test "EditBuffer - complex tab scenario" {
|
|
667
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
668
|
+
defer gp.deinitGlobalPool();
|
|
669
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
670
|
+
defer link.deinitGlobalLinkPool();
|
|
671
|
+
|
|
672
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
673
|
+
defer eb.deinit();
|
|
674
|
+
|
|
675
|
+
try eb.insertText("\tx\ty");
|
|
676
|
+
try eb.setCursor(0, 0);
|
|
677
|
+
|
|
678
|
+
const line_width = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
679
|
+
|
|
680
|
+
eb.moveRight();
|
|
681
|
+
const p1 = eb.getCursor(0).?;
|
|
682
|
+
|
|
683
|
+
eb.moveRight();
|
|
684
|
+
const p2 = eb.getCursor(0).?;
|
|
685
|
+
try std.testing.expect(p2.col > p1.col);
|
|
686
|
+
|
|
687
|
+
eb.moveRight();
|
|
688
|
+
const p3 = eb.getCursor(0).?;
|
|
689
|
+
try std.testing.expect(p3.col > p2.col);
|
|
690
|
+
|
|
691
|
+
eb.moveRight();
|
|
692
|
+
const p4 = eb.getCursor(0).?;
|
|
693
|
+
try std.testing.expect(p4.col > p3.col);
|
|
694
|
+
try std.testing.expectEqual(line_width, p4.col);
|
|
695
|
+
|
|
696
|
+
// Already at append position, can't move further
|
|
697
|
+
eb.moveRight();
|
|
698
|
+
const p5 = eb.getCursor(0).?;
|
|
699
|
+
try std.testing.expectEqual(p4.col, p5.col);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
test "EditBuffer - cursor stuck at tab in middle of line" {
|
|
703
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
704
|
+
defer gp.deinitGlobalPool();
|
|
705
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
706
|
+
defer link.deinitGlobalLinkPool();
|
|
707
|
+
|
|
708
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
709
|
+
defer eb.deinit();
|
|
710
|
+
|
|
711
|
+
try eb.insertText("a\tb");
|
|
712
|
+
try eb.setCursor(0, 1);
|
|
713
|
+
|
|
714
|
+
var buffer: [100]u8 = undefined;
|
|
715
|
+
_ = eb.getText(&buffer);
|
|
716
|
+
|
|
717
|
+
eb.moveRight();
|
|
718
|
+
const p1 = eb.getCursor(0).?;
|
|
719
|
+
|
|
720
|
+
eb.moveRight();
|
|
721
|
+
const p2 = eb.getCursor(0).?;
|
|
722
|
+
try std.testing.expect(p2.col > p1.col);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
test "EditBuffer - type between tabs then move right" {
|
|
726
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
727
|
+
defer gp.deinitGlobalPool();
|
|
728
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
729
|
+
defer link.deinitGlobalLinkPool();
|
|
730
|
+
|
|
731
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
732
|
+
defer eb.deinit();
|
|
733
|
+
|
|
734
|
+
try eb.insertText("\t\t");
|
|
735
|
+
try eb.setCursor(0, 2);
|
|
736
|
+
try eb.insertText("x");
|
|
737
|
+
|
|
738
|
+
const line_width = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
739
|
+
const after_insert = eb.getCursor(0).?;
|
|
740
|
+
|
|
741
|
+
eb.moveRight();
|
|
742
|
+
const p1 = eb.getCursor(0).?;
|
|
743
|
+
try std.testing.expect(p1.col > after_insert.col);
|
|
744
|
+
try std.testing.expectEqual(line_width, p1.col);
|
|
745
|
+
|
|
746
|
+
// Already at append position, can't move further
|
|
747
|
+
eb.moveRight();
|
|
748
|
+
const p2 = eb.getCursor(0).?;
|
|
749
|
+
try std.testing.expectEqual(p1.col, p2.col);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
test "EditBuffer - tabs only with cursor movement" {
|
|
753
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
754
|
+
defer gp.deinitGlobalPool();
|
|
755
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
756
|
+
defer link.deinitGlobalLinkPool();
|
|
757
|
+
|
|
758
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
759
|
+
defer eb.deinit();
|
|
760
|
+
|
|
761
|
+
try eb.insertText("\t\t\t");
|
|
762
|
+
try eb.setCursor(0, 0);
|
|
763
|
+
|
|
764
|
+
var prev_col: u32 = 0;
|
|
765
|
+
var i: u32 = 0;
|
|
766
|
+
while (i < 5) : (i += 1) {
|
|
767
|
+
_ = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
768
|
+
_ = eb.tb.getGraphemeWidthAt(0, prev_col);
|
|
769
|
+
eb.moveRight();
|
|
770
|
+
const cursor = eb.getCursor(0).?;
|
|
771
|
+
try std.testing.expect(cursor.col >= prev_col);
|
|
772
|
+
prev_col = cursor.col;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// ===== getTextRange Tests =====
|
|
777
|
+
|
|
778
|
+
test "EditBuffer - getTextRange basic ASCII" {
|
|
779
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
780
|
+
defer gp.deinitGlobalPool();
|
|
781
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
782
|
+
defer link.deinitGlobalLinkPool();
|
|
783
|
+
|
|
784
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
785
|
+
defer eb.deinit();
|
|
786
|
+
|
|
787
|
+
try eb.insertText("Hello World");
|
|
788
|
+
|
|
789
|
+
var buffer: [100]u8 = undefined;
|
|
790
|
+
const len = try eb.getTextRange(0, 5, &buffer);
|
|
791
|
+
try std.testing.expectEqualStrings("Hello", buffer[0..len]);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
test "EditBuffer - getTextRange full text" {
|
|
795
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
796
|
+
defer gp.deinitGlobalPool();
|
|
797
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
798
|
+
defer link.deinitGlobalLinkPool();
|
|
799
|
+
|
|
800
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
801
|
+
defer eb.deinit();
|
|
802
|
+
|
|
803
|
+
try eb.insertText("Hello World");
|
|
804
|
+
|
|
805
|
+
var buffer: [100]u8 = undefined;
|
|
806
|
+
const len = try eb.getTextRange(0, 11, &buffer);
|
|
807
|
+
try std.testing.expectEqualStrings("Hello World", buffer[0..len]);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
test "EditBuffer - getTextRange with emojis" {
|
|
811
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
812
|
+
defer gp.deinitGlobalPool();
|
|
813
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
814
|
+
defer link.deinitGlobalLinkPool();
|
|
815
|
+
|
|
816
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
817
|
+
defer eb.deinit();
|
|
818
|
+
|
|
819
|
+
try eb.insertText("Hello 👋 World");
|
|
820
|
+
|
|
821
|
+
var buffer: [100]u8 = undefined;
|
|
822
|
+
// "Hello " = 6 cols, emoji = 2 cols, so emoji is at offset 6-8
|
|
823
|
+
const len = try eb.getTextRange(6, 8, &buffer);
|
|
824
|
+
try std.testing.expectEqualStrings("👋", buffer[0..len]);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
test "EditBuffer - getTextRange emoji with skin tone" {
|
|
828
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
829
|
+
defer gp.deinitGlobalPool();
|
|
830
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
831
|
+
defer link.deinitGlobalLinkPool();
|
|
832
|
+
|
|
833
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
834
|
+
defer eb.deinit();
|
|
835
|
+
|
|
836
|
+
// Waving hand with medium skin tone
|
|
837
|
+
try eb.insertText("Hi 👋🏽 there");
|
|
838
|
+
|
|
839
|
+
var buffer: [100]u8 = undefined;
|
|
840
|
+
// "Hi " = 3 cols, emoji = 2 cols
|
|
841
|
+
const len = try eb.getTextRange(3, 5, &buffer);
|
|
842
|
+
try std.testing.expectEqualStrings("👋🏽", buffer[0..len]);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
test "EditBuffer - getTextRange flag emoji" {
|
|
846
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
847
|
+
defer gp.deinitGlobalPool();
|
|
848
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
849
|
+
defer link.deinitGlobalLinkPool();
|
|
850
|
+
|
|
851
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
852
|
+
defer eb.deinit();
|
|
853
|
+
|
|
854
|
+
// USA flag 🇺🇸 (regional indicator symbols)
|
|
855
|
+
try eb.insertText("Flag: 🇺🇸 here");
|
|
856
|
+
|
|
857
|
+
var buffer: [100]u8 = undefined;
|
|
858
|
+
// "Flag: " = 6 cols, flag = 2 cols
|
|
859
|
+
const len = try eb.getTextRange(6, 8, &buffer);
|
|
860
|
+
try std.testing.expectEqualStrings("🇺🇸", buffer[0..len]);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
test "EditBuffer - getTextRange family emoji" {
|
|
864
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
865
|
+
defer gp.deinitGlobalPool();
|
|
866
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
867
|
+
defer link.deinitGlobalLinkPool();
|
|
868
|
+
|
|
869
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
870
|
+
defer eb.deinit();
|
|
871
|
+
|
|
872
|
+
// Family emoji (ZWJ sequence): 👨👩👧👦
|
|
873
|
+
try eb.insertText("Family: 👨👩👧👦 end");
|
|
874
|
+
|
|
875
|
+
var buffer: [100]u8 = undefined;
|
|
876
|
+
// "Family: " = 8 cols, family emoji should be 2 cols
|
|
877
|
+
const len = try eb.getTextRange(8, 10, &buffer);
|
|
878
|
+
try std.testing.expectEqualStrings("👨👩👧👦", buffer[0..len]);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
test "EditBuffer - getTextRange Devanagari with combining marks" {
|
|
882
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
883
|
+
defer gp.deinitGlobalPool();
|
|
884
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
885
|
+
defer link.deinitGlobalLinkPool();
|
|
886
|
+
|
|
887
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
888
|
+
defer eb.deinit();
|
|
889
|
+
|
|
890
|
+
// "नमस्ते" (Namaste in Devanagari) - 5 display columns with zero-width combining marks
|
|
891
|
+
try eb.insertText("Say नमस्ते ok");
|
|
892
|
+
|
|
893
|
+
var buffer: [100]u8 = undefined;
|
|
894
|
+
// "Say " = 4 cols (0-3), "नमस्ते" = 5 cols (4-8), " " = col 9
|
|
895
|
+
const len = try eb.getTextRange(4, 8, &buffer);
|
|
896
|
+
try std.testing.expectEqualStrings("नमस्ते", buffer[0..len]);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
test "EditBuffer - getTextRange CJK characters" {
|
|
900
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
901
|
+
defer gp.deinitGlobalPool();
|
|
902
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
903
|
+
defer link.deinitGlobalLinkPool();
|
|
904
|
+
|
|
905
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
906
|
+
defer eb.deinit();
|
|
907
|
+
|
|
908
|
+
// "你好" (Hello in Chinese) - each character is 2 cols wide
|
|
909
|
+
try eb.insertText("Say 你好 end");
|
|
910
|
+
|
|
911
|
+
var buffer: [100]u8 = undefined;
|
|
912
|
+
// "Say " = 4 cols, 你 = 2 cols, 好 = 2 cols
|
|
913
|
+
const len = try eb.getTextRange(4, 8, &buffer);
|
|
914
|
+
try std.testing.expectEqualStrings("你好", buffer[0..len]);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
test "EditBuffer - getTextRange single CJK character" {
|
|
918
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
919
|
+
defer gp.deinitGlobalPool();
|
|
920
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
921
|
+
defer link.deinitGlobalLinkPool();
|
|
922
|
+
|
|
923
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
924
|
+
defer eb.deinit();
|
|
925
|
+
|
|
926
|
+
try eb.insertText("A 日 B");
|
|
927
|
+
|
|
928
|
+
var buffer: [100]u8 = undefined;
|
|
929
|
+
// "A " = 2 cols, 日 = 2 cols at offset 2-4
|
|
930
|
+
const len = try eb.getTextRange(2, 4, &buffer);
|
|
931
|
+
try std.testing.expectEqualStrings("日", buffer[0..len]);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
test "EditBuffer - getTextRange across lines" {
|
|
935
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
936
|
+
defer gp.deinitGlobalPool();
|
|
937
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
938
|
+
defer link.deinitGlobalLinkPool();
|
|
939
|
+
|
|
940
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
941
|
+
defer eb.deinit();
|
|
942
|
+
|
|
943
|
+
try eb.insertText("Hello\nWorld");
|
|
944
|
+
|
|
945
|
+
var buffer: [100]u8 = undefined;
|
|
946
|
+
// "Hello" = 5 cols, newline = 1 weight, "Wo" = 2 cols
|
|
947
|
+
const len = try eb.getTextRange(3, 8, &buffer);
|
|
948
|
+
try std.testing.expectEqualStrings("lo\nWo", buffer[0..len]);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
test "EditBuffer - getTextRange with tabs" {
|
|
952
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
953
|
+
defer gp.deinitGlobalPool();
|
|
954
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
955
|
+
defer link.deinitGlobalLinkPool();
|
|
956
|
+
|
|
957
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
958
|
+
defer eb.deinit();
|
|
959
|
+
|
|
960
|
+
try eb.insertText("A\tB");
|
|
961
|
+
|
|
962
|
+
var buffer: [100]u8 = undefined;
|
|
963
|
+
// Should include the tab character
|
|
964
|
+
const len = try eb.getTextRange(0, 10, &buffer);
|
|
965
|
+
try std.testing.expectEqualStrings("A\tB", buffer[0..len]);
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
test "EditBuffer - getTextRange partial grapheme snap to start" {
|
|
969
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
970
|
+
defer gp.deinitGlobalPool();
|
|
971
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
972
|
+
defer link.deinitGlobalLinkPool();
|
|
973
|
+
|
|
974
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
975
|
+
defer eb.deinit();
|
|
976
|
+
|
|
977
|
+
// CJK character is 2 cols wide
|
|
978
|
+
try eb.insertText("A 好 B");
|
|
979
|
+
|
|
980
|
+
var buffer: [100]u8 = undefined;
|
|
981
|
+
// Try to get range starting at middle of 好 (offset 3), should snap to start (offset 2)
|
|
982
|
+
const len = try eb.getTextRange(3, 5, &buffer);
|
|
983
|
+
try std.testing.expectEqualStrings("好 ", buffer[0..len]);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
test "EditBuffer - getTextRange partial grapheme snap to end" {
|
|
987
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
988
|
+
defer gp.deinitGlobalPool();
|
|
989
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
990
|
+
defer link.deinitGlobalLinkPool();
|
|
991
|
+
|
|
992
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
993
|
+
defer eb.deinit();
|
|
994
|
+
|
|
995
|
+
// CJK character is 2 cols wide
|
|
996
|
+
try eb.insertText("A 好 B");
|
|
997
|
+
|
|
998
|
+
var buffer: [100]u8 = undefined;
|
|
999
|
+
// Try to get range ending at middle of 好 (offset 3), should snap to end (offset 4)
|
|
1000
|
+
const len = try eb.getTextRange(0, 3, &buffer);
|
|
1001
|
+
try std.testing.expectEqualStrings("A 好", buffer[0..len]);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
test "EditBuffer - getTextRange empty range" {
|
|
1005
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1006
|
+
defer gp.deinitGlobalPool();
|
|
1007
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1008
|
+
defer link.deinitGlobalLinkPool();
|
|
1009
|
+
|
|
1010
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1011
|
+
defer eb.deinit();
|
|
1012
|
+
|
|
1013
|
+
try eb.insertText("Hello");
|
|
1014
|
+
|
|
1015
|
+
var buffer: [100]u8 = undefined;
|
|
1016
|
+
const len = try eb.getTextRange(5, 5, &buffer);
|
|
1017
|
+
try std.testing.expectEqual(@as(usize, 0), len);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
test "EditBuffer - getTextRange out of bounds" {
|
|
1021
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1022
|
+
defer gp.deinitGlobalPool();
|
|
1023
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1024
|
+
defer link.deinitGlobalLinkPool();
|
|
1025
|
+
|
|
1026
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1027
|
+
defer eb.deinit();
|
|
1028
|
+
|
|
1029
|
+
try eb.insertText("Hello");
|
|
1030
|
+
|
|
1031
|
+
var buffer: [100]u8 = undefined;
|
|
1032
|
+
const len = try eb.getTextRange(0, 1000, &buffer);
|
|
1033
|
+
try std.testing.expectEqualStrings("Hello", buffer[0..len]);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
test "EditBuffer - getTextRange mixed scripts" {
|
|
1037
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1038
|
+
defer gp.deinitGlobalPool();
|
|
1039
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1040
|
+
defer link.deinitGlobalLinkPool();
|
|
1041
|
+
|
|
1042
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1043
|
+
defer eb.deinit();
|
|
1044
|
+
|
|
1045
|
+
// Mix of ASCII, emoji, CJK, Devanagari
|
|
1046
|
+
try eb.insertText("Hi 👋 世界 नमस्ते");
|
|
1047
|
+
|
|
1048
|
+
var buffer: [100]u8 = undefined;
|
|
1049
|
+
// Get everything
|
|
1050
|
+
const total_len = try eb.getTextRange(0, 100, &buffer);
|
|
1051
|
+
try std.testing.expectEqualStrings("Hi 👋 世界 नमस्ते", buffer[0..total_len]);
|
|
1052
|
+
|
|
1053
|
+
// Get just the emoji
|
|
1054
|
+
const emoji_len = try eb.getTextRange(3, 5, &buffer);
|
|
1055
|
+
try std.testing.expectEqualStrings("👋", buffer[0..emoji_len]);
|
|
1056
|
+
|
|
1057
|
+
// Get the CJK part: "Hi " = 3, "👋 " = 3, "世界" = 4 (cols 6-10)
|
|
1058
|
+
const cjk_len = try eb.getTextRange(6, 10, &buffer);
|
|
1059
|
+
try std.testing.expectEqualStrings("世界", buffer[0..cjk_len]);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
test "EditBuffer - getTextRange before cursor" {
|
|
1063
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1064
|
+
defer gp.deinitGlobalPool();
|
|
1065
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1066
|
+
defer link.deinitGlobalLinkPool();
|
|
1067
|
+
|
|
1068
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1069
|
+
defer eb.deinit();
|
|
1070
|
+
|
|
1071
|
+
try eb.insertText("Hello World");
|
|
1072
|
+
try eb.setCursor(0, 5);
|
|
1073
|
+
|
|
1074
|
+
const cursor = eb.getCursor(0).?;
|
|
1075
|
+
var buffer: [100]u8 = undefined;
|
|
1076
|
+
|
|
1077
|
+
// Get text before cursor
|
|
1078
|
+
const len = try eb.getTextRange(0, cursor.offset, &buffer);
|
|
1079
|
+
try std.testing.expectEqualStrings("Hello", buffer[0..len]);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
test "EditBuffer - getTextRange char before cursor" {
|
|
1083
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1084
|
+
defer gp.deinitGlobalPool();
|
|
1085
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1086
|
+
defer link.deinitGlobalLinkPool();
|
|
1087
|
+
|
|
1088
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1089
|
+
defer eb.deinit();
|
|
1090
|
+
|
|
1091
|
+
try eb.insertText("Hello World");
|
|
1092
|
+
try eb.setCursor(0, 5);
|
|
1093
|
+
|
|
1094
|
+
const cursor = eb.getCursor(0).?;
|
|
1095
|
+
var buffer: [100]u8 = undefined;
|
|
1096
|
+
|
|
1097
|
+
// Get last char before cursor (if cursor > 0)
|
|
1098
|
+
if (cursor.offset > 0) {
|
|
1099
|
+
const prev_width = eb.tb.getPrevGraphemeWidth(cursor.row, cursor.col);
|
|
1100
|
+
const len = try eb.getTextRange(cursor.offset - prev_width, cursor.offset, &buffer);
|
|
1101
|
+
try std.testing.expectEqualStrings("o", buffer[0..len]);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
test "EditBuffer - getTextRange emoji before cursor" {
|
|
1106
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1107
|
+
defer gp.deinitGlobalPool();
|
|
1108
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1109
|
+
defer link.deinitGlobalLinkPool();
|
|
1110
|
+
|
|
1111
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1112
|
+
defer eb.deinit();
|
|
1113
|
+
|
|
1114
|
+
try eb.insertText("Hi 👋");
|
|
1115
|
+
try eb.setCursor(0, 5); // After emoji
|
|
1116
|
+
|
|
1117
|
+
const cursor = eb.getCursor(0).?;
|
|
1118
|
+
var buffer: [100]u8 = undefined;
|
|
1119
|
+
|
|
1120
|
+
// Get emoji before cursor
|
|
1121
|
+
const prev_width = eb.tb.getPrevGraphemeWidth(cursor.row, cursor.col);
|
|
1122
|
+
const len = try eb.getTextRange(cursor.offset - prev_width, cursor.offset, &buffer);
|
|
1123
|
+
try std.testing.expectEqualStrings("👋", buffer[0..len]);
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
test "EditBuffer - getTextRange multiline with emojis" {
|
|
1127
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1128
|
+
defer gp.deinitGlobalPool();
|
|
1129
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1130
|
+
defer link.deinitGlobalLinkPool();
|
|
1131
|
+
|
|
1132
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1133
|
+
defer eb.deinit();
|
|
1134
|
+
|
|
1135
|
+
try eb.insertText("Line1 👋\nLine2 🎉\nLine3");
|
|
1136
|
+
|
|
1137
|
+
var buffer: [100]u8 = undefined;
|
|
1138
|
+
// Get across all lines
|
|
1139
|
+
const len = try eb.getTextRange(0, 100, &buffer);
|
|
1140
|
+
try std.testing.expectEqualStrings("Line1 👋\nLine2 🎉\nLine3", buffer[0..len]);
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
test "EditBuffer - wcwidth mode treats multi-codepoint emoji as separate chars" {
|
|
1144
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1145
|
+
defer gp.deinitGlobalPool();
|
|
1146
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1147
|
+
defer link.deinitGlobalLinkPool();
|
|
1148
|
+
|
|
1149
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1150
|
+
defer eb.deinit();
|
|
1151
|
+
|
|
1152
|
+
// Hand emoji with skin tone: U+1F44B (waving hand) + U+1F3FB (light skin tone)
|
|
1153
|
+
// In wcwidth mode, these should be treated as 2 separate chars with width 2 each = 4 total
|
|
1154
|
+
// In unicode/no_zwj mode, they would be 1 grapheme with width 2
|
|
1155
|
+
const hand_with_skin_tone = "👋🏻"; // U+1F44B U+1F3FB
|
|
1156
|
+
|
|
1157
|
+
// Family emoji: U+1F468 (man) + U+200D (ZWJ) + U+1F469 (woman) + U+200D + U+1F467 (girl)
|
|
1158
|
+
// In wcwidth mode: each visible codepoint should count separately
|
|
1159
|
+
const family = "👨👩👧"; // man + ZWJ + woman + ZWJ + girl
|
|
1160
|
+
|
|
1161
|
+
// Girl with laptop: U+1F469 (woman) + U+200D (ZWJ) + U+1F4BB (laptop)
|
|
1162
|
+
const girl_laptop = "👩💻"; // woman + ZWJ + laptop
|
|
1163
|
+
|
|
1164
|
+
try eb.setText(hand_with_skin_tone);
|
|
1165
|
+
try eb.setCursor(0, 0);
|
|
1166
|
+
|
|
1167
|
+
// In wcwidth mode:
|
|
1168
|
+
// - U+1F44B (👋) has width 2
|
|
1169
|
+
// - U+1F3FB (🏻 skin tone) has width 2
|
|
1170
|
+
// Total width should be 4 (not 2 as in grapheme mode)
|
|
1171
|
+
const line_width_hand = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1172
|
+
|
|
1173
|
+
// Move right should go: col 0 -> col 2 (after first codepoint) -> col 4 (after second codepoint)
|
|
1174
|
+
eb.moveRight();
|
|
1175
|
+
var cursor = eb.getPrimaryCursor();
|
|
1176
|
+
|
|
1177
|
+
eb.moveRight();
|
|
1178
|
+
cursor = eb.getPrimaryCursor();
|
|
1179
|
+
|
|
1180
|
+
// Expected behavior for wcwidth mode: treating each codepoint as separate
|
|
1181
|
+
try std.testing.expectEqual(@as(u32, 4), line_width_hand);
|
|
1182
|
+
try eb.setCursor(0, 0);
|
|
1183
|
+
eb.moveRight();
|
|
1184
|
+
cursor = eb.getPrimaryCursor();
|
|
1185
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col); // After first codepoint (width 2)
|
|
1186
|
+
eb.moveRight();
|
|
1187
|
+
cursor = eb.getPrimaryCursor();
|
|
1188
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col); // After second codepoint (width 2)
|
|
1189
|
+
|
|
1190
|
+
try eb.setText(family);
|
|
1191
|
+
const line_width_family = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1192
|
+
|
|
1193
|
+
// Family: man (width 2) + ZWJ (width 0) + woman (width 2) + ZWJ (width 0) + girl (width 2)
|
|
1194
|
+
// In wcwidth mode, total should be 6
|
|
1195
|
+
try std.testing.expectEqual(@as(u32, 6), line_width_family);
|
|
1196
|
+
|
|
1197
|
+
try eb.setCursor(0, 0);
|
|
1198
|
+
eb.moveRight(); // Should move to col 2 (after man)
|
|
1199
|
+
cursor = eb.getPrimaryCursor();
|
|
1200
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1201
|
+
|
|
1202
|
+
eb.moveRight(); // Should move to col 4 (after woman)
|
|
1203
|
+
cursor = eb.getPrimaryCursor();
|
|
1204
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1205
|
+
|
|
1206
|
+
eb.moveRight(); // Should move to col 6 (after girl)
|
|
1207
|
+
cursor = eb.getPrimaryCursor();
|
|
1208
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1209
|
+
|
|
1210
|
+
try eb.setText(girl_laptop);
|
|
1211
|
+
const line_width_laptop = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1212
|
+
|
|
1213
|
+
// Woman (width 2) + ZWJ (width 0) + laptop (width 2) = 4 in wcwidth mode
|
|
1214
|
+
try std.testing.expectEqual(@as(u32, 4), line_width_laptop);
|
|
1215
|
+
|
|
1216
|
+
try eb.setCursor(0, 0);
|
|
1217
|
+
eb.moveRight(); // Should move to col 2 (after woman)
|
|
1218
|
+
cursor = eb.getPrimaryCursor();
|
|
1219
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1220
|
+
|
|
1221
|
+
eb.moveRight(); // Should move to col 4 (after laptop)
|
|
1222
|
+
cursor = eb.getPrimaryCursor();
|
|
1223
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
test "EditBuffer - wcwidth comprehensive emoji cursor movement and backspace" {
|
|
1227
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1228
|
+
defer gp.deinitGlobalPool();
|
|
1229
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1230
|
+
defer link.deinitGlobalLinkPool();
|
|
1231
|
+
|
|
1232
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1233
|
+
defer eb.deinit();
|
|
1234
|
+
|
|
1235
|
+
// Test string with various emoji types
|
|
1236
|
+
// "👩🏽💻 👨👩👧👦 🏳️🌈 🇺🇸 🇩🇪 🇯🇵 🇮🇳"
|
|
1237
|
+
const woman_tech = "👩🏽💻"; // Woman + skin tone + ZWJ + laptop = 2+2+0+2 = 6
|
|
1238
|
+
const family = "👨👩👧👦"; // Man + ZWJ + Woman + ZWJ + Girl + ZWJ + Boy = 2+0+2+0+2+0+2 = 8
|
|
1239
|
+
const rainbow_flag = "🏳️🌈"; // Flag + VS16 + ZWJ + Rainbow = 1+0+0+2 = 3 (white flag is width 1 in wcwidth)
|
|
1240
|
+
const us_flag = "🇺🇸"; // Regional indicators = 1+1 = 2
|
|
1241
|
+
_ = "🇩🇪"; // German flag (unused but documented)
|
|
1242
|
+
_ = "🇯🇵"; // Japanese flag (unused but documented)
|
|
1243
|
+
_ = "🇮🇳"; // Indian flag (unused but documented)
|
|
1244
|
+
|
|
1245
|
+
try eb.setText(woman_tech);
|
|
1246
|
+
const width1 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1247
|
+
try std.testing.expectEqual(@as(u32, 6), width1);
|
|
1248
|
+
|
|
1249
|
+
// Test moving right through all codepoints
|
|
1250
|
+
try eb.setCursor(0, 0);
|
|
1251
|
+
eb.moveRight(); // Past woman (width 2)
|
|
1252
|
+
var cursor = eb.getPrimaryCursor();
|
|
1253
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1254
|
+
|
|
1255
|
+
eb.moveRight(); // Past skin tone (width 2)
|
|
1256
|
+
cursor = eb.getPrimaryCursor();
|
|
1257
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1258
|
+
|
|
1259
|
+
eb.moveRight(); // Past ZWJ - since ZWJ has width 0, we skip it and move to laptop
|
|
1260
|
+
cursor = eb.getPrimaryCursor();
|
|
1261
|
+
// ZWJ is zero-width and should be skipped - cursor jumps directly to laptop
|
|
1262
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1263
|
+
|
|
1264
|
+
// Test moving back left
|
|
1265
|
+
eb.moveLeft(); // Back before laptop, skip ZWJ, land at skin tone
|
|
1266
|
+
cursor = eb.getPrimaryCursor();
|
|
1267
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col); // Skipped ZWJ, at skin tone
|
|
1268
|
+
|
|
1269
|
+
eb.moveLeft(); // Back before skin tone
|
|
1270
|
+
cursor = eb.getPrimaryCursor();
|
|
1271
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1272
|
+
|
|
1273
|
+
eb.moveLeft(); // Back to start
|
|
1274
|
+
cursor = eb.getPrimaryCursor();
|
|
1275
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.col);
|
|
1276
|
+
|
|
1277
|
+
// Test backspace from end
|
|
1278
|
+
try eb.setCursor(0, 6); // At end
|
|
1279
|
+
|
|
1280
|
+
// Get initial text
|
|
1281
|
+
var buf: [100]u8 = undefined;
|
|
1282
|
+
var len = eb.getText(&buf);
|
|
1283
|
+
try std.testing.expectEqualStrings(woman_tech, buf[0..len]);
|
|
1284
|
+
|
|
1285
|
+
// Backspace from col 6 should delete laptop and move to col 4
|
|
1286
|
+
try eb.backspace();
|
|
1287
|
+
cursor = eb.getPrimaryCursor();
|
|
1288
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1289
|
+
|
|
1290
|
+
len = eb.getText(&buf);
|
|
1291
|
+
|
|
1292
|
+
// Backspace from col 4: getPrevGraphemeWidth skips ZWJ and returns skin tone width (2)
|
|
1293
|
+
// So we delete from col 2 to col 4, which removes both ZWJ and skin tone
|
|
1294
|
+
// Cursor moves to col 2
|
|
1295
|
+
try eb.backspace();
|
|
1296
|
+
cursor = eb.getPrimaryCursor();
|
|
1297
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1298
|
+
|
|
1299
|
+
len = eb.getText(&buf);
|
|
1300
|
+
|
|
1301
|
+
// Backspace from col 2 should delete woman and move to col 0
|
|
1302
|
+
try eb.backspace();
|
|
1303
|
+
cursor = eb.getPrimaryCursor();
|
|
1304
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.col);
|
|
1305
|
+
|
|
1306
|
+
len = eb.getText(&buf);
|
|
1307
|
+
try std.testing.expectEqual(@as(usize, 0), len);
|
|
1308
|
+
|
|
1309
|
+
try eb.setText(family);
|
|
1310
|
+
const width2 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1311
|
+
try std.testing.expectEqual(@as(u32, 8), width2);
|
|
1312
|
+
|
|
1313
|
+
// Move through all visible codepoints (ZWJs are automatically skipped)
|
|
1314
|
+
try eb.setCursor(0, 0);
|
|
1315
|
+
eb.moveRight(); // Man (skips following ZWJ)
|
|
1316
|
+
cursor = eb.getPrimaryCursor();
|
|
1317
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1318
|
+
|
|
1319
|
+
eb.moveRight(); // Woman (skips preceding and following ZWJ)
|
|
1320
|
+
cursor = eb.getPrimaryCursor();
|
|
1321
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1322
|
+
|
|
1323
|
+
eb.moveRight(); // Girl (skips preceding and following ZWJ)
|
|
1324
|
+
cursor = eb.getPrimaryCursor();
|
|
1325
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1326
|
+
|
|
1327
|
+
eb.moveRight(); // Boy (skips preceding ZWJ)
|
|
1328
|
+
cursor = eb.getPrimaryCursor();
|
|
1329
|
+
try std.testing.expectEqual(@as(u32, 8), cursor.col);
|
|
1330
|
+
|
|
1331
|
+
// Move back (ZWJs are skipped)
|
|
1332
|
+
eb.moveLeft(); // Back to Girl
|
|
1333
|
+
cursor = eb.getPrimaryCursor();
|
|
1334
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1335
|
+
|
|
1336
|
+
eb.moveLeft(); // Back to Woman
|
|
1337
|
+
cursor = eb.getPrimaryCursor();
|
|
1338
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1339
|
+
|
|
1340
|
+
eb.moveLeft(); // Back to Man
|
|
1341
|
+
cursor = eb.getPrimaryCursor();
|
|
1342
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1343
|
+
|
|
1344
|
+
try eb.setText(rainbow_flag);
|
|
1345
|
+
const width3 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1346
|
+
try std.testing.expectEqual(@as(u32, 3), width3);
|
|
1347
|
+
|
|
1348
|
+
try eb.setCursor(0, 0);
|
|
1349
|
+
eb.moveRight(); // White flag (width 1, skips VS16 and ZWJ)
|
|
1350
|
+
cursor = eb.getPrimaryCursor();
|
|
1351
|
+
try std.testing.expectEqual(@as(u32, 1), cursor.col);
|
|
1352
|
+
|
|
1353
|
+
eb.moveRight(); // Rainbow (width 2, VS16 and ZWJ were skipped)
|
|
1354
|
+
cursor = eb.getPrimaryCursor();
|
|
1355
|
+
try std.testing.expectEqual(@as(u32, 3), cursor.col);
|
|
1356
|
+
|
|
1357
|
+
try eb.setText(us_flag);
|
|
1358
|
+
const width4 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1359
|
+
try std.testing.expectEqual(@as(u32, 2), width4);
|
|
1360
|
+
|
|
1361
|
+
try eb.setCursor(0, 0);
|
|
1362
|
+
eb.moveRight(); // First regional indicator
|
|
1363
|
+
cursor = eb.getPrimaryCursor();
|
|
1364
|
+
try std.testing.expectEqual(@as(u32, 1), cursor.col);
|
|
1365
|
+
|
|
1366
|
+
eb.moveRight(); // Second regional indicator
|
|
1367
|
+
cursor = eb.getPrimaryCursor();
|
|
1368
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1369
|
+
|
|
1370
|
+
// Move back
|
|
1371
|
+
eb.moveLeft();
|
|
1372
|
+
cursor = eb.getPrimaryCursor();
|
|
1373
|
+
try std.testing.expectEqual(@as(u32, 1), cursor.col);
|
|
1374
|
+
|
|
1375
|
+
eb.moveLeft();
|
|
1376
|
+
cursor = eb.getPrimaryCursor();
|
|
1377
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.col);
|
|
1378
|
+
|
|
1379
|
+
const mixed_text = "A 👩🏽💻 B 👨👩👧👦 C";
|
|
1380
|
+
try eb.setText(mixed_text);
|
|
1381
|
+
const mixed_width = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1382
|
+
// A(1) + space(1) + woman_tech(6) + space(1) + B(1) + space(1) + family(8) + space(1) + C(1) = 21
|
|
1383
|
+
try std.testing.expectEqual(@as(u32, 21), mixed_width);
|
|
1384
|
+
|
|
1385
|
+
// Navigate through the mixed text
|
|
1386
|
+
try eb.setCursor(0, 0);
|
|
1387
|
+
|
|
1388
|
+
// Move to 'A'
|
|
1389
|
+
eb.moveRight();
|
|
1390
|
+
cursor = eb.getPrimaryCursor();
|
|
1391
|
+
try std.testing.expectEqual(@as(u32, 1), cursor.col);
|
|
1392
|
+
|
|
1393
|
+
// Move past space
|
|
1394
|
+
eb.moveRight();
|
|
1395
|
+
cursor = eb.getPrimaryCursor();
|
|
1396
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1397
|
+
|
|
1398
|
+
// Move through woman technologist (ZWJs are skipped)
|
|
1399
|
+
eb.moveRight(); // woman
|
|
1400
|
+
cursor = eb.getPrimaryCursor();
|
|
1401
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1402
|
+
|
|
1403
|
+
eb.moveRight(); // skin tone
|
|
1404
|
+
cursor = eb.getPrimaryCursor();
|
|
1405
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1406
|
+
|
|
1407
|
+
eb.moveRight(); // laptop (ZWJ is skipped)
|
|
1408
|
+
cursor = eb.getPrimaryCursor();
|
|
1409
|
+
try std.testing.expectEqual(@as(u32, 8), cursor.col);
|
|
1410
|
+
|
|
1411
|
+
// Should be at space after woman_tech
|
|
1412
|
+
eb.moveRight();
|
|
1413
|
+
cursor = eb.getPrimaryCursor();
|
|
1414
|
+
try std.testing.expectEqual(@as(u32, 9), cursor.col);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
test "EditBuffer - wcwidth ZWJ does not appear in rendered text" {
|
|
1418
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1419
|
+
defer gp.deinitGlobalPool();
|
|
1420
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1421
|
+
defer link.deinitGlobalLinkPool();
|
|
1422
|
+
|
|
1423
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1424
|
+
defer eb.deinit();
|
|
1425
|
+
|
|
1426
|
+
const woman_tech = "👩🏽💻"; // Contains ZWJ at byte position
|
|
1427
|
+
try eb.setText(woman_tech);
|
|
1428
|
+
|
|
1429
|
+
// Get the raw bytes - ZWJ should be present in the buffer
|
|
1430
|
+
var buf: [100]u8 = undefined;
|
|
1431
|
+
const len = eb.getText(&buf);
|
|
1432
|
+
const text_bytes = buf[0..len];
|
|
1433
|
+
|
|
1434
|
+
// Check that ZWJ (U+200D = 0xE2 0x80 0x8D in UTF-8) is present in bytes
|
|
1435
|
+
var has_zwj = false;
|
|
1436
|
+
var i: usize = 0;
|
|
1437
|
+
while (i + 2 < len) : (i += 1) {
|
|
1438
|
+
if (text_bytes[i] == 0xE2 and text_bytes[i + 1] == 0x80 and text_bytes[i + 2] == 0x8D) {
|
|
1439
|
+
has_zwj = true;
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
try std.testing.expect(has_zwj);
|
|
1444
|
+
|
|
1445
|
+
// Verify that the full text is preserved byte-for-byte
|
|
1446
|
+
try std.testing.expectEqualStrings(woman_tech, text_bytes);
|
|
1447
|
+
|
|
1448
|
+
// But cursor movement should skip over ZWJ
|
|
1449
|
+
try eb.setCursor(0, 0);
|
|
1450
|
+
const line_width = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1451
|
+
try std.testing.expectEqual(@as(u32, 6), line_width); // 2+2+0+2
|
|
1452
|
+
|
|
1453
|
+
// Moving through: cursor positions should be 0, 2, 4, 6
|
|
1454
|
+
// ZWJ is skipped automatically
|
|
1455
|
+
try eb.setCursor(0, 0);
|
|
1456
|
+
eb.moveRight(); // Woman
|
|
1457
|
+
var cursor = eb.getPrimaryCursor();
|
|
1458
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1459
|
+
|
|
1460
|
+
eb.moveRight(); // Skin tone
|
|
1461
|
+
cursor = eb.getPrimaryCursor();
|
|
1462
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1463
|
+
|
|
1464
|
+
eb.moveRight(); // Laptop (ZWJ is skipped)
|
|
1465
|
+
cursor = eb.getPrimaryCursor();
|
|
1466
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
test "EditBuffer - wcwidth each visible emoji requires exactly one cursor move" {
|
|
1470
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1471
|
+
defer gp.deinitGlobalPool();
|
|
1472
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1473
|
+
defer link.deinitGlobalLinkPool();
|
|
1474
|
+
|
|
1475
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1476
|
+
defer eb.deinit();
|
|
1477
|
+
|
|
1478
|
+
// Test 1: Simple laptop emoji (no ZWJ)
|
|
1479
|
+
try eb.setText("💻");
|
|
1480
|
+
const width1 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1481
|
+
try std.testing.expectEqual(@as(u32, 2), width1);
|
|
1482
|
+
|
|
1483
|
+
try eb.setCursor(0, 0);
|
|
1484
|
+
eb.moveRight(); // Should move past laptop in ONE move
|
|
1485
|
+
var cursor = eb.getPrimaryCursor();
|
|
1486
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1487
|
+
|
|
1488
|
+
// Test 2: Woman emoji (no modifiers)
|
|
1489
|
+
try eb.setText("👩");
|
|
1490
|
+
try eb.setCursor(0, 0);
|
|
1491
|
+
eb.moveRight(); // Should move past woman in ONE move
|
|
1492
|
+
cursor = eb.getPrimaryCursor();
|
|
1493
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1494
|
+
|
|
1495
|
+
// Test 3: Skin tone emoji alone
|
|
1496
|
+
try eb.setText("🏽");
|
|
1497
|
+
try eb.setCursor(0, 0);
|
|
1498
|
+
eb.moveRight(); // Should move past skin in ONE move
|
|
1499
|
+
cursor = eb.getPrimaryCursor();
|
|
1500
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1501
|
+
|
|
1502
|
+
// Test 4: Woman + skin (no ZWJ yet)
|
|
1503
|
+
try eb.setText("👩🏽");
|
|
1504
|
+
const width4 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1505
|
+
try std.testing.expectEqual(@as(u32, 4), width4); // 2+2
|
|
1506
|
+
|
|
1507
|
+
try eb.setCursor(0, 0);
|
|
1508
|
+
eb.moveRight(); // Move past woman
|
|
1509
|
+
cursor = eb.getPrimaryCursor();
|
|
1510
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1511
|
+
|
|
1512
|
+
eb.moveRight(); // Move past skin in ONE more move
|
|
1513
|
+
cursor = eb.getPrimaryCursor();
|
|
1514
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1515
|
+
|
|
1516
|
+
// Test 5: Woman + skin + ZWJ + laptop (full technologist)
|
|
1517
|
+
try eb.setText("👩🏽💻");
|
|
1518
|
+
const width5 = iter_mod.lineWidthAt(eb.tb.rope(), 0);
|
|
1519
|
+
try std.testing.expectEqual(@as(u32, 6), width5); // 2+2+0+2
|
|
1520
|
+
|
|
1521
|
+
try eb.setCursor(0, 0);
|
|
1522
|
+
|
|
1523
|
+
// Should take exactly 3 moves to get to the end (woman, skin, laptop)
|
|
1524
|
+
// ZWJ should be completely invisible to cursor
|
|
1525
|
+
eb.moveRight(); // Move 1: woman
|
|
1526
|
+
cursor = eb.getPrimaryCursor();
|
|
1527
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1528
|
+
|
|
1529
|
+
eb.moveRight(); // Move 2: skin
|
|
1530
|
+
cursor = eb.getPrimaryCursor();
|
|
1531
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1532
|
+
|
|
1533
|
+
eb.moveRight(); // Move 3: laptop (ZWJ should be skipped automatically)
|
|
1534
|
+
cursor = eb.getPrimaryCursor();
|
|
1535
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1536
|
+
|
|
1537
|
+
// Moving right again should do nothing (at end)
|
|
1538
|
+
eb.moveRight();
|
|
1539
|
+
cursor = eb.getPrimaryCursor();
|
|
1540
|
+
try std.testing.expectEqual(@as(u32, 6), cursor.col);
|
|
1541
|
+
|
|
1542
|
+
// Test moving backwards
|
|
1543
|
+
eb.moveLeft(); // Should move back to before laptop (skip ZWJ), land at skin
|
|
1544
|
+
cursor = eb.getPrimaryCursor();
|
|
1545
|
+
try std.testing.expectEqual(@as(u32, 4), cursor.col);
|
|
1546
|
+
|
|
1547
|
+
eb.moveLeft(); // Should move back to before skin
|
|
1548
|
+
cursor = eb.getPrimaryCursor();
|
|
1549
|
+
try std.testing.expectEqual(@as(u32, 2), cursor.col);
|
|
1550
|
+
|
|
1551
|
+
eb.moveLeft(); // Should move back to start
|
|
1552
|
+
cursor = eb.getPrimaryCursor();
|
|
1553
|
+
try std.testing.expectEqual(@as(u32, 0), cursor.col);
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
test "EditBuffer - replaceText allows undo" {
|
|
1557
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1558
|
+
defer gp.deinitGlobalPool();
|
|
1559
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1560
|
+
defer link.deinitGlobalLinkPool();
|
|
1561
|
+
|
|
1562
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1563
|
+
defer eb.deinit();
|
|
1564
|
+
|
|
1565
|
+
// Set initial text (resets everything)
|
|
1566
|
+
try eb.setText("Initial");
|
|
1567
|
+
|
|
1568
|
+
var buffer: [100]u8 = undefined;
|
|
1569
|
+
var len = eb.getText(&buffer);
|
|
1570
|
+
try std.testing.expectEqualStrings("Initial", buffer[0..len]);
|
|
1571
|
+
|
|
1572
|
+
// Replace text with history preserved
|
|
1573
|
+
try eb.replaceText("Modified");
|
|
1574
|
+
len = eb.getText(&buffer);
|
|
1575
|
+
try std.testing.expectEqualStrings("Modified", buffer[0..len]);
|
|
1576
|
+
|
|
1577
|
+
// Should be able to undo
|
|
1578
|
+
try std.testing.expect(eb.canUndo());
|
|
1579
|
+
_ = try eb.undo();
|
|
1580
|
+
|
|
1581
|
+
// Should be back to "Initial"
|
|
1582
|
+
len = eb.getText(&buffer);
|
|
1583
|
+
try std.testing.expectEqualStrings("Initial", buffer[0..len]);
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
test "EditBuffer - setText clears all history" {
|
|
1587
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1588
|
+
defer gp.deinitGlobalPool();
|
|
1589
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1590
|
+
defer link.deinitGlobalLinkPool();
|
|
1591
|
+
|
|
1592
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1593
|
+
defer eb.deinit();
|
|
1594
|
+
|
|
1595
|
+
// Insert some text that creates undo history
|
|
1596
|
+
try eb.insertText("Initial");
|
|
1597
|
+
|
|
1598
|
+
// Should have undo history
|
|
1599
|
+
try std.testing.expect(eb.canUndo());
|
|
1600
|
+
|
|
1601
|
+
var buffer: [100]u8 = undefined;
|
|
1602
|
+
var len = eb.getText(&buffer);
|
|
1603
|
+
try std.testing.expectEqualStrings("Initial", buffer[0..len]);
|
|
1604
|
+
|
|
1605
|
+
// setText now completely resets the buffer (clears history)
|
|
1606
|
+
try eb.setText("New");
|
|
1607
|
+
|
|
1608
|
+
len = eb.getText(&buffer);
|
|
1609
|
+
try std.testing.expectEqualStrings("New", buffer[0..len]);
|
|
1610
|
+
|
|
1611
|
+
// History should be cleared
|
|
1612
|
+
try std.testing.expect(!eb.canUndo());
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
test "EditBuffer - multiple replaceText with history keeps add_buffer functional" {
|
|
1616
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1617
|
+
defer gp.deinitGlobalPool();
|
|
1618
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1619
|
+
defer link.deinitGlobalLinkPool();
|
|
1620
|
+
|
|
1621
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1622
|
+
defer eb.deinit();
|
|
1623
|
+
|
|
1624
|
+
// Use replaceText to preserve history
|
|
1625
|
+
try eb.replaceText("Line 1");
|
|
1626
|
+
|
|
1627
|
+
// Insert more text using the add_buffer
|
|
1628
|
+
try eb.insertText("\nLine 2");
|
|
1629
|
+
|
|
1630
|
+
// Replace text again (preserves history)
|
|
1631
|
+
// This sets cursor to (0, 0)
|
|
1632
|
+
try eb.replaceText("Reset");
|
|
1633
|
+
|
|
1634
|
+
// Insert more text using the add_buffer (should still work)
|
|
1635
|
+
// Since cursor is at (0, 0), text is inserted at the beginning
|
|
1636
|
+
try eb.insertText(" and more");
|
|
1637
|
+
|
|
1638
|
+
var buffer: [100]u8 = undefined;
|
|
1639
|
+
const len = eb.getText(&buffer);
|
|
1640
|
+
// Text is inserted at cursor position (0, 0), so it appears before "Reset"
|
|
1641
|
+
try std.testing.expectEqualStrings(" and moreReset", buffer[0..len]);
|
|
1642
|
+
|
|
1643
|
+
// Verify we can undo
|
|
1644
|
+
try std.testing.expect(eb.canUndo());
|
|
1645
|
+
|
|
1646
|
+
// Move cursor to end and insert more text
|
|
1647
|
+
const line_count = eb.tb.lineCount();
|
|
1648
|
+
const last_line_width = iter_mod.lineWidthAt(eb.tb.rope(), line_count - 1);
|
|
1649
|
+
try eb.setCursor(line_count - 1, last_line_width);
|
|
1650
|
+
try eb.insertText(" more");
|
|
1651
|
+
|
|
1652
|
+
const len2 = eb.getText(&buffer);
|
|
1653
|
+
try std.testing.expectEqualStrings(" and moreReset more", buffer[0..len2]);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
test "EditBuffer - setText resets add_buffer" {
|
|
1657
|
+
const pool = gp.initGlobalPool(std.testing.allocator);
|
|
1658
|
+
defer gp.deinitGlobalPool();
|
|
1659
|
+
const link_pool = link.initGlobalLinkPool(std.testing.allocator);
|
|
1660
|
+
defer link.deinitGlobalLinkPool();
|
|
1661
|
+
|
|
1662
|
+
var eb = try EditBuffer.init(std.testing.allocator, pool, link_pool, .wcwidth);
|
|
1663
|
+
defer eb.deinit();
|
|
1664
|
+
|
|
1665
|
+
// Insert text that uses add_buffer
|
|
1666
|
+
try eb.insertText("First");
|
|
1667
|
+
try eb.insertText(" Second");
|
|
1668
|
+
|
|
1669
|
+
var buffer: [100]u8 = undefined;
|
|
1670
|
+
var len = eb.getText(&buffer);
|
|
1671
|
+
try std.testing.expectEqualStrings("First Second", buffer[0..len]);
|
|
1672
|
+
|
|
1673
|
+
// setText should reset add_buffer.len to 0
|
|
1674
|
+
try eb.setText("Reset");
|
|
1675
|
+
|
|
1676
|
+
len = eb.getText(&buffer);
|
|
1677
|
+
try std.testing.expectEqualStrings("Reset", buffer[0..len]);
|
|
1678
|
+
|
|
1679
|
+
// After setText, add_buffer should be reset and work fine
|
|
1680
|
+
// setText places cursor at (0,0), so move to end of text
|
|
1681
|
+
const line_count = eb.tb.lineCount();
|
|
1682
|
+
const last_line_width = iter_mod.lineWidthAt(eb.tb.rope(), line_count - 1);
|
|
1683
|
+
try eb.setCursor(line_count - 1, last_line_width);
|
|
1684
|
+
|
|
1685
|
+
try eb.insertText(" More");
|
|
1686
|
+
|
|
1687
|
+
len = eb.getText(&buffer);
|
|
1688
|
+
try std.testing.expectEqualStrings("Reset More", buffer[0..len]);
|
|
1689
|
+
}
|