diff options
-rw-r--r-- | modules/textadept/editing.lua | 5 | ||||
-rw-r--r-- | test/test.lua | 3 |
2 files changed, 6 insertions, 2 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 0c35942e..e130125c 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -9,7 +9,8 @@ local M = {} -- Match the previous line's indentation level after inserting a new line. -- The default value is `true`. -- @field strip_trailing_spaces (bool) --- Strip trailing whitespace before saving files. +-- Strip trailing whitespace before saving files. (Does not apply to binary +-- files.) -- The default value is `false`. -- @field autocomplete_all_words (bool) -- Autocomplete the current word using words from all open buffers. @@ -269,7 +270,7 @@ end -- Prepares the buffer for saving to a file by stripping trailing whitespace, -- ensuring a final newline, and normalizing line endings. events.connect(events.FILE_BEFORE_SAVE, function() - if not M.strip_trailing_spaces then return end + if not M.strip_trailing_spaces or not buffer.encoding then return end buffer:begin_undo_action() -- Strip trailing whitespace. for line = 1, buffer.line_count do diff --git a/test/test.lua b/test/test.lua index 047f6601..ee4cbd0f 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1481,6 +1481,9 @@ function test_editing_strip_trailing_spaces() assert_equal(buffer.current_pos, buffer.line_end_position[2]) buffer:undo() assert_equal(buffer:get_text(), text) + buffer.encoding = nil -- treat as a binary file + events.emit(events.FILE_BEFORE_SAVE) + assert_equal(buffer:get_text(), text) buffer:close(true) textadept.editing.strip_trailing_spaces = strip -- restore end |