From b1d103ecb28589d507477715f25fba5641d247c8 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sat, 28 Feb 2009 20:55:22 -0500 Subject: Use UTF-8 internally and respect platform filename encoding. Added 'textadept.iconv' function to interface with GLib's g_convert() and set global _CHARSET to be the platform's filename encoding/code page. --- core/events.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'core/events.lua') diff --git a/core/events.lua b/core/events.lua index b28b36ee..6767ebac 100644 --- a/core/events.lua +++ b/core/events.lua @@ -371,15 +371,17 @@ add_handler('save_point_left', end) add_handler('uri_dropped', - function(uris) + function(utf8_uris) local lfs = require 'lfs' - for uri in uris:gmatch('[^\r\n\f]+') do - if uri:find('^file://') then - uri = uri:match('^file://([^\r\n\f]+)') - uri = uri:gsub('%%20', ' ') -- sub back for spaces - if WIN32 then uri = uri:sub(2, -1) end -- ignore leading '/' + for utf8_uri in utf8_uris:gmatch('[^\r\n\f]+') do + if utf8_uri:find('^file://') then + utf8_uri = utf8_uri:match('^file://([^\r\n\f]+)') + utf8_uri = utf8_uri:gsub('%%(%x%x)', + function(hex) return string.char(tonumber(hex, 16)) end) + if WIN32 then utf8_uri = utf8_uri:sub(2, -1) end -- ignore leading '/' + local uri = textadept.iconv(utf8_uri, _CHARSET, 'UTF-8') if lfs.attributes(uri).mode ~= 'directory' then - textadept.io.open(uri) + textadept.io.open(utf8_uri) end end end -- cgit v1.2.3