mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
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.
This commit is contained in:
parent
da56e208ef
commit
da1b080935
3 changed files with 5 additions and 4 deletions
|
@ -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
|
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;
|
int last_matching_offset = -1;
|
||||||
|
@ -893,7 +893,8 @@ bool Editor::search(const StringView& phrase, bool allow_empty)
|
||||||
if (allow_empty || phrase.length() > 0) {
|
if (allow_empty || phrase.length() > 0) {
|
||||||
size_t search_offset = m_search_offset;
|
size_t search_offset = m_search_offset;
|
||||||
for (size_t i = m_history_cursor; i > 0; --i) {
|
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) {
|
if (contains) {
|
||||||
last_matching_offset = i - 1;
|
last_matching_offset = i - 1;
|
||||||
if (search_offset == 0) {
|
if (search_offset == 0) {
|
||||||
|
|
|
@ -300,7 +300,7 @@ private:
|
||||||
|
|
||||||
Style find_applicable_style(size_t offset) const;
|
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()
|
inline void end_search()
|
||||||
{
|
{
|
||||||
m_is_searching = false;
|
m_is_searching = false;
|
||||||
|
|
|
@ -244,7 +244,7 @@ void Editor::enter_search()
|
||||||
m_search_editor->on_display_refresh = [this](Editor& search_editor) {
|
m_search_editor->on_display_refresh = [this](Editor& search_editor) {
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append(Utf32View { search_editor.buffer().data(), search_editor.buffer().size() });
|
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_buffer.clear();
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue