|
@@ -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&) {
|
|
|
String value;
|
|
|
if (InputBox::show(value, window(), "Line:", "Go to line") == InputBox::ExecOK) {
|
|
|
- auto line_number = value.to_uint();
|
|
|
- if (line_number.has_value())
|
|
|
- set_cursor(line_number.value() - 1, 0);
|
|
|
+ auto line_target = value.to_uint();
|
|
|
+ if (line_target.has_value()) {
|
|
|
+ set_cursor_and_focus_line(line_target.value() - 1, 0);
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
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()
|
|
|
{
|
|
|
update(line_widget_rect(m_cursor.line()));
|