@@ -127,6 +127,14 @@ void EditorLog::_update_theme() {
127127 theme_cache.message_color = get_theme_color (SNAME (" font_color" ), EditorStringName (Editor)) * Color (1 , 1 , 1 , 0.6 );
128128}
129129
130+ void EditorLog::_editor_settings_changed () {
131+ int new_line_limit = int (EDITOR_GET (" run/output/max_lines" ));
132+ if (new_line_limit != line_limit) {
133+ line_limit = new_line_limit;
134+ _rebuild_log ();
135+ }
136+ }
137+
130138void EditorLog::_notification (int p_what) {
131139 switch (p_what) {
132140 case NOTIFICATION_ENTER_TREE: {
@@ -267,21 +275,57 @@ void EditorLog::_undo_redo_cbk(void *p_self, const String &p_name) {
267275void EditorLog::_rebuild_log () {
268276 log->clear ();
269277
270- for (int msg_idx = 0 ; msg_idx < messages.size (); msg_idx++) {
278+ int line_count = 0 ;
279+ int start_message_index = 0 ;
280+ int initial_skip = 0 ;
281+
282+ // Search backward for starting place.
283+ for (start_message_index = messages.size () - 1 ; start_message_index >= 0 ; start_message_index--) {
284+ LogMessage msg = messages[start_message_index];
285+ if (collapse) {
286+ if (_check_display_message (msg)) {
287+ line_count++;
288+ }
289+ } else {
290+ // If not collapsing, log each instance on a line.
291+ for (int i = 0 ; i < msg.count ; i++) {
292+ if (_check_display_message (msg)) {
293+ line_count++;
294+ }
295+ }
296+ }
297+ if (line_count >= line_limit) {
298+ initial_skip = line_count - line_limit;
299+ break ;
300+ }
301+ if (start_message_index == 0 ) {
302+ break ;
303+ }
304+ }
305+
306+ for (int msg_idx = start_message_index; msg_idx < messages.size (); msg_idx++) {
271307 LogMessage msg = messages[msg_idx];
272308
273309 if (collapse) {
274310 // If collapsing, only log one instance of the message.
275311 _add_log_line (msg);
276312 } else {
277313 // If not collapsing, log each instance on a line.
278- for (int i = 0 ; i < msg.count ; i++) {
314+ for (int i = initial_skip; i < msg.count ; i++) {
315+ initial_skip = 0 ;
279316 _add_log_line (msg);
280317 }
281318 }
282319 }
283320}
284321
322+ bool EditorLog::_check_display_message (LogMessage &p_message) {
323+ bool filter_active = type_filter_map[p_message.type ]->is_active ();
324+ String search_text = search_box->get_text ();
325+ bool search_match = search_text.is_empty () || p_message.text .findn (search_text) > -1 ;
326+ return filter_active && search_match;
327+ }
328+
285329void EditorLog::_add_log_line (LogMessage &p_message, bool p_replace_previous) {
286330 if (!is_inside_tree ()) {
287331 // The log will be built all at once when it enters the tree and has its theme items.
@@ -294,11 +338,7 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
294338 }
295339
296340 // Only add the message to the log if it passes the filters.
297- bool filter_active = type_filter_map[p_message.type ]->is_active ();
298- String search_text = search_box->get_text ();
299- bool search_match = search_text.is_empty () || p_message.text .findn (search_text) > -1 ;
300-
301- if (!filter_active || !search_match) {
341+ if (!_check_display_message (p_message)) {
302342 return ;
303343 }
304344
@@ -359,6 +399,10 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
359399 }
360400 }
361401 }
402+
403+ while (log->get_paragraph_count () > line_limit + 1 ) {
404+ log->remove_paragraph (0 , true );
405+ }
362406}
363407
364408void EditorLog::_set_filter_active (bool p_active, MessageType p_message_type) {
@@ -392,6 +436,9 @@ EditorLog::EditorLog() {
392436 save_state_timer->connect (" timeout" , callable_mp (this , &EditorLog::_save_state));
393437 add_child (save_state_timer);
394438
439+ line_limit = int (EDITOR_GET (" run/output/max_lines" ));
440+ EditorSettings::get_singleton ()->connect (" settings_changed" , callable_mp (this , &EditorLog::_editor_settings_changed));
441+
395442 HBoxContainer *hb = this ;
396443
397444 VBoxContainer *vb_left = memnew (VBoxContainer);
0 commit comments