diff options
author | 2016-04-28 08:48:59 -0400 | |
---|---|---|
committer | 2016-04-28 08:48:59 -0400 | |
commit | 3d6c4435d931d07ad5aaf7866a8791f5f0844612 (patch) | |
tree | 1c49553a06375ee5a1204a2911ea9b84df23b486 | |
parent | 1ba8afae428166f72fd29bc80cbc304d483686f1 (diff) |
`enclose()` works with multiple selections; modules/textadept/editing.lua
Thanks to Brian Schott.
-rw-r--r-- | modules/textadept/editing.lua | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 06776219..8f8cdaa0 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -359,13 +359,25 @@ end --- -- Encloses the selected text or the current word within strings *left* and --- *right*. +-- *right*, taking multiple selections into account. -- @param left The left part of the enclosure. -- @param right The right part of the enclosure. -- @name enclose function M.enclose(left, right) - if buffer.selection_empty then M.select_word() end - buffer:replace_sel(left..buffer:get_sel_text()..right) + buffer:begin_undo_action() + for i = 0, buffer.selections - 1 do + local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i] + if s == e then + buffer:set_target_range(buffer:word_start_position(s, true), + buffer:word_end_position(e, true)) + else + buffer:set_target_range(s, e) + end + buffer:replace_target(left..buffer.target_text..right) + buffer.selection_n_start[i] = buffer.target_end + buffer.selection_n_end[i] = buffer.target_end + end + buffer:end_undo_action() end --- |