mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
Shell+LibLine: Record the input offset of completions
This makes the completion entry retain information about how much of the suggestion was part of the string that caused the match.
This commit is contained in:
parent
f164b808b5
commit
a9cee8ee02
Notes:
sideshowbarker
2024-07-19 02:03:04 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/a9cee8ee021 Pull-request: https://github.com/SerenityOS/serenity/pull/3675 Reviewed-by: https://github.com/awesomekling
2 changed files with 16 additions and 5 deletions
|
@ -72,6 +72,7 @@ public:
|
|||
Vector<u32> trailing_trivia;
|
||||
Style style;
|
||||
size_t start_index { 0 };
|
||||
size_t input_offset { 0 };
|
||||
|
||||
Utf32View text_view;
|
||||
Utf32View trivia_view;
|
||||
|
|
|
@ -1185,6 +1185,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_path(const String& base, cons
|
|||
} else {
|
||||
suggestions.append({ escape_token(file), " " });
|
||||
}
|
||||
suggestions.last().input_offset = token_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1202,8 +1203,9 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(const String& na
|
|||
return complete_path("", name, offset);
|
||||
|
||||
String completion = *match;
|
||||
auto token_length = escape_token(name).length();
|
||||
if (m_editor)
|
||||
m_editor->suggest(escape_token(name).length(), 0);
|
||||
m_editor->suggest(token_length, 0);
|
||||
|
||||
// Now that we have a program name starting with our token, we look at
|
||||
// other program names starting with our token and cut off any mismatching
|
||||
|
@ -1214,11 +1216,14 @@ Vector<Line::CompletionSuggestion> Shell::complete_program_name(const String& na
|
|||
int index = match - cached_path.data();
|
||||
for (int i = index - 1; i >= 0 && cached_path[i].starts_with(name); --i) {
|
||||
suggestions.append({ cached_path[i], " " });
|
||||
suggestions.last().input_offset = token_length;
|
||||
}
|
||||
for (size_t i = index + 1; i < cached_path.size() && cached_path[i].starts_with(name); ++i) {
|
||||
suggestions.append({ cached_path[i], " " });
|
||||
suggestions.last().input_offset = token_length;
|
||||
}
|
||||
suggestions.append({ cached_path[index], " " });
|
||||
suggestions.last().input_offset = token_length;
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
@ -1250,6 +1255,7 @@ Vector<Line::CompletionSuggestion> Shell::complete_variable(const String& name,
|
|||
if (suggestions.contains_slow(name))
|
||||
continue;
|
||||
suggestions.append(move(name));
|
||||
suggestions.last().input_offset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1271,8 +1277,10 @@ Vector<Line::CompletionSuggestion> Shell::complete_user(const String& name, size
|
|||
|
||||
while (di.has_next()) {
|
||||
String name = di.next_path();
|
||||
if (name.starts_with(pattern))
|
||||
if (name.starts_with(pattern)) {
|
||||
suggestions.append(name);
|
||||
suggestions.last().input_offset = offset;
|
||||
}
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
|
@ -1309,9 +1317,11 @@ Vector<Line::CompletionSuggestion> Shell::complete_option(const String& program_
|
|||
builder.append(view);
|
||||
return builder.to_string();
|
||||
};
|
||||
#define __ENUMERATE_SHELL_OPTION(name, d_, descr_) \
|
||||
if (StringView { #name }.starts_with(option_pattern)) \
|
||||
suggestions.append(maybe_negate(#name));
|
||||
#define __ENUMERATE_SHELL_OPTION(name, d_, descr_) \
|
||||
if (StringView { #name }.starts_with(option_pattern)) { \
|
||||
suggestions.append(maybe_negate(#name)); \
|
||||
suggestions.last().input_offset = offset; \
|
||||
}
|
||||
|
||||
ENUMERATE_SHELL_OPTIONS();
|
||||
#undef __ENUMERATE_SHELL_OPTION
|
||||
|
|
Loading…
Reference in a new issue