Skip to content

Commit b823724

Browse files
committed
Add line limit to Editor Output Log
1 parent 06d105e commit b823724

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

doc/classes/EditorSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,9 @@
924924
<member name="run/output/font_size" type="int" setter="" getter="">
925925
The size of the font in the [b]Output[/b] panel at the bottom of the editor. This setting does not impact the font size of the script editor (see [member interface/editor/code_font_size]).
926926
</member>
927+
<member name="run/output/max_lines" type="int" setter="" getter="">
928+
Maximum number of lines to show at any one time in the Output panel.
929+
</member>
927930
<member name="run/platforms/linuxbsd/prefer_wayland" type="bool" setter="" getter="">
928931
If [code]true[/code], on Linux/BSD, the editor will check for Wayland first instead of X11 (if available).
929932
</member>

editor/editor_log.cpp

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
130138
void 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) {
267275
void 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+
285329
void 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

364408
void 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);

editor/editor_log.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class EditorLog : public HBoxContainer {
128128
}
129129
};
130130

131+
int line_limit = 10000;
132+
131133
Vector<LogMessage> messages;
132134
// Maps MessageTypes to LogFilters for convenient access and storage (don't need 1 member per filter).
133135
HashMap<MessageType, LogFilter *> type_filter_map;
@@ -164,6 +166,7 @@ class EditorLog : public HBoxContainer {
164166

165167
void _rebuild_log();
166168
void _add_log_line(LogMessage &p_message, bool p_replace_previous = false);
169+
bool _check_display_message(LogMessage &p_message);
167170

168171
void _set_filter_active(bool p_active, MessageType p_message_type);
169172
void _set_search_visible(bool p_visible);
@@ -179,6 +182,7 @@ class EditorLog : public HBoxContainer {
179182
void _load_state();
180183

181184
void _update_theme();
185+
void _editor_settings_changed();
182186

183187
protected:
184188
void _notification(int p_what);

editor/editor_settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
821821
_initial_set("run/output/always_open_output_on_play", true);
822822
_initial_set("run/output/always_close_output_on_stop", false);
823823

824+
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "run/output/max_lines", 10000, "100,100000,1")
825+
824826
// Platform
825827
_initial_set("run/platforms/linuxbsd/prefer_wayland", false);
826828
set_restart_if_changed("run/platforms/linuxbsd/prefer_wayland", true);

0 commit comments

Comments
 (0)