mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Shell: Make Juxtaposition autocompletion smarter
Now something like `"$HOME"/` autocompletes correctly. Note that only the first element of lists is used to autocomplete things.
This commit is contained in:
parent
2e333b3571
commit
78d1093dab
Notes:
sideshowbarker
2024-07-17 20:31:23 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/78d1093dabe Pull-request: https://github.com/SerenityOS/serenity/pull/12044 Issue: https://github.com/SerenityOS/serenity/issues/11976
1 changed files with 28 additions and 15 deletions
|
@ -3013,23 +3013,36 @@ void Juxtaposition::highlight_in_editor(Line::Editor& editor, Shell& shell, High
|
|||
Vector<Line::CompletionSuggestion> Juxtaposition::complete_for_editor(Shell& shell, size_t offset, const HitTestResult& hit_test_result)
|
||||
{
|
||||
auto matching_node = hit_test_result.matching_node;
|
||||
// '~/foo/bar' is special, we have to actually resolve the tilde
|
||||
// then complete the bareword with that path prefix.
|
||||
if (m_right->is_bareword() && m_left->is_tilde()) {
|
||||
auto tilde_value = m_left->run(shell)->resolve_as_list(shell)[0];
|
||||
|
||||
auto corrected_offset = offset - matching_node->position().start_offset;
|
||||
auto* node = static_cast<BarewordLiteral*>(matching_node.ptr());
|
||||
|
||||
if (corrected_offset > node->text().length())
|
||||
return {};
|
||||
|
||||
auto text = node->text().substring(1, node->text().length() - 1);
|
||||
|
||||
return shell.complete_path(tilde_value, text, corrected_offset - 1, Shell::ExecutableOnly::No);
|
||||
if (m_left->would_execute() || m_right->would_execute()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return Node::complete_for_editor(shell, offset, hit_test_result);
|
||||
// '~/foo/bar' is special, we have to actually resolve the tilde
|
||||
// then complete the bareword with that path prefix.
|
||||
auto left_values = m_left->run(shell)->resolve_as_list(shell);
|
||||
|
||||
if (left_values.is_empty())
|
||||
return m_right->complete_for_editor(shell, offset, hit_test_result);
|
||||
|
||||
auto& left_value = left_values.first();
|
||||
|
||||
auto right_values = m_right->run(shell)->resolve_as_list(shell);
|
||||
StringView right_value {};
|
||||
|
||||
auto corrected_offset = offset - matching_node->position().start_offset;
|
||||
|
||||
if (!right_values.is_empty())
|
||||
right_value = right_values.first();
|
||||
|
||||
if (m_left->is_tilde() && !right_value.is_empty()) {
|
||||
right_value = right_value.substring_view(1);
|
||||
corrected_offset--;
|
||||
}
|
||||
|
||||
if (corrected_offset > right_value.length())
|
||||
return {};
|
||||
|
||||
return shell.complete_path(left_value, right_value, corrected_offset, Shell::ExecutableOnly::No);
|
||||
}
|
||||
|
||||
HitTestResult Juxtaposition::hit_test_position(size_t offset) const
|
||||
|
|
Loading…
Reference in a new issue