diff --git a/paint/sources/functions.h b/paint/sources/functions.h index 3edc8f6f..8b00f948 100644 --- a/paint/sources/functions.h +++ b/paint/sources/functions.h @@ -325,6 +325,7 @@ void history_delete_material_group(node_group_t *group); void tab_scripts_set(char *s); char *tab_scripts_get(); void tab_scripts_create(char *name); +void tab_scripts_strip_trailing_whitespace(); void tab_scripts_draw(ui_handle_t *htab); ui_text_coloring_t *tab_scripts_get_text_coloring(); void tab_debug_draw(ui_handle_t *htab); diff --git a/paint/sources/io/export_arm.c b/paint/sources/io/export_arm.c index 559e2ef9..84e90f07 100644 --- a/paint/sources/io/export_arm.c +++ b/paint/sources/io/export_arm.c @@ -98,6 +98,7 @@ string_array_t *export_arm_fonts_to_files(char *project_path, slot_font_t_array_ void export_arm_run_project() { tab_timeline_prepare_save(); + tab_scripts_strip_trailing_whitespace(); workflow_t _workflow = g_config->workflow; g_config->workflow = WORKFLOW_PBR; diff --git a/paint/sources/ui/tab_scripts.c b/paint/sources/ui/tab_scripts.c index 2b050456..4fa192c5 100644 --- a/paint/sources/ui/tab_scripts.c +++ b/paint/sources/ui/tab_scripts.c @@ -34,6 +34,42 @@ void tab_scripts_set(char *s) { tab_scripts_minimap_dirty = true; } +static void tab_scripts_strip_line_whitespace(char *s) { + int len = string_length(s); + int write = 0; + int read = 0; + while (read < len) { + // Find end of the current line + int line_end = read; + while (line_end < len && s[line_end] != '\n') { + ++line_end; + } + // Trim trailing spaces/tabs + int trimmed_end = line_end; + while (trimmed_end > read && (s[trimmed_end - 1] == ' ' || s[trimmed_end - 1] == '\t')) { + --trimmed_end; + } + for (int i = read; i < trimmed_end; ++i) { + s[write++] = s[i]; + } + if (line_end < len) { // Keep the newline + s[write++] = '\n'; + } + read = line_end + 1; + } + s[write] = '\0'; +} + +void tab_scripts_strip_trailing_whitespace() { + if (g_project->script_datas == NULL) { + return; + } + for (i32 i = 0; i < g_project->script_datas->length; ++i) { + g_project->script_datas->buffer[i] = string_copy(g_project->script_datas->buffer[i]); + tab_scripts_strip_line_whitespace(g_project->script_datas->buffer[i]); + } +} + void tab_scripts_create(char *name) { tab_scripts_prepare(); i32 i = string_array_index_of(g_project->script_names, name);