natecraddock / zf

a commandline fuzzy finder and zig package designed for filtering filepaths
MIT License
451 stars 14 forks source link

Overlapping highlights are incorrect #22

Closed natecraddock closed 1 year ago

natecraddock commented 1 year ago
❯ fd -t f | zf
> source/b/e outlinerdraw
source/blender/freestyle/intern/scene_graph/DrawingStyle.h

On the second line we would expect the source/b/e and the outlinerdraw highlights to overlap, highlighting source/blender/freestyle/intern/scene_graph/Draw, but only the first token is highlighted.

So filtering works, but range highlighting needs a rework.

The current algorithm is messy and error prone. Because range highlighting occurs for a smaller number of candidates (n < 100 usually), we can do a bit more work.

Ideally, when highlighting the output array of ranges should be sorted and joined. So the ranges are in the correct order, and if needed, any overlaps are joined together.

natecraddock commented 1 year ago

An even better solution would be to remove the concept of range highlighting altogether. Instead, highlight each individual byte/character/grapheme. This will actually simplify the implementation greatly.

This is also how fzf and fzy do highlighting