aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/editing.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2017-08-27 09:55:32 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2017-08-27 09:55:32 -0400
commita928edb09fcda4cbfa59c47f593fab008553af17 (patch)
tree5efd495ae9d2f1c62abc737b21e733030f6da599 /modules/textadept/editing.lua
parente4f87af174807e07eaeec606f5ad9f53ca65ac0f (diff)
downloadtextadept-a928edb09fcda4cbfa59c47f593fab008553af17.tar.gz
textadept-a928edb09fcda4cbfa59c47f593fab008553af17.zip
Made `textadept.editing.transpose_chars()` UTF-8-aware.
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r--modules/textadept/editing.lua12
1 files changed, 8 insertions, 4 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 0fa078ca..09008311 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -315,10 +315,14 @@ end
function M.transpose_chars()
if buffer.current_pos == 0 then return end
local pos, byte = buffer.current_pos, buffer.char_at[buffer.current_pos]
- if byte == 10 or byte == 13 or pos == buffer.length then pos = pos - 1 end
- buffer:set_target_range(pos - 1, pos + 1)
- buffer:replace_target(buffer.target_text:reverse())
- buffer:goto_pos(pos + 1)
+ if byte == 10 or byte == 13 or pos == buffer.length then
+ pos = buffer:position_before(pos)
+ end
+ local pos1, pos2 = buffer:position_before(pos), buffer:position_after(pos)
+ local ch1, ch2 = buffer:text_range(pos1, pos), buffer:text_range(pos, pos2)
+ buffer:set_target_range(pos1, pos2)
+ buffer:replace_target(ch2..ch1)
+ buffer:goto_pos(pos2)
end
---