aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2017-11-10 19:04:03 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2017-11-10 19:04:03 -0500
commit80e568c5e95b103ded1e19985f73a864b739cf04 (patch)
tree38db3cfee885af4f2188bc9b0d37a67e3ae390c2
parent6a784e47193042e2522dc54e0d98701c109573fb (diff)
downloadtextadept-80e568c5e95b103ded1e19985f73a864b739cf04.tar.gz
textadept-80e568c5e95b103ded1e19985f73a864b739cf04.zip
Removed `textadept.editing.match_brace()`.
"Select to Matching Brace" has been moved into `textadept.editing.select_enclosed()`, which now automatically determines what to select between if no arguments are given.
-rw-r--r--modules/textadept/editing.lua57
-rw-r--r--modules/textadept/keys.lua2
-rw-r--r--modules/textadept/menu.lua9
3 files changed, 38 insertions, 30 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 75844a44..111930c7 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -284,25 +284,6 @@ function M.paste()
end
---
--- Goes to the current character's matching brace, selecting the text in between
--- if *select* is `true`.
--- @param select Optional flag indicating whether or not to select the text
--- between matching braces. The default value is `false`.
--- @name match_brace
-function M.match_brace(select)
- local pos = buffer.current_pos
- local match_pos = buffer:brace_match(pos)
- if match_pos == -1 then return end
- if not select then
- buffer:goto_pos(match_pos)
- elseif match_pos > pos then
- buffer:set_sel(pos, match_pos + 1)
- else
- buffer:set_sel(pos + 1, match_pos)
- end
-end
-
----
-- Comments or uncomments the selected lines based on the current language.
-- As long as any part of a line is selected, the entire line is eligible for
-- commenting/uncommenting.
@@ -426,14 +407,40 @@ end
-- Selects the text between strings *left* and *right* that enclose the caret.
-- If that range is already selected, toggles between selecting *left* and
-- *right* as well.
--- @param left The left part of the enclosure.
--- @param right The right part of the enclosure.
+-- If *left* and *right* are not provided, they are inferred from the current
+-- position or selection.
+-- @param left Optional left part of the enclosure.
+-- @param right Optional right part of the enclosure.
-- @name select_enclosed
function M.select_enclosed(left, right)
- 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)
+ local s, e, anchor, pos = -1, -1, buffer.anchor, buffer.current_pos
+ if left and right then
+ if anchor ~= pos then buffer:goto_pos(pos - #right) end
+ buffer:search_anchor()
+ s, e = buffer:search_prev(0, left), buffer:search_next(0, right)
+ elseif M.auto_pairs then
+ s = buffer.selection_start
+ local char_at, style_at = buffer.char_at, buffer.style_at
+ while s >= 0 do
+ local match = M.auto_pairs[char_at[s]]
+ left, right = string.char(char_at[s]), match
+ if match then
+ if buffer:brace_match(s) >= buffer.selection_end - 1 then
+ e = buffer:brace_match(s)
+ break
+ elseif M.brace_matches[char_at[s]] or
+ style_at[s] == style_at[buffer.selection_start] then
+ buffer.search_flags = 0
+ buffer:set_target_range(s + 1, buffer.length)
+ if buffer:search_in_target(match) >= buffer.selection_end - 1 then
+ e = buffer.target_end - 1
+ break
+ end
+ end
+ end
+ s = s - 1
+ end
+ end
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)
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index 40ff9ef9..bd389775 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -303,7 +303,7 @@ keys.del = buffer.clear
keys[not OSX and (GUI and 'adel' or 'mdel')
or 'cdel'] = m_edit[_L['D_elete Word']][2]
keys[not OSX and GUI and 'ca' or 'ma'] = buffer.select_all
-keys[GUI and 'cm' or 'mm'] = textadept.editing.match_brace
+keys[GUI and 'cm' or 'mm'] = m_edit[_L['_Match Brace']][2]
keys[not OSX and ((GUI or WIN32) and 'c\n' or 'cmj')
or 'cesc'] = m_edit[_L['Complete _Word']][2]
if GUI then
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index ad23552f..7b2f2a81 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -90,7 +90,10 @@ local default_menubar = {
end},
{_L['Select _All'], buffer.select_all},
SEPARATOR,
- {_L['_Match Brace'], textadept.editing.match_brace},
+ {_L['_Match Brace'], function()
+ local match_pos = buffer:brace_match(buffer.current_pos)
+ if match_pos >= 0 then buffer:goto_pos(match_pos) end
+ end},
{_L['Complete _Word'], function()
textadept.editing.autocomplete('word')
end},
@@ -103,9 +106,7 @@ local default_menubar = {
end},
{
title = _L['_Select'],
- {_L['Select to _Matching Brace'], function()
- textadept.editing.match_brace('select')
- end},
+ {_L['Select to _Matching Brace'], sel_enc},
{_L['Select between _XML Tags'], function() sel_enc('>', '<') end},
{_L['Select in XML _Tag'], function() sel_enc('<', '>') end},
{_L['Select in _Single Quotes'], function() sel_enc("'", "'") end},