diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-10-30 13:57:46 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-10-30 13:57:46 +0000 |
| commit | 2bf44b6b49dc9bf52ee424da6decdd5c8fcae665 (patch) | |
| tree | d1871e3eb04bfd4f154b09a466aadb1a8dfd1fe0 /src/insert_completer.cc | |
| parent | 92c3aa4d31e07c6681c2267cbef6ebc069195ba2 (diff) | |
Make word insert completion work better with unicode char
Diffstat (limited to 'src/insert_completer.cc')
| -rw-r--r-- | src/insert_completer.cc | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc index add9c0f0..1718220d 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -10,6 +10,7 @@ #include "user_interface.hh" #include "window.hh" #include "word_db.hh" +#include "utf8_iterator.hh" #include <numeric> @@ -75,23 +76,24 @@ WordDB& get_word_db(const Buffer& buffer) template<bool other_buffers> InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos) { - auto pos = buffer.iterator_at(cursor_pos); - if (pos == buffer.begin() or not is_word(*utf8::previous(pos, buffer.begin()))) - return {}; + using Utf8It = utf8::iterator<BufferIterator>; + Utf8It pos{buffer.iterator_at(cursor_pos), buffer}; + if (pos == buffer.begin() or not is_word(*(pos-1))) + return {}; - auto end = buffer.iterator_at(cursor_pos); + auto end = Utf8It{buffer.iterator_at(cursor_pos), buffer}; auto begin = end-1; while (begin != buffer.begin() and is_word(*begin)) --begin; if (not is_word(*begin)) ++begin; - String prefix{begin, end}; + String prefix{begin.base(), end.base()}; while (end != buffer.end() and is_word(*end)) ++end; - String current_word{begin, end}; + String current_word{begin.base(), end.base()}; struct RankedMatchAndBuffer : RankedMatch { @@ -153,7 +155,7 @@ InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos) candidates.push_back({m.candidate().str(), "", std::move(menu_entry)}); } - return { begin.coord(), cursor_pos, std::move(candidates), buffer.timestamp() }; + return { begin.base().coord(), cursor_pos, std::move(candidates), buffer.timestamp() }; } template<bool require_slash> |
