mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.93k stars 714 forks source link

Cursor moves right using \Q and (?i) with empty search input #2013

Open aver-d opened 6 years ago

aver-d commented 6 years ago

Steps /\Q (eca53db2 latest, kak -n) Outcome Cursor moves right one character Expect No cursor movement. My expectation would be that \Q to begin an escaped sequence is a non-matching zero-width indicator, and so the cursor should not move until a subsequent matching character is entered.

Notes: This seems to occur only in the initial (left-most) position of the search input. If \Q is entered after any other character, then no (additional) cursor movement occurs. \Q and .\Q both have the same effect: move cursor to next character.

I suppose the cursor movement is somewhat distracting, and it also occurs with case-insensitive flag (?i). The movement suggests a match, but in fact only a regex flag has been entered.

So, in a simplified example, we search using the (?i) flag for the regex a and the next character happens to be "a". The cursor moves immediately after typing /(?i), but now typing a does not move the cursor. My expectation would be that cursor moves to the character "a" only after actually typing a in the sequence /(?i)a.

mawww commented 6 years ago

Hello,

The reason for that is that \Q is a regex matching an empty string at the begining of the subject. Contrarily to empty string, which is an invalid regex. When searching, the subject string starts on the character just after the current selection. So once you type \Q, Kakoune finds an empty match just after current selection end, moving the cursor one character to the right. Same thing for (?i). The only way I can think of to prevent that would be to consider \Q and (?i) as invalid regex, which could make sense.

aver-d commented 6 years ago

Ok thanks. Yes, making these invalid would make sense to me if you'd be happy with that.

To my mind, even if \Q and (?i) are theoretically different from empty string, the effect they should have in practice inside Kakoune should be the same as empty string because the user's intended search term hasn't yet been written.

lenormf commented 4 years ago

Could we close this?