Fix explicit line completion
trim_indent call was incorrect, trim_indent is intended to work on multi-line strings and trims trailing whitespace as well (could benefit from a better name). Fixes #4378
This commit is contained in:
parent
7648d56fc3
commit
6029ee9815
|
@ -348,7 +348,14 @@ InsertCompletion complete_line(const SelectionList& sels,
|
||||||
const ColumnCount tabstop = options["tabstop"].get<int>();
|
const ColumnCount tabstop = options["tabstop"].get<int>();
|
||||||
const ColumnCount column = get_column(buffer, tabstop, cursor_pos);
|
const ColumnCount column = get_column(buffer, tabstop, cursor_pos);
|
||||||
|
|
||||||
String prefix = trim_indent(buffer[cursor_pos.line].substr(0_byte, cursor_pos.column));
|
auto trim_leading_whitespaces = [](StringView s) {
|
||||||
|
utf8::iterator it{s.begin(), s};
|
||||||
|
while (it != s.end() and is_horizontal_blank(*it))
|
||||||
|
++it;
|
||||||
|
return StringView{it.base(), s.end()};
|
||||||
|
};
|
||||||
|
|
||||||
|
StringView prefix = trim_leading_whitespaces(buffer[cursor_pos.line].substr(0_byte, cursor_pos.column));
|
||||||
BufferCoord replace_begin = buffer.advance(cursor_pos, -prefix.length());
|
BufferCoord replace_begin = buffer.advance(cursor_pos, -prefix.length());
|
||||||
InsertCompletion::CandidateList candidates;
|
InsertCompletion::CandidateList candidates;
|
||||||
|
|
||||||
|
@ -358,15 +365,15 @@ InsertCompletion complete_line(const SelectionList& sels,
|
||||||
if (buf.name() == buffer.name() && l == cursor_pos.line)
|
if (buf.name() == buffer.name() && l == cursor_pos.line)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String line = trim_indent(buf[l]);
|
StringView line = buf[l];
|
||||||
|
StringView candidate = trim_leading_whitespaces(line.substr(0_byte, line.length()-1));
|
||||||
|
|
||||||
if (line.length() == 0)
|
if (candidate.length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (prefix == line.substr(0_byte, prefix.length()))
|
if (prefix == candidate.substr(0_byte, prefix.length()))
|
||||||
{
|
{
|
||||||
String candidate = trim_indent(line.substr(0_byte, line.length()));
|
candidates.push_back({candidate.str(), "", {expand_tabs(candidate, tabstop, column), {}} });
|
||||||
candidates.push_back({candidate, "", {expand_tabs(candidate, tabstop, column), {}} });
|
|
||||||
// perf: it's unlikely the user intends to search among >10 candidates anyway
|
// perf: it's unlikely the user intends to search among >10 candidates anyway
|
||||||
if (candidates.size() == 100)
|
if (candidates.size() == 100)
|
||||||
break;
|
break;
|
||||||
|
|
1
test/regression/4378-line-explicit-completion-buggy/cmd
Normal file
1
test/regression/4378-line-explicit-completion-buggy/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
a<c-x>l<c-n><esc>
|
2
test/regression/4378-line-explicit-completion-buggy/in
Normal file
2
test/regression/4378-line-explicit-completion-buggy/in
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
a b
|
||||||
|
a%( )
|
2
test/regression/4378-line-explicit-completion-buggy/out
Normal file
2
test/regression/4378-line-explicit-completion-buggy/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
a b
|
||||||
|
a b
|
Loading…
Reference in New Issue
Block a user