mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
TextEditor: Go-to-line now shows line in middle of view (#4008)
This commit is contained in:
parent
940380c986
commit
1041ab88ca
2 changed files with 23 additions and 3 deletions
|
@ -96,9 +96,10 @@ void TextEditor::create_actions()
|
||||||
"Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
"Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](auto&) {
|
||||||
String value;
|
String value;
|
||||||
if (InputBox::show(value, window(), "Line:", "Go to line") == InputBox::ExecOK) {
|
if (InputBox::show(value, window(), "Line:", "Go to line") == InputBox::ExecOK) {
|
||||||
auto line_number = value.to_uint();
|
auto line_target = value.to_uint();
|
||||||
if (line_number.has_value())
|
if (line_target.has_value()) {
|
||||||
set_cursor(line_number.value() - 1, 0);
|
set_cursor_and_focus_line(line_target.value() - 1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
@ -1156,6 +1157,24 @@ Gfx::IntRect TextEditor::line_content_rect(size_t line_index) const
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditor::set_cursor_and_focus_line(size_t line, size_t column)
|
||||||
|
{
|
||||||
|
u_int index_max = line_count() - 1;
|
||||||
|
set_cursor(line, column);
|
||||||
|
if (line > 1 && line < index_max) {
|
||||||
|
int headroom = frame_inner_rect().height() / 3;
|
||||||
|
do {
|
||||||
|
auto line_data = m_line_visual_data[line];
|
||||||
|
headroom -= line_data.visual_rect.height();
|
||||||
|
line--;
|
||||||
|
} while (line > 0 && headroom > 0);
|
||||||
|
|
||||||
|
Gfx::IntRect rect = { 0, line_content_rect(line).y(),
|
||||||
|
1, frame_inner_rect().height() };
|
||||||
|
scroll_into_view(rect, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditor::update_cursor()
|
void TextEditor::update_cursor()
|
||||||
{
|
{
|
||||||
update(line_widget_rect(m_cursor.line()));
|
update(line_widget_rect(m_cursor.line()));
|
||||||
|
|
|
@ -154,6 +154,7 @@ public:
|
||||||
|
|
||||||
void add_custom_context_menu_action(Action&);
|
void add_custom_context_menu_action(Action&);
|
||||||
|
|
||||||
|
void set_cursor_and_focus_line(size_t line, size_t column);
|
||||||
void set_cursor(size_t line, size_t column);
|
void set_cursor(size_t line, size_t column);
|
||||||
void set_cursor(const TextPosition&);
|
void set_cursor(const TextPosition&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue