mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibLine: Correctly slice completion substrings as unicode strings
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-22.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-22.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-22.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Ports a fix from Serenity's LibLine.
cee0d979cc
This commit is contained in:
parent
087fcb84cb
commit
5ac0e81c4a
Notes:
github-actions[bot]
2024-09-20 10:58:01 +00:00
Author: https://github.com/alimpfard Commit: https://github.com/LadybirdBrowser/ladybird/commit/5ac0e81c4ae Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1443
3 changed files with 13 additions and 6 deletions
|
@ -383,7 +383,13 @@ void Editor::insert(ByteString const& string)
|
|||
|
||||
void Editor::insert(StringView string_view)
|
||||
{
|
||||
for (auto ch : Utf8View { string_view })
|
||||
auto view = Utf8View { string_view };
|
||||
insert(view);
|
||||
}
|
||||
|
||||
void Editor::insert(Utf8View& view)
|
||||
{
|
||||
for (auto ch : view)
|
||||
insert(ch);
|
||||
}
|
||||
|
||||
|
@ -1205,7 +1211,7 @@ ErrorOr<void> Editor::handle_read_event()
|
|||
m_chars_touched_in_the_middle++;
|
||||
|
||||
for (auto& view : completion_result.insert)
|
||||
insert(view.as_string());
|
||||
insert(view);
|
||||
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream));
|
||||
|
|
|
@ -218,6 +218,7 @@ public:
|
|||
void clear_line();
|
||||
void insert(ByteString const&);
|
||||
void insert(StringView);
|
||||
void insert(Utf8View&);
|
||||
void insert(Utf32View const&);
|
||||
void insert(u32 const);
|
||||
void stylize(Span const&, Style const&);
|
||||
|
|
|
@ -141,14 +141,14 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
|
|||
if (mode == CompletePrefix) {
|
||||
// Only auto-complete *if possible*.
|
||||
if (can_complete) {
|
||||
result.insert.append(suggestion.text_view().substring_view(suggestion.invariant_offset, m_largest_common_suggestion_prefix_length - suggestion.invariant_offset));
|
||||
result.insert.append(suggestion.text_view().unicode_substring_view(suggestion.invariant_offset, m_largest_common_suggestion_prefix_length - suggestion.invariant_offset));
|
||||
m_last_shown_suggestion_display_length = m_largest_common_suggestion_prefix_length;
|
||||
// Do not increment the suggestion index, as the first tab should only be a *peek*.
|
||||
if (m_suggestions.size() == 1) {
|
||||
// If there's one suggestion, commit and forget.
|
||||
result.new_completion_mode = DontComplete;
|
||||
// Add in the trivia of the last selected suggestion.
|
||||
result.insert.append(suggestion.trivia_view());
|
||||
result.insert.append(suggestion.trailing_trivia.code_points());
|
||||
m_last_shown_suggestion_display_length = 0;
|
||||
result.style_to_apply = suggestion.style;
|
||||
m_last_shown_suggestion_was_complete = true;
|
||||
|
@ -161,9 +161,9 @@ SuggestionManager::CompletionAttemptResult SuggestionManager::attempt_completion
|
|||
m_last_shown_suggestion_was_complete = false;
|
||||
m_last_shown_suggestion = ByteString::empty();
|
||||
} else {
|
||||
result.insert.append(suggestion.text_view().substring_view(suggestion.invariant_offset, suggestion.text_view().length() - suggestion.invariant_offset));
|
||||
result.insert.append(suggestion.text_view().unicode_substring_view(suggestion.invariant_offset, suggestion.text_view().length() - suggestion.invariant_offset));
|
||||
// Add in the trivia of the last selected suggestion.
|
||||
result.insert.append(suggestion.trivia_view());
|
||||
result.insert.append(suggestion.trailing_trivia.code_points());
|
||||
m_last_shown_suggestion_display_length += suggestion.trivia_view().length();
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue