diff options
author | 2013-09-18 21:39:40 -0400 | |
---|---|---|
committer | 2013-09-18 21:39:40 -0400 | |
commit | 91c754b5874877f57888c51c0e9f6221b11f42eb (patch) | |
tree | 0375b7e8aa4886d283934ff81b72505999e506ce | |
parent | f2e4290169cf95fe14417eae2c8952a30e1f7239 (diff) |
Support multiple selections with `select_word()`; modules/textadept/editing.lua
-rw-r--r-- | modules/textadept/editing.lua | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 72a905e5..4c9d149c 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -257,20 +257,14 @@ function M.autocomplete_word(words) end --- --- Comments or uncomments the selected lines with line comment or block comment --- delimiters string *comment* or the comment from the `comment_string` table --- for the current lexer. --- Block comment delimiters are separated by a '|' character. +-- Comments or uncomments the selected lines based on the current lexer. -- As long as any part of a line is selected, the entire line is eligible for -- commenting/uncommenting. --- @param comment Optional comment string inserted or removed from each line in --- the selection. The default value is the comment in the `comment_string` --- table for the current lexer. -- @see comment_string -- @name block_comment -function M.block_comment(comment) +function M.block_comment() local buffer = buffer - comment = comment or M.comment_string[buffer:get_lexer(true)] + local comment = M.comment_string[buffer:get_lexer(true)] local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$') if not prefix then return end local anchor, pos = buffer.selection_start, buffer.selection_end @@ -388,11 +382,23 @@ end --- -- Selects the current word. +-- If already selected, selects the next occurrence as a multiple selection. -- @see buffer.word_chars -- @name select_word function M.select_word() - buffer:set_sel(buffer:word_start_position(buffer.current_pos, true), - buffer:word_end_position(buffer.current_pos, true)) + if buffer:get_sel_text() == '' then + buffer:set_selection(buffer:word_start_position(buffer.current_pos, true), + buffer:word_end_position(buffer.current_pos, true)) + else + local word = buffer:text_range(buffer.selection_start, buffer.selection_end) + buffer.target_start = buffer.selection_n_end[buffer.selections - 1] + buffer.target_end = buffer.length - 1 + buffer.search_flags = buffer.SCFIND_MATCHCASE + buffer.SCFIND_WHOLEWORD + if buffer:search_in_target(word) ~= -1 then + buffer:add_selection(buffer.target_start, buffer.target_end) + buffer.main_selection = 0 + end + end end --- |