[code] textadept.editing.enclose with multiple selections

From: Brian Schott <briancschott.att.gmail.com>
Date: Tue, 26 Apr 2016 13:37:19 -0700

I made some changes to the enclose function so that it will work with
multiple selections:

---
-- 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: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)
  end
  buffer:end_undo_action()
end
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 26 Apr 2016 - 16:37:19 EDT

This archive was generated by hypermail 2.2.0 : Wed 27 Apr 2016 - 06:25:39 EDT