diff --git a/NEWS b/NEWS index e5985c4..07416d0 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Bug fixes * Correct selection so it works backwards as well * Don't remove highlighting of lines when backspace/delete or newline are entered * When opening unrecognised files and cancelling choice don't remember as opened + * Fix issue with whitespace indenting on newline when splitting at whitespace ======= diff --git a/elm_code/src/lib/elm_code_text.c b/elm_code/src/lib/elm_code_text.c index abb5a69..7e7e994 100644 --- a/elm_code/src/lib/elm_code_text.c +++ b/elm_code/src/lib/elm_code_text.c @@ -210,6 +210,19 @@ elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line); } +EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line) +{ + unsigned int length, leading; + const char *content; + + content = elm_code_line_text_get(line, &length); + leading = elm_code_text_leading_whitespace_length(content, length); + if (leading == 0) + return; + + elm_code_line_text_remove(line, 0, leading); +} + EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) { unsigned int length, trailing; @@ -220,8 +233,7 @@ EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line) if (trailing == 0) return; - length -= trailing;; - elm_code_line_text_set(line, content, length); + elm_code_line_text_remove(line, length - trailing, trailing); } /* generic text functions */ diff --git a/elm_code/src/lib/elm_code_text.h b/elm_code/src/lib/elm_code_text.h index 02d2cc4..54b64d1 100644 --- a/elm_code/src/lib/elm_code_text.h +++ b/elm_code/src/lib/elm_code_text.h @@ -36,6 +36,8 @@ EAPI void elm_code_line_text_insert(Elm_Code_Line *line, unsigned int position, EAPI void elm_code_line_text_remove(Elm_Code_Line *line, unsigned int position, int length); +EAPI void elm_code_line_text_leading_whitespace_strip(Elm_Code_Line *line); + EAPI void elm_code_line_text_trailing_whitespace_strip(Elm_Code_Line *line); /** diff --git a/elm_code/src/lib/widget/elm_code_widget.c b/elm_code/src/lib/widget/elm_code_widget.c index 4b433a1..3d9067a 100644 --- a/elm_code/src/lib/widget/elm_code_widget.c +++ b/elm_code/src/lib/widget/elm_code_widget.c @@ -1030,6 +1030,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget) line = elm_code_file_line_get(code->file, row + 1); leading = elm_code_text_leading_whitespace_length(oldtext, oldlen); + elm_code_line_text_leading_whitespace_strip(line); elm_code_line_text_insert(line, 0, oldtext, leading); free(oldtext);