hoaproject / Console

The Hoa\Console library.
https://hoa-project.net/
366 stars 32 forks source link

Autocompleter: Force to work on a sub-line #68

Closed Hywan closed 8 years ago

Hywan commented 8 years ago

Fix #67.

Before this patch, all autocompleters were finding words on a complete line. This were leading to some issues, like the one described in https://github.com/hoaproject/Console/issues/67: If one has the “foo ” line and starts autocompleting with the Word autocompleter, it will find the foo word. Since the autocompletion algorithm chose the word to autocomplete based on the closest offset, in this case it would have tried to autocomplete foo, which is wrong because there is a space after foo (“foo ”).

Now, instead of working with word offsets, the algorithm uses an anchor ($) to find the latest word in the “line”. In fact, the algorithm no longer works on the full line but on a subset of the line (called “sub-line”), which starts from the beginning and ends at the current position of the cursor.

In addition to fix the bug, it saves useless computations and regular expressions matching. Also the algorithm is a little more simple to understand. The notion of prefix has been removed too: The found word is directly the prefix used by autocompleters.

Finally, no modification is needed on existing autocompleters regarding the word definition. In this case, we were able to simplify the word definition of Word but it is not related. There should be no backward compatibility break.

vonglasow commented 8 years ago

:+1: