diff options
author | 2020-10-22 12:32:14 -0400 | |
---|---|---|
committer | 2020-10-22 12:32:14 -0400 | |
commit | 57871e1b1f05ee2d87c07ed6e1bcb86d753f6a43 (patch) | |
tree | 3215d10cb2a039c85b18a9dd349efd7579248d75 | |
parent | 6b82a6288fe1775f63894882ba9b1a9727780b45 (diff) | |
download | textadept-57871e1b1f05ee2d87c07ed6e1bcb86d753f6a43.tar.gz textadept-57871e1b1f05ee2d87c07ed6e1bcb86d753f6a43.zip |
`textadept.editing.strip_trailing_spaces` should not apply to binary files.
-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 |