fix line completion with prefix

There's a bug in current line completion, fix it.

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2021-04-11 11:54:48 +08:00
parent 5696ed02e4
commit 41833d7b7d
3 changed files with 6 additions and 6 deletions

View File

@ -348,7 +348,7 @@ InsertCompletion complete_line(const SelectionList& sels,
const ColumnCount tabstop = options["tabstop"].get<int>();
const ColumnCount column = get_column(buffer, tabstop, cursor_pos);
StringView prefix = trim_indent(buffer[cursor_pos.line].substr(0_byte, cursor_pos.column));
String prefix = trim_indent(buffer[cursor_pos.line].substr(0_byte, cursor_pos.column));
BufferCoord replace_begin = buffer.advance(cursor_pos, -prefix.length());
InsertCompletion::CandidateList candidates;
@ -358,15 +358,15 @@ InsertCompletion complete_line(const SelectionList& sels,
if (buf.name() == buffer.name() && l == cursor_pos.line)
continue;
const StringView line = trim_indent(buf[l]);
String line = trim_indent(buf[l]);
if (line.length() == 0)
continue;
if (prefix == line.substr(0_byte, prefix.length()))
{
StringView candidate = trim_indent(line.substr(0_byte, line.length()));
candidates.push_back({candidate.str(), "", {expand_tabs(candidate, tabstop, column), {}} });
String candidate = trim_indent(line.substr(0_byte, line.length()));
candidates.push_back({candidate, "", {expand_tabs(candidate, tabstop, column), {}} });
// perf: it's unlikely the user intends to search among >10 candidates anyway
if (candidates.size() == 100)
break;

View File

@ -1 +1 @@
gjA<c-x>l<c-n><c-n><esc>
gjA<c-x>l<c-n><esc>

View File

@ -1,4 +1,4 @@
w111111
w222222
w2