mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:17:36 +00:00
LibLine: Make it possible to avoid autocompletion if requested
Setting 'allow_commit_without_listing' to false will now make LibLine show the suggestion before actually committing to it; this is useful for completions that will replace all the user input, where mistakes can go unnoticed without some visual cue.
This commit is contained in:
parent
d5b3998d23
commit
1699ddc186
4 changed files with 15 additions and 2 deletions
|
@ -1167,7 +1167,7 @@ void Editor::handle_read_event()
|
||||||
m_suggestion_manager.previous();
|
m_suggestion_manager.previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_suggestion_manager.count() < 2) {
|
if (m_suggestion_manager.count() < 2 && !completion_result.avoid_committing_to_single_suggestion) {
|
||||||
// We have none, or just one suggestion,
|
// We have none, or just one suggestion,
|
||||||
// we should just commit that and continue
|
// we should just commit that and continue
|
||||||
// after it, as if it were auto-completed.
|
// after it, as if it were auto-completed.
|
||||||
|
|
|
@ -112,6 +112,15 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
|
||||||
if (m_next_suggestion_index < m_suggestions.size()) {
|
if (m_next_suggestion_index < m_suggestions.size()) {
|
||||||
auto& next_suggestion = m_suggestions[m_next_suggestion_index];
|
auto& next_suggestion = m_suggestions[m_next_suggestion_index];
|
||||||
|
|
||||||
|
if (mode == CompletePrefix && !next_suggestion.allow_commit_without_listing) {
|
||||||
|
result.new_completion_mode = CompletionMode::ShowSuggestions;
|
||||||
|
result.avoid_committing_to_single_suggestion = true;
|
||||||
|
m_last_shown_suggestion_display_length = 0;
|
||||||
|
m_last_shown_suggestion_was_complete = false;
|
||||||
|
m_last_shown_suggestion = String::empty();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
auto can_complete = next_suggestion.invariant_offset <= m_largest_common_suggestion_prefix_length;
|
auto can_complete = next_suggestion.invariant_offset <= m_largest_common_suggestion_prefix_length;
|
||||||
ssize_t actual_offset;
|
ssize_t actual_offset;
|
||||||
size_t shown_length = m_last_shown_suggestion_display_length;
|
size_t shown_length = m_last_shown_suggestion_display_length;
|
||||||
|
@ -121,7 +130,7 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
|
||||||
break;
|
break;
|
||||||
case ShowSuggestions:
|
case ShowSuggestions:
|
||||||
actual_offset = 0 - m_largest_common_suggestion_prefix_length + next_suggestion.invariant_offset;
|
actual_offset = 0 - m_largest_common_suggestion_prefix_length + next_suggestion.invariant_offset;
|
||||||
if (can_complete)
|
if (can_complete && next_suggestion.allow_commit_without_listing)
|
||||||
shown_length = m_largest_common_suggestion_prefix_length + m_last_shown_suggestion.trivia_view.length();
|
shown_length = m_largest_common_suggestion_prefix_length + m_last_shown_suggestion.trivia_view.length();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
size_t input_offset { 0 };
|
size_t input_offset { 0 };
|
||||||
size_t static_offset { 0 };
|
size_t static_offset { 0 };
|
||||||
size_t invariant_offset { 0 };
|
size_t invariant_offset { 0 };
|
||||||
|
bool allow_commit_without_listing { true };
|
||||||
|
|
||||||
Utf32View text_view;
|
Utf32View text_view;
|
||||||
Utf32View trivia_view;
|
Utf32View trivia_view;
|
||||||
|
@ -104,6 +105,8 @@ public:
|
||||||
Vector<Utf32View> insert {};
|
Vector<Utf32View> insert {};
|
||||||
|
|
||||||
Optional<Style> style_to_apply {};
|
Optional<Style> style_to_apply {};
|
||||||
|
|
||||||
|
bool avoid_committing_to_single_suggestion { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
CompletionAttemptResult attempt_completion(CompletionMode, size_t initiation_start_index);
|
CompletionAttemptResult attempt_completion(CompletionMode, size_t initiation_start_index);
|
||||||
|
|
|
@ -1890,6 +1890,7 @@ ErrorOr<Vector<Line::CompletionSuggestion>> Shell::complete_via_program_itself(s
|
||||||
};
|
};
|
||||||
suggestion.static_offset = object.get("static_offset").to_u64(0);
|
suggestion.static_offset = object.get("static_offset").to_u64(0);
|
||||||
suggestion.invariant_offset = object.get("invariant_offset").to_u64(0);
|
suggestion.invariant_offset = object.get("invariant_offset").to_u64(0);
|
||||||
|
suggestion.allow_commit_without_listing = object.get("allow_commit_without_listing").to_bool(true);
|
||||||
suggestions.append(move(suggestion));
|
suggestions.append(move(suggestion));
|
||||||
} else {
|
} else {
|
||||||
dbgln("LibLine: Unhandled completion kind: {}", kind);
|
dbgln("LibLine: Unhandled completion kind: {}", kind);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue