Change window_range to emit each element as a separate string

This commit is contained in:
Maxime Coste 2023-11-13 19:19:53 +11:00
parent 2261b48e35
commit fc7be678ed
3 changed files with 28 additions and 25 deletions

View File

@ -5,6 +5,8 @@ released versions.
== Development version == Development version
* `%val{window_range}` elements are now emitted as different strings
* `+` only duplicates identical selections a single time to avoid surprising * `+` only duplicates identical selections a single time to avoid surprising
and slow exponential growth in the number of selections. and slow exponential growth in the number of selections.

View File

@ -1115,32 +1115,32 @@ private:
const String& line = m_line_editor.line(); const String& line = m_line_editor.line();
m_completions = completer(context(), flags, line, m_completions = completer(context(), flags, line,
line.byte_count_to(m_line_editor.cursor_pos())); line.byte_count_to(m_line_editor.cursor_pos()));
if (not context().has_client())
return;
if (m_completions.candidates.empty())
return context().client().menu_hide();
Vector<DisplayLine> items;
for (auto& candidate : m_completions.candidates)
items.push_back({ candidate, {} });
const auto menu_style = (m_flags & PromptFlags::Search) ? MenuStyle::Search : MenuStyle::Prompt;
context().client().menu_show(items, {}, menu_style);
const bool menu = (bool)(m_completions.flags & Completions::Flags::Menu); const bool menu = (bool)(m_completions.flags & Completions::Flags::Menu);
if (context().has_client()) if (menu)
context().client().menu_select(0);
auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start);
if (not menu and not contains(m_completions.candidates, prefix))
{ {
if (m_completions.candidates.empty()) m_current_completion = m_completions.candidates.size();
return context().client().menu_hide(); m_completions.candidates.push_back(prefix.str());
m_prefix_in_completions = true;
Vector<DisplayLine> items;
for (auto& candidate : m_completions.candidates)
items.push_back({ candidate, {} });
const auto menu_style = (m_flags & PromptFlags::Search) ? MenuStyle::Search : MenuStyle::Prompt;
context().client().menu_show(items, {}, menu_style);
if (menu)
context().client().menu_select(0);
auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start);
if (not menu and not contains(m_completions.candidates, prefix))
{
m_current_completion = m_completions.candidates.size();
m_completions.candidates.push_back(prefix.str());
m_prefix_in_completions = true;
}
else
m_prefix_in_completions = false;
} }
else
m_prefix_in_completions = false;
} catch (runtime_error&) {} } catch (runtime_error&) {}
} }

View File

@ -46,6 +46,7 @@ struct {
StringView notes; StringView notes;
} constexpr version_notes[] = { { } constexpr version_notes[] = { {
0, 0,
"» {+b}%val{window_range}{} is now emitted as separate strings\n"
"» {+b}+{} only duplicates identical selections a single time\n" "» {+b}+{} only duplicates identical selections a single time\n"
"» {+u}daemonize-session{} command\n" "» {+u}daemonize-session{} command\n"
}, { }, {
@ -387,8 +388,8 @@ static const EnvVarDesc builtin_env_vars[] = { {
[](StringView name, const Context& context) -> Vector<String> [](StringView name, const Context& context) -> Vector<String>
{ {
const auto& setup = context.window().last_display_setup(); const auto& setup = context.window().last_display_setup();
return {format("{} {} {} {}", setup.first_line, setup.first_column, return {to_string(setup.first_line), to_string(setup.first_column),
setup.line_count, 0)}; to_string(setup.line_count), to_string(0)};
} }
}, { }, {
"history", false, "history", false,