aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2011-08-09 18:57:30 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2011-08-09 18:57:30 -0400
commit130a9677c7c14e93dfbddd12fd54c41d605bbc5b (patch)
tree8b31f09bd2be75e9f3d3a7b1ee87ffbd3a643c8d /modules
parenta8af7ff1d2141bdbbd6d670b23c34f993496a353 (diff)
downloadtextadept-130a9677c7c14e93dfbddd12fd54c41d605bbc5b.tar.gz
textadept-130a9677c7c14e93dfbddd12fd54c41d605bbc5b.zip
Autocomplete supports multiple selections.
Contributed by Brian Schott.
Diffstat (limited to 'modules')
-rw-r--r--modules/textadept/adeptsense.lua9
-rw-r--r--modules/textadept/editing.lua28
2 files changed, 34 insertions, 3 deletions
diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua
index aab1bd65..e414bd73 100644
--- a/modules/textadept/adeptsense.lua
+++ b/modules/textadept/adeptsense.lua
@@ -504,7 +504,14 @@ function complete(sense, only_fields, only_functions)
buffer:clear_registered_images()
buffer:register_image(1, FIELDS)
buffer:register_image(2, FUNCTIONS)
- buffer:auto_c_show(#part, table.concat(completions, ' '))
+ if not buffer.auto_c_choose_single or #completions ~= 1 then
+ buffer:auto_c_show(#part, table.concat(completions, ' '))
+ else
+ -- Scintilla does not emit AUTO_C_SELECTION in this case. This is necessary
+ -- for autocompletion with multiple selections.
+ events.emit(events.AUTO_C_SELECTION, completions[1]:sub(#part + 1),
+ buffer.current_pos)
+ end
return true
end
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 5fe7ab7f..b6b6c9ee 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -138,6 +138,23 @@ events.connect(events.CHAR_ADDED, function(char)
end
end)
+-- Autocomplete multiple selections.
+events.connect(events.AUTO_C_SELECTION, function(text, position)
+ local buffer = buffer
+ local caret = buffer.selection_n_caret[buffer.main_selection]
+ if position ~= caret then text = text:sub(caret - position + 1) end
+ buffer:begin_undo_action()
+ for i = 0, buffer.selections - 1 do
+ buffer.target_start = buffer.selection_n_anchor[i]
+ buffer.target_end = buffer.selection_n_caret[i]
+ buffer:replace_target(text)
+ buffer.selection_n_anchor[i] = buffer.selection_n_anchor[i] + #text
+ buffer.selection_n_caret[i] = buffer.selection_n_caret[i] + #text
+ end
+ buffer:end_undo_action()
+ buffer:auto_c_cancel() -- tell Scintilla not to handle autocompletion normally
+end)
+
---
-- Goes to a matching brace position, selecting the text inside if specified.
-- @param select If true, selects the text between matching braces.
@@ -172,7 +189,8 @@ function autocomplete_word(word_chars)
if not root or root == '' then return end
local patt = '^['..word_chars..']+'
buffer.target_start, buffer.target_end = 0, buffer.length
- buffer.search_flags = 1048580 -- word start and match case
+ buffer.search_flags = _SCINTILLA.constants.SCFIND_WORDSTART +
+ _SCINTILLA.constants.SCFIND_MATCHCASE
local match_pos = buffer:search_in_target(root)
while match_pos ~= -1 do
local s, e = buffer_text:find(patt, match_pos + 1)
@@ -185,7 +203,13 @@ function autocomplete_word(word_chars)
match_pos = buffer:search_in_target(root)
end
if #c_list > 0 then
- buffer:auto_c_show(#root, table.concat(c_list, ' '))
+ if not buffer.auto_c_choose_single or #c_list ~= 1 then
+ buffer:auto_c_show(#root, table.concat(c_list, ' '))
+ else
+ -- Scintilla does not emit AUTO_C_SELECTION in this case. This is
+ -- necessary for autocompletion with multiple selections.
+ events.emit(events.AUTO_C_SELECTION, c_list[1]:sub(#root + 1), caret)
+ end
return true
end
end