helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.61k stars 2.5k forks source link

`mip` sees whitespace filled lines as part of paragraph #11146

Open d3m1gd opened 3 months ago

d3m1gd commented 3 months ago

given text with empty line with spaces between paragraphs and cursor inside foo block, mip will choose both foo and bar blocks, when it should only select foo block.

foo foo foo
foo foo foo
foo foo foo

bar bar bar
bar bar bar
bar bar bar

if the empty line contains no whitespace (or tabs) then the behavior is as expected - only foo block is selected.

probably related to #5182

EpocSquadron commented 3 months ago

I have some insight on this one from working on #1810. Turns out that there is a helper line_ending::rope_is_line_ending that is tempting to use rather than implementing your own "emtpy line" detector logic. The paragraph textobject implementation uses this. I also used this in my PR when I discovered its existence, and then later discovered that it does not handle the case of whitespace-only. I still haven't fixed it in my PR, but while looking at the paragraph textobject implementation I realized that my indent detection logic is really a stone's throw away from the paragraph detection. There's even a question in my mind similar to #5182.

In any case, we could fix this by implementing a new empty line detecting function that delegates to rope_is_line_ending for the special case, then checks for only whitespace characters. It would fix both these issues, and help my PR.