aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/editing.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2013-04-26 13:32:00 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2013-04-26 13:32:00 -0400
commitc53d2b6565096b7e9f17c1846d890ecd9557960b (patch)
tree6fcafbfca99bfa84b22467388e5c5d7c7a4d5362 /modules/textadept/editing.lua
parentc61bba557a11ef70b5fc4da6ec54e0730ff2a0ab (diff)
downloadtextadept-c53d2b6565096b7e9f17c1846d890ecd9557960b.tar.gz
textadept-c53d2b6565096b7e9f17c1846d890ecd9557960b.zip
Consolidated the editing module's `grow_selection()` into `enclose_selected()`.
The former was originally designed to complement the latter.
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r--modules/textadept/editing.lua22
1 files changed, 7 insertions, 15 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index eb9aa8c5..59799709 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -381,28 +381,20 @@ end
---
-- Selects the text in-between strings *left* and *right* containing the caret.
+-- If already selected, toggles between selecting the *left* and *right*
+-- enclosures too.
-- @param left The left part of the enclosure.
-- @param right The right part of the enclosure.
-- @name select_enclosed
function M.select_enclosed(left, right)
local buffer = buffer
+ local anchor, pos = buffer.anchor, buffer.current_pos
+ if anchor ~= pos then buffer:goto_pos(pos - #right) end
buffer:search_anchor()
local s, e = buffer:search_prev(0, left), buffer:search_next(0, right)
- if s >= 0 and e >= 0 then buffer:set_sel(s + 1, e) end
-end
-
----
--- Grows the selected text by *amount* number of characters on either end.
--- @param amount The number of characters to grow the selection by on either
--- end.
--- @name grow_selection
-function M.grow_selection(amount)
- local buffer = buffer
- local anchor, pos = buffer.anchor, buffer.current_pos
- if anchor < pos then
- buffer:set_sel(anchor - amount, pos + amount)
- else
- buffer:set_sel(anchor + amount, pos - amount)
+ if s >= 0 and e >= 0 then
+ if s + #left == anchor and e == pos then s, e = s - #left, e + #right end
+ buffer:set_sel(s + #left, e)
end
end