aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2009-01-25 15:09:23 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2009-01-25 15:09:23 -0500
commita874a6dd0ae87f565a053324fed12bbc9a6152ce (patch)
tree82094332f8cbdc54e4874fa25a329171361b7dc5 /core
parentdd69c77712c089902194f2a2d74b6ffdfff6c78d (diff)
downloadtextadept-a874a6dd0ae87f565a053324fed12bbc9a6152ce.tar.gz
textadept-a874a6dd0ae87f565a053324fed12bbc9a6152ce.zip
Fixed bugs with opening binary files; core/file_io.lua
Diffstat (limited to 'core')
-rw-r--r--core/file_io.lua6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index d9f1c25e..3adb9d89 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -28,7 +28,11 @@ local function open_helper(filename)
local buffer = textadept.new_buffer()
local f, err = io.open(filename)
if f then
- buffer:set_text(f:read('*all'))
+ local text = f:read('*all')
+ local chunk = #text > 65536 and text:sub(1, 65536) or text
+ if chunk:find('\0') then buffer.code_page = 0 end -- binary file; no UTF-8
+ buffer:add_text(text, #text)
+ buffer:goto_pos(0)
buffer:empty_undo_buffer()
f:close()
end