From 41833d7b7d1b8b08b887984d6ac744f1e6d7ed78 Mon Sep 17 00:00:00 2001 From: Tw Date: Sun, 11 Apr 2021 11:54:48 +0800 Subject: [PATCH] fix line completion with prefix There's a bug in current line completion, fix it. Signed-off-by: Tw --- src/insert_completer.cc | 8 ++++---- test/compose/line-completion/cmd | 2 +- test/compose/line-completion/in | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 2df7aa73..d7733ccc 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -348,7 +348,7 @@ InsertCompletion complete_line(const SelectionList& sels, const ColumnCount tabstop = options["tabstop"].get(); 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; diff --git a/test/compose/line-completion/cmd b/test/compose/line-completion/cmd index 46a2bfdd..a234af2c 100644 --- a/test/compose/line-completion/cmd +++ b/test/compose/line-completion/cmd @@ -1 +1 @@ -gjAl +gjAl diff --git a/test/compose/line-completion/in b/test/compose/line-completion/in index d7d4c490..8f3963c6 100644 --- a/test/compose/line-completion/in +++ b/test/compose/line-completion/in @@ -1,4 +1,4 @@ w111111 w222222 - + w2