unexpected behaviour of object selection #1105

Open
cvlmtg opened this Issue Jan 3, 2017 · 4 comments

Projects

None yet

3 participants

@cvlmtg
cvlmtg commented Jan 3, 2017 edited

let's suppose I have this text file:

print 'aaa'; print 'bbb'; print 'ccc';

(yes, it's weird but makes the examples easier)

If I am in vim and put the cursor on the first single quote of 'bbb', the command vi' correctly selects bbb. in kakoune <a-i>' selects ; print 'bbb. the same weirdness applies to <a-a>'.

anyway, I think kakoune is an interesting program and keep trying it out once in a while :) keep up the good work!

@lenormf
Contributor
lenormf commented Jan 8, 2017

Since simple quotes are not directed like e.g. brackets or braces, it's not possible for the editor to guess what way the selection should go, so you get kind of an undefined behaviour there (the same thing applies to double quotes, back quotes etc).

I think vim parses the language in the buffer to know what part it should select, which is something Kakoune does not do (and probably won't).

@cvlmtg
cvlmtg commented Jan 8, 2017 edited

I think vim does nothing particular with languages. if i start vim with vim -u NONE --noplugin and type in the scratch buffer:

'some ol\' words'

"filetype" isn't set, yet with vi' vim is able to select the whole string from any cursor position, because it "sees" the escaped single quote. If I remove the backslash it selects the first half or the second one depending on the cursors position.

'foo' and 'bar'
    1     2

with this example vim correctly selects the first string with the cursor in position 1 and the second string with cursor in position 2. It looks like it counts the quotes on the line, because If I add a fifth single quote in front of and it selects foo and and.

counting quotes and checking for backslashes doesn't depend on languages (I think the backslash is kinda universal...). No idea how difficult could be to add these rules in kakoune selection code, but I think it would really improve selection behaviour :)

a much simpler improvement could be to check the character the cursor is on instead of ignoring it (like it appears it currently does)

@mawww
Owner
mawww commented Jan 8, 2017

The main reason we do not count delimiter is that it makes to operation non local, it means we have to count the quotes. If we want to be as correct as possible, we end up needing to read from buffer begin, which makes the operation more expensive when we are further away from the buffer begin.

Ignoring the delimiter under the cursor is not nice, I think we should assume, then we have a delimiter under the cursor, that it is the start of an object.

Regarding escaping, I am not sure if we want to handle it or not, on one side its very common to escape with backslashes, on the other, its still language dependent, and it adds complexity.

@cvlmtg
cvlmtg commented Jan 9, 2017

Not sure if vim count quotes just on the current line or not. I have to admit this looks like that kind of problems that grows bigger and bigger the more you look into them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment