indent selector: When line is empty, find indent from surrounding lines
Look for the first non empty line preceeding the current line, or if not found, the first non empty line following it. Fixes #1904
This commit is contained in:
parent
81f605709c
commit
59e9108812
|
@ -654,6 +654,17 @@ select_indent(const Context& context, const Selection& selection,
|
||||||
return indent;
|
return indent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto get_current_indent = [&](const Buffer& buffer, LineCount line, int tabstop)
|
||||||
|
{
|
||||||
|
for (auto l = line; l >= 0; --l)
|
||||||
|
if (buffer[l] != "\n"_sv)
|
||||||
|
return get_indent(buffer[l], tabstop);
|
||||||
|
for (auto l = line+1; l < buffer.line_count(); ++l)
|
||||||
|
if (buffer[l] != "\n"_sv)
|
||||||
|
return get_indent(buffer[l], tabstop);
|
||||||
|
return 0_char;
|
||||||
|
};
|
||||||
|
|
||||||
auto is_only_whitespaces = [](StringView str) {
|
auto is_only_whitespaces = [](StringView str) {
|
||||||
auto it = str.begin();
|
auto it = str.begin();
|
||||||
skip_while(it, str.end(),
|
skip_while(it, str.end(),
|
||||||
|
@ -667,8 +678,8 @@ select_indent(const Context& context, const Selection& selection,
|
||||||
auto& buffer = context.buffer();
|
auto& buffer = context.buffer();
|
||||||
int tabstop = context.options()["tabstop"].get<int>();
|
int tabstop = context.options()["tabstop"].get<int>();
|
||||||
auto pos = selection.cursor();
|
auto pos = selection.cursor();
|
||||||
LineCount line = pos.line;
|
const LineCount line = pos.line;
|
||||||
auto indent = get_indent(buffer[line], tabstop);
|
const auto indent = get_current_indent(buffer, line, tabstop);
|
||||||
|
|
||||||
LineCount begin_line = line - 1;
|
LineCount begin_line = line - 1;
|
||||||
if (to_begin)
|
if (to_begin)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
2j<a-i>i
|
|
@ -0,0 +1,4 @@
|
||||||
|
foo():
|
||||||
|
foo
|
||||||
|
|
||||||
|
bar
|
|
@ -0,0 +1,4 @@
|
||||||
|
foo
|
||||||
|
|
||||||
|
bar
|
||||||
|
|
Loading…
Reference in New Issue
Block a user