Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching editor help centers around the found text (optional) #36866

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) {
}
}

bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) {
bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous, bool p_center_result) {

ERR_FAIL_COND_V(!selection.enabled, false);
Item *it = main;
Expand Down Expand Up @@ -2534,7 +2534,15 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
item = item->parent;
}
vscroll->set_value(offset - fh);

real_t margin;

if (p_center_result)
margin = get_size().height / 2.0f;
else
margin = fh;

vscroll->set_value(offset - margin);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/rich_text_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class RichTextLabel : public Control {
void set_tab_size(int p_spaces);
int get_tab_size() const;

bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false);
bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false, bool p_center_result = true);

void scroll_to_line(int p_line);
int get_line_count() const;
Expand Down