diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-09-07 00:44:55 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-07 11:42:56 +0200 |
commit | da1b080935d6344274406b0d8ff0e6395cf0ce21 (patch) | |
tree | e9d0f634b301b884bfab098b2d72c07eeca01cfd | |
parent | da56e208ef611f95d95685a564a1ec39dde87aaf (diff) | |
download | serenity-da1b080935d6344274406b0d8ff0e6395cf0ce21.zip |
LibLine: Make ^R search match the input anywhere in a given line
This is closer to what other line editors (and shells) do, and makes ^R
actually useful.
-rw-r--r-- | Libraries/LibLine/Editor.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibLine/Editor.h | 2 | ||||
-rw-r--r-- | Libraries/LibLine/InternalFunctions.cpp | 2 |
3 files changed, 5 insertions, 4 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 542aa6d591..08bef585fa 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -883,7 +883,7 @@ void Editor::cleanup_suggestions() m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB } -bool Editor::search(const StringView& phrase, bool allow_empty) +bool Editor::search(const StringView& phrase, bool allow_empty, bool from_beginning) { int last_matching_offset = -1; @@ -893,7 +893,8 @@ bool Editor::search(const StringView& phrase, bool allow_empty) if (allow_empty || phrase.length() > 0) { size_t search_offset = m_search_offset; for (size_t i = m_history_cursor; i > 0; --i) { - auto contains = m_history[i - 1].starts_with(phrase); + auto& entry = m_history[i - 1]; + auto contains = from_beginning ? entry.starts_with(phrase) : entry.contains(phrase); if (contains) { last_matching_offset = i - 1; if (search_offset == 0) { diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 1d1545f36f..bf026b62b7 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -300,7 +300,7 @@ private: Style find_applicable_style(size_t offset) const; - bool search(const StringView&, bool allow_empty = false); + bool search(const StringView&, bool allow_empty = false, bool from_beginning = true); inline void end_search() { m_is_searching = false; diff --git a/Libraries/LibLine/InternalFunctions.cpp b/Libraries/LibLine/InternalFunctions.cpp index 5802492f28..dcac6a20c0 100644 --- a/Libraries/LibLine/InternalFunctions.cpp +++ b/Libraries/LibLine/InternalFunctions.cpp @@ -244,7 +244,7 @@ void Editor::enter_search() m_search_editor->on_display_refresh = [this](Editor& search_editor) { StringBuilder builder; builder.append(Utf32View { search_editor.buffer().data(), search_editor.buffer().size() }); - if (!search(builder.build())) { + if (!search(builder.build(), false, false)) { m_buffer.clear(); m_cursor = 0; } |