diff options
author | 2013-10-29 23:27:24 -0400 | |
---|---|---|
committer | 2013-10-29 23:27:24 -0400 | |
commit | f39b1ecbfe29339f44402e3d3878dc3701730959 (patch) | |
tree | 2f2716a73282c7ae1c82afa9b7953a1540a35871 /modules | |
parent | 93b6fefcaf71e176ae0fab7ef515bcf178e0730b (diff) | |
download | textadept-f39b1ecbfe29339f44402e3d3878dc3701730959.tar.gz textadept-f39b1ecbfe29339f44402e3d3878dc3701730959.zip |
Fix `enclose()` to enclose the whole current word; modules/textadept/editing.lua
It used to enclose just the part of the word behind the caret.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/textadept/editing.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 30984d37..5fd900d9 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -354,16 +354,20 @@ function M.join_lines() end --- --- Encloses the selected text or the word behind the caret within strings *left* --- and *right*. +-- Encloses the selected text or the current word within strings *left* and +-- *right*. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -- @name enclose function M.enclose(left, right) buffer:target_from_selection() local s, e = buffer.target_start, buffer.target_end - if s == e then buffer.target_start = buffer:word_start_position(s, true) end - buffer:replace_target(left..buffer:text_range(buffer.target_start, e)..right) + if s == e then + buffer.target_start = buffer:word_start_position(s, true) + buffer.target_end = buffer:word_end_position(e, true) + s, e = buffer.target_start, buffer.target_end + end + buffer:replace_target(left..buffer:text_range(s, e)..right) buffer:goto_pos(buffer.target_end) end |