diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | core/locale.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.ar.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.de.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.es.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.fr.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.it.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.pl.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.ru.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.sv.conf | 1 | ||||
-rw-r--r-- | core/locales/locale.zh.conf | 1 | ||||
-rw-r--r-- | core/ui.lua | 46 | ||||
-rw-r--r-- | doc/manual.md | 18 | ||||
-rw-r--r-- | init.lua | 11 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 38 | ||||
-rw-r--r-- | modules/textadept/find.lua | 13 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 6 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 1 | ||||
-rw-r--r-- | test/test.lua | 98 | ||||
-rw-r--r-- | themes/dark.lua | 4 | ||||
-rw-r--r-- | themes/light.lua | 4 | ||||
-rw-r--r-- | themes/term.lua | 2 |
22 files changed, 173 insertions, 81 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 89683816..74cee61f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -448,7 +448,7 @@ Changes: * Added optional position argument to [`textadept.editing.show_documentation()`][]. -* [`textadept.editing.highlight_word()`][] does not select the word by default +* `textadept.editing.highlight_word()` does not select the word by default anymore. * Changed [file filter][] format to be more flat and intuitive. * Added `-l` and `--line` command line switches to jump to a buffer line. @@ -466,7 +466,6 @@ Changes: [PGP -- 10.3 beta Modules]: download/textadept_10.3_beta.modules.zip.asc [`os.spawn()`]: api.html#os.spawn [`textadept.editing.show_documentation()`]: api.html#textadept.editing.show_documentation -[`textadept.editing.highlight_word()`]: api.html#textadept.editing.highlight_word [PDCurses]: https://pdcurses.sourceforge.io/ ## 10.2 (01 Nov 2018) diff --git a/core/locale.conf b/core/locale.conf index e461f12f..b5792cb4 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -166,7 +166,6 @@ Delete Word = D_elete Word Select All = Select _All Match Brace = _Match Brace Complete Word = Complete _Word -Highlight Word = _Highlight Word Toggle Block Comment = Toggle _Block Comment Transpose Characters = T_ranspose Characters Join Lines = _Join Lines diff --git a/core/locales/locale.ar.conf b/core/locales/locale.ar.conf index d1cf7408..08dde3c0 100644 --- a/core/locales/locale.ar.conf +++ b/core/locales/locale.ar.conf @@ -166,7 +166,6 @@ Delete Word = اح_ذف كلمة Select All = ا_ختيار الكل Match Brace = __طابق القوس Complete Word = كمّل ال_كلمة -Highlight Word = _ظلّل الكلمة Toggle Block Comment = _بدِّل التعليق Transpose Characters = ا_سحب الحرف Join Lines = ا_دمج الأسطر diff --git a/core/locales/locale.de.conf b/core/locales/locale.de.conf index d94cfe3c..9ddee348 100644 --- a/core/locales/locale.de.conf +++ b/core/locales/locale.de.conf @@ -166,7 +166,6 @@ Delete Word = Wort löschen Select All = A_lles auswählen Match Brace = Zugehörige Klammer Complete Word = Wort vervollständigen -Highlight Word = Wort hervorheben Toggle Block Comment = Kommentar umschalten Transpose Characters = Zeichen vertauschen Join Lines = Zeilen verbinden diff --git a/core/locales/locale.es.conf b/core/locales/locale.es.conf index 299a517b..3a6f8dd6 100644 --- a/core/locales/locale.es.conf +++ b/core/locales/locale.es.conf @@ -166,7 +166,6 @@ Delete Word = _Borrar palabra Select All = Seleccionar _todo Match Brace = _Saltar a paréntesis coincidente Complete Word = C_ompletar palabra -Highlight Word = Res_altar palabra Toggle Block Comment = Activar/Desactivar co_mentario de bloque Transpose Characters = _Intercambiar caracteres Join Lines = U_nir líneas diff --git a/core/locales/locale.fr.conf b/core/locales/locale.fr.conf index 4468e16b..c2b45231 100644 --- a/core/locales/locale.fr.conf +++ b/core/locales/locale.fr.conf @@ -167,7 +167,6 @@ Delete Word = Supprim_er le mot Select All = _Tout sélectionner Match Brace = _Aller à la parenthèse correspondante Complete Word = Compléter le _mot -Highlight Word = Sur_ligner le mot Toggle Block Comment = Commenter/_Décommenter Transpose Characters = In_verser deux caractères Join Lines = _Joindre les lignes diff --git a/core/locales/locale.it.conf b/core/locales/locale.it.conf index dcd1dc64..03c394a4 100644 --- a/core/locales/locale.it.conf +++ b/core/locales/locale.it.conf @@ -166,7 +166,6 @@ Delete Word = E_limina la parola Select All = Sele_ziona tutto Match Brace = _Parentesi corrispondente Complete Word = C_ompleta la parola -Highlight Word = E_videnzia la parola Toggle Block Comment = Co_mmenta/Scommenta Transpose Characters = I_nverti due caratteri Join Lines = Con_giungi le linee diff --git a/core/locales/locale.pl.conf b/core/locales/locale.pl.conf index 351d3637..506aea78 100644 --- a/core/locales/locale.pl.conf +++ b/core/locales/locale.pl.conf @@ -167,7 +167,6 @@ Delete Word = Usuń wy_raz Select All = Z_aznacz wszystko Match Brace = Dopasuj nawias_y Complete Word = D_okończ wyraz -Highlight Word = Podświe_tl wyraz Toggle Block Comment = Włącz/wyłącz komentarz _blokowy Transpose Characters = Tran_sponuj znaki Join Lines = Połącz w_iersze diff --git a/core/locales/locale.ru.conf b/core/locales/locale.ru.conf index 50eec40c..ec8e8999 100644 --- a/core/locales/locale.ru.conf +++ b/core/locales/locale.ru.conf @@ -166,7 +166,6 @@ Delete Word = Уда_лить слово Select All = Выделить вс_ё Match Brace = _Парные скобки Complete Word = Автозавершение сл_ова -Highlight Word = Под_светить слово Toggle Block Comment = Изменить комментирование _блока Transpose Characters = Пе_реставить символы Join Lines = _Объединить строки diff --git a/core/locales/locale.sv.conf b/core/locales/locale.sv.conf index 1b3d3196..2b74dbb6 100644 --- a/core/locales/locale.sv.conf +++ b/core/locales/locale.sv.conf @@ -166,7 +166,6 @@ Delete Word = Ta _bort ord Select All = Markera _allt Match Brace = Matcha _parentes Complete Word = Komplettera _ord -Highlight Word = _Framhäv ord Toggle Block Comment = Kommentera Transpose Characters = Transponera t_ecken Join Lines = _Slå ihop rader diff --git a/core/locales/locale.zh.conf b/core/locales/locale.zh.conf index 99cf57c5..2745bf92 100644 --- a/core/locales/locale.zh.conf +++ b/core/locales/locale.zh.conf @@ -166,7 +166,6 @@ Delete Word = 删除单词(_E) Select All = 全选(_A) Match Brace = 匹配括号(_M) Complete Word = 补全单词(_W) -Highlight Word = 高亮单词(_H) Toggle Block Comment = 设置区块注释(_B) Transpose Characters = 颠倒字符(_R) Join Lines = 合并行(_J) diff --git a/core/ui.lua b/core/ui.lua index ee0042b3..5ee4fbd1 100644 --- a/core/ui.lua +++ b/core/ui.lua @@ -33,9 +33,17 @@ local ui = ui -- with a group of [`ui.print()`]() and [`ui._print()`]() function calls. -- The default value is `false`, and focuses buffers when messages are printed -- to them. +-- @field highlight_words (bool) +-- Whether or not to automatically highlight all instances of the selected +-- word. +-- The default value is `true` except in the terminal version. +-- @field INDIC_HIGHLIGHT (number) +-- The word highlight indicator number. module('ui')]] ui.silent_print = false +ui.highlight_words = not CURSES +ui.INDIC_HIGHLIGHT = _SCINTILLA.next_indic_number() -- Helper function for printing messages to buffers. -- @see ui._print @@ -179,10 +187,12 @@ ui.dialogs = setmetatable({}, {__index = function(_, k) end end}) +local events, events_connect = events, events.connect + local buffers_zorder = {} -- Adds new buffers to the z-order list. -events.connect(events.BUFFER_NEW, function() +events_connect(events.BUFFER_NEW, function() if buffer ~= ui.command_entry then table.insert(buffers_zorder, 1, buffer) end end) @@ -198,13 +208,13 @@ local function update_zorder() end table.insert(buffers_zorder, 1, buffer) end -events.connect(events.BUFFER_AFTER_SWITCH, update_zorder) -events.connect(events.VIEW_AFTER_SWITCH, update_zorder) +events_connect(events.BUFFER_AFTER_SWITCH, update_zorder) +events_connect(events.VIEW_AFTER_SWITCH, update_zorder) -- Saves and restores buffer zorder data during a reset. -events.connect( +events_connect( events.RESET_BEFORE, function(persist) persist.ui_zorder = buffers_zorder end) -events.connect( +events_connect( events.RESET_AFTER, function(persist) buffers_zorder = persist.ui_zorder end) --- @@ -281,7 +291,31 @@ function ui.goto_file(filename, split, preferred_view, sloppy) io.open_file(filename) end -local events, events_connect = events, events.connect +-- Clears highlighted word indicators. +local function clear_highlighted_words() + buffer.indicator_current = ui.INDIC_HIGHLIGHT + buffer:indicator_clear_range(1, buffer.length) +end +events_connect(events.KEYPRESS, function(code) + if keys.KEYSYMS[code] == 'esc' then clear_highlighted_words() end +end, 1) + +-- Highlight all instances of the selected word. +events_connect(events.UPDATE_UI, function(updated) + if updated and updated & buffer.UPDATE_SELECTION > 0 and + ui.highlight_words and not buffer.selection_empty and + buffer:is_range_word(buffer.selection_start, buffer.selection_end) then + clear_highlighted_words() + local word = buffer:text_range(buffer.selection_start, buffer.selection_end) + buffer.search_flags = buffer.FIND_MATCHCASE | buffer.FIND_WHOLEWORD + buffer:target_whole_document() + while buffer:search_in_target(word) ~= -1 do + buffer:indicator_fill_range( + buffer.target_start, buffer.target_end - buffer.target_start) + buffer:set_target_range(buffer.target_end, buffer.length + 1) + end + end +end) -- Ensure title, statusbar, etc. are updated for new views. events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI, 3) end) diff --git a/doc/manual.md b/doc/manual.md index acd5604c..7b464606 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -768,9 +768,8 @@ point on the current line. ### Word Highlight -In order to highlight all occurrences of a given word, such as a variable name, -place the caret over the word and press `Ctrl+Alt+Shift+H` (`⌘⇧H` on Mac OSX | -N/A in curses). This feature also works for plain text. +All occurrences of the selected word, such as a variable name, are automatically +highlighted. This also works with Find results in the current buffer. ![Word Highlight](images/wordhighlight.png) @@ -1018,11 +1017,13 @@ curses) or by reading the [buffer API documentation][]. Many of Textadept's default modules come with configurable settings that can be changed from your *~/.textadept/init.lua* (which is executed after those modules are loaded). Each module's [API documentation][] lists any configurable settings -it has. For example, in order to always hide the tab bar, disable character -autopairing with typeover, strip trailing whitespace on save, and use C99-style -line comments in C code, add the following to *~/.textadept/init.lua*: +it has. For example, in order to always hide the tab bar, stop automatically +highlighting all instances of selected words, disable character autopairing with +typeover, strip trailing whitespace on save, and use C99-style line comments in +C code, add the following to *~/.textadept/init.lua*: ui.tabs = false + ui.highlight_words = false textadept.editing.auto_pairs = nil textadept.editing.typeover_chars = nil textadept.editing.strip_trailing_spaces = true @@ -2037,6 +2038,9 @@ N/A |Added |[styles][] dir\_foreach() |Replaced|for filename in [`lfs.walk()`][] do ... end **textadept.bookmarks** | | toggle(line, on) |Changed |[toggle()][] +**textadept.editing** | | +highlight_word() |Replaced|[ui.highlight_words][] +INDIC\_HIGHLIGHT |Replaced|[ui.INDIC_HIGHLIGHT][] **textadept.file_types** | | lexers |Removed |N/A<sup>a</sup> **textadept.snippets** | | @@ -2072,6 +2076,8 @@ section below. [styles]: api.html#lexer.styles [`lfs.walk()`]: api.html#lfs.walk [toggle()]: api.html#textadept.bookmarks.toggle +[ui.highlight_words]: api.html#ui.highlight_words +[ui.INDIC_HIGHLIGHT]: api.html#ui.INDIC_HIGHLIGHT [insert()]: api.html#textadept.snippets.insert [previous()]: api.html#textadept.snippets.previous [cancel_current()]: api.html#textadept.snippets.cancel_current @@ -67,12 +67,12 @@ view.set_theme = set_theme -- needed for the first view if not arg then view:goto_buffer(buffer) end -- Temporary compatibility. -function lfs.dir_foreach(dir, f, filter, n, include_dirs) ui.dialogs.msgbox{text='Compatibility issue',text='Please change your use of "lfs.dir_foreach()" to "for filename in lfs.walk()"'}; for filename in lfs.walk(dir, filter, n, include_dirs) do if f(filename) == false then return end end end +function lfs.dir_foreach(dir, f, filter, n, include_dirs) ui.dialogs.msgbox{title='Compatibility issue',text='Please change your use of "lfs.dir_foreach()" to "for filename in lfs.walk()"'}; for filename in lfs.walk(dir, filter, n, include_dirs) do if f(filename) == false then return end end end setmetatable(_L, {__index = function(t, k) return rawget(t, k:gsub('_', '')) or 'No Localization:'..k end}) setmetatable(textadept.snippets, {__index = function(t, k) return rawget(t, k:gsub('^_', '')) end}) buffer.set_theme = function(...) view:set_theme(select(2, ...)); events.connect(events.INITIALIZED, function() ui.dialogs.msgbox{title='Compatibility issue',text='Please change your use of "buffer:set_theme()" to "view:set_theme()"'} end) end -local function en_au_to_us() for au,us in pairs{CASEINSENSITIVEBEHAVIOUR_IGNORECASE=buffer.CASEINSENSITIVEBEHAVIOR_IGNORECASE,CASEINSENSITIVEBEHAVIOUR_RESPECTCASE=buffer.CASEINSENSITIVEBEHAVIOR_RESPECTCASE,INDIC_GRADIENTCENTRE=buffer.INDIC_GRADIENTCENTER,MARGIN_COLOUR=buffer.MARGIN_COLOR,auto_c_case_insensitive_behaviour=buffer.auto_c_case_insensitive_behavior,colourise=buffer.colorize,edge_colour=buffer.edge_color,set_fold_margin_colour=function()ui.dialogs.msgbox{text='Compatibility issue',text="Please update your theme's use of renamed buffer/view fields"}; return buffer.set_fold_margin_color end,set_fold_margin_hi_colour=buffer.set_fold_margin_hi_color,vertical_centre_caret=buffer.vertical_center_caret} do buffer[au]=us;view[au]=us end end; events.connect(events.BUFFER_NEW, en_au_to_us); en_au_to_us() -events.connect(events.INITIALIZED, function() local update_keys={}; local function translate_keys(keys,new_keys) for k,v in pairs(keys) do if type(k)=='string' and k:find('^[cmas]+.$') and not k:find('ctrl') and not k:find('cmd') and not k:find('alt') and not k:find('meta') and not k:find('shift') then update_keys[#update_keys+1]=k; k=k:gsub('^(c?m?a?)s(.)','%1shift+%2'):gsub('^(c?m?)a(.)','%1alt+%2'):gsub('^(c?)m(.)',string.format('%%1%s%%2',OSX and 'cmd+' or 'meta+')):gsub('^c(.)','ctrl+%1') end new_keys[k]=type(v)=='table' and translate_keys(v,{}) or v end return new_keys end; for k,v in pairs(translate_keys(keys,{})) do keys[k]=v end; if #update_keys>0 then ui.dialogs.msgbox{text='Compatibility issue',text='Please update your keys to use the new modifiers:\n'..table.concat(update_keys,'\n')} end end) +local function en_au_to_us() for au,us in pairs{CASEINSENSITIVEBEHAVIOUR_IGNORECASE=buffer.CASEINSENSITIVEBEHAVIOR_IGNORECASE,CASEINSENSITIVEBEHAVIOUR_RESPECTCASE=buffer.CASEINSENSITIVEBEHAVIOR_RESPECTCASE,INDIC_GRADIENTCENTRE=buffer.INDIC_GRADIENTCENTER,MARGIN_COLOUR=buffer.MARGIN_COLOR,auto_c_case_insensitive_behaviour=buffer.auto_c_case_insensitive_behavior,colourise=buffer.colorize,edge_colour=buffer.edge_color,set_fold_margin_colour=function()ui.dialogs.msgbox{title='Compatibility issue',text="Please update your theme's use of renamed buffer/view fields"}; return buffer.set_fold_margin_color end,set_fold_margin_hi_colour=buffer.set_fold_margin_hi_color,vertical_centre_caret=buffer.vertical_center_caret} do buffer[au]=us;view[au]=us end end; events.connect(events.BUFFER_NEW, en_au_to_us); en_au_to_us() +events.connect(events.INITIALIZED, function() local update_keys={}; local function translate_keys(keys,new_keys) for k,v in pairs(keys) do if type(k)=='string' and k:find('^[cmas]+.$') and not k:find('ctrl') and not k:find('cmd') and not k:find('alt') and not k:find('meta') and not k:find('shift') then update_keys[#update_keys+1]=k; k=k:gsub('^(c?m?a?)s(.)','%1shift+%2'):gsub('^(c?m?)a(.)','%1alt+%2'):gsub('^(c?)m(.)',string.format('%%1%s%%2',OSX and 'cmd+' or 'meta+')):gsub('^c(.)','ctrl+%1') end new_keys[k]=type(v)=='table' and translate_keys(v,{}) or v end return new_keys end; for k,v in pairs(translate_keys(keys,{})) do keys[k]=v end; if #update_keys>0 then ui.dialogs.msgbox{title='Compatibility issue',text='Please update your keys to use the new modifiers:\n'..table.concat(update_keys,'\n')} end end) -- The remainder of this file defines default buffer properties and applies them -- to subsequent buffers. Normally, a setting like `buffer.use_tabs = false` @@ -260,9 +260,8 @@ if not CURSES then view.indic_under[ui.find.INDIC_FIND] = true end local INDIC_BRACEMATCH = textadept.editing.INDIC_BRACEMATCH view.indic_style[INDIC_BRACEMATCH] = view.INDIC_BOX view:brace_highlight_indicator(not CURSES, INDIC_BRACEMATCH) -local INDIC_HIGHLIGHT = textadept.editing.INDIC_HIGHLIGHT -view.indic_style[INDIC_HIGHLIGHT] = view.INDIC_ROUNDBOX -if not CURSES then view.indic_under[INDIC_HIGHLIGHT] = true end +view.indic_style[ui.INDIC_HIGHLIGHT] = view.INDIC_ROUNDBOX +if not CURSES then view.indic_under[ui.INDIC_HIGHLIGHT] = true end local INDIC_PLACEHOLDER = textadept.snippets.INDIC_PLACEHOLDER view.indic_style[INDIC_PLACEHOLDER] = not CURSES and view.INDIC_DOTBOX or view.INDIC_STRAIGHTBOX diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 5aafe964..20b0c0bd 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -17,15 +17,12 @@ local M = {} -- The default value is `false`. -- @field INDIC_BRACEMATCH (number) -- The matching brace highlight indicator number. --- @field INDIC_HIGHLIGHT (number) --- The word highlight indicator number. module('textadept.editing')]] M.auto_indent = true M.strip_trailing_spaces = false M.autocomplete_all_words = false M.INDIC_BRACEMATCH = _SCINTILLA.next_indic_number() -M.INDIC_HIGHLIGHT = _SCINTILLA.next_indic_number() --- -- Map of image names to registered image numbers. @@ -538,41 +535,6 @@ function M.convert_indentation() buffer:end_undo_action() end --- Clears highlighted word indicators and markers. -local function clear_highlighted_words() - buffer.indicator_current = M.INDIC_HIGHLIGHT - buffer:indicator_clear_range(1, buffer.length) -end -events.connect(events.KEYPRESS, function(code) - if keys.KEYSYMS[code] == 'esc' then clear_highlighted_words() end -end, 1) - ---- --- Highlights all occurrences of the selected text or all occurrences of the --- current word. --- @see buffer.word_chars --- @name highlight_word -function M.highlight_word() - clear_highlighted_words() - local buffer = buffer - local s, e = buffer.selection_start, buffer.selection_end - if s == e then - s = buffer:word_start_position(s, true) - e = buffer:word_end_position(s, true) - end - if s == e then return end - local word = buffer:text_range(s, e) - local flags = buffer.FIND_MATCHCASE - if buffer:is_range_word(s, e) then flags = flags | buffer.FIND_WHOLEWORD end - buffer.search_flags = flags - buffer:target_whole_document() - while buffer:search_in_target(word) ~= -1 do - buffer:indicator_fill_range( - buffer.target_start, buffer.target_end - buffer.target_start) - buffer:set_target_range(buffer.target_end, buffer.length + 1) - end -end - --- -- Passes the selected text or all buffer text to string shell command *command* -- as standard input (stdin) and replaces the input text with the command's diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index c34ce370..22a6a376 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -124,6 +124,19 @@ local function find(text, next, flags, no_wrap, wrapped) if flags >= 1 << 31 then M.find_in_files() return end -- not performed here local first_visible_line = view.first_visible_line -- for 'no results found' + -- Highlight all occurrences first, otherwise regex tags will be overwritten. + buffer.indicator_current = ui.INDIC_HIGHLIGHT + buffer:indicator_clear_range(1, buffer.length) + if ui.highlight_words and #text > 1 then + buffer.search_flags = flags + buffer:target_whole_document() + while buffer:search_in_target(text) ~= -1 do + buffer:indicator_fill_range( + buffer.target_start, buffer.target_end - buffer.target_start) + buffer:set_target_range(buffer.target_end, buffer.length + 1) + end + end + -- If text is selected, assume it is from the current search and move the -- caret appropriately for the next search. buffer:goto_pos(next and buffer.selection_end or buffer.selection_start) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 938cb0af..f70a7027 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -38,7 +38,6 @@ local M = {} -- Ctrl+A |⌘A |M-A |Select all -- Ctrl+M |^M |M-M |Match brace -- Ctrl+Enter |^Esc |M-Enter^(‡) |Complete word --- Ctrl+Alt+Shift+H |⌘⇧H |None |Highlight word -- Ctrl+/ |^/ |M-/ |Toggle block comment -- Ctrl+T |^T |^T |Transpose characters -- Ctrl+Shift+J |^J |M-J |Join lines @@ -222,7 +221,7 @@ module('textadept.keys')]] -- Unassigned keys (~ denotes keys reserved by the operating system): -- c: C H I p Q T ~ V Y _ ) ] } + -- a: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ_ ) ] } *+-/=\n\s --- ca: aAbBcCdD F jJkKlLmM N qQ t xXy zZ_"'()[]{}<>* / \s +-- ca: aAbBcCdD F H jJkKlLmM N qQ t xXy zZ_"'()[]{}<>* / \s -- -- c = 'ctrl' (Control ^) -- a = 'alt' (Alt) @@ -233,7 +232,7 @@ module('textadept.keys')]] -- Mac OSX key bindings. -- -- Unassigned keys (~ denotes keys reserved by the operating system): --- m: C ~ I JkK ~M p ~ tT V yY _ ) ] } + ~~\n +-- m: C ~H I JkK ~M p ~ tT V yY _ ) ] } + ~~\n -- c: cC D gG H J K L oO qQ xXyYzZ_ ) ] } * / -- cm: aAbBcC~D F ~HiIjJkKlL~MnN p q~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n -- @@ -313,7 +312,6 @@ local bindings = { [m_edit[_L['Match Brace']][2]] = {'ctrl+m', 'ctrl+m', 'meta+m'}, [m_edit[_L['Complete Word']][2]] = {'ctrl+\n', 'ctrl+esc', {'ctrl+meta+j', 'ctrl+\n'}}, - [textadept.editing.highlight_word] = {'ctrl+alt+H', 'cmd+H', nil}, [textadept.editing.block_comment] = {'ctrl+/', 'ctrl+/', 'meta+/'}, [textadept.editing.transpose_chars] = {'ctrl+t', 'ctrl+t', 'ctrl+t'}, [textadept.editing.join_lines] = {'ctrl+J', 'ctrl+j', 'meta+j'}, diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index c84e2bd7..4d461abb 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -97,7 +97,6 @@ local default_menubar = { {_L['Complete Word'], function() textadept.editing.autocomplete('word') end}, - {_L['Highlight Word'], textadept.editing.highlight_word}, {_L['Toggle Block Comment'], textadept.editing.block_comment}, {_L['Transpose Characters'], textadept.editing.transpose_chars}, {_L['Join Lines'], textadept.editing.join_lines}, diff --git a/test/test.lua b/test/test.lua index 8ae24678..3831fcfb 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1753,7 +1753,7 @@ function test_editing_convert_indentation() buffer:close(true) end -function test_editing_highlight_word() +function test_ui_highlight_word() buffer.new() buffer:append_text(table.concat({ 'foo', @@ -1763,18 +1763,33 @@ function test_editing_highlight_word() 'fooquux', 'foo' }, '\n')) - textadept.editing.highlight_word() + textadept.editing.select_word() + ui.update() local indics = { buffer:position_from_line(LINE(1)), buffer:position_from_line(LINE(3)) + 4, buffer:position_from_line(LINE(4)) + 4, buffer:position_from_line(LINE(6)) } - local bit = 1 << textadept.editing.INDIC_HIGHLIGHT - 1 + local bit = 1 << ui.INDIC_HIGHLIGHT - 1 for _, pos in ipairs(indics) do local mask = buffer:indicator_all_on_for(pos) assert(mask & bit > 0, 'no indicator on line %d', buffer:line_from_position(pos)) end + events.emit(events.KEYPRESS, not CURSES and 0xFF1B or 7) -- esc + local pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 1) + assert_equal(pos, 1) -- highlights cleared + -- Verify turning off word highlighting. + ui.highlight_words = false + textadept.editing.select_word() + ui.update() + pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2) + assert_equal(pos, 1) -- no highlights + ui.highlight_words = true -- reset + -- Verify partial word selections do not highlight words. + buffer:set_sel(1, 3) + pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2) + assert_equal(pos, 1) -- no highlights buffer:close(true) end @@ -1999,6 +2014,53 @@ function test_ui_find_find_text() buffer:close(true) end +function test_ui_find_highlight_results() + local function assert_indics(indics) + local bit = 1 << ui.INDIC_HIGHLIGHT - 1 + for _, pos in ipairs(indics) do + local mask = buffer:indicator_all_on_for(pos) + assert(mask & bit > 0, 'no indicator on line %d', buffer:line_from_position(pos)) + end + end + + buffer.new() + buffer:append_text(table.concat({ + 'foo', + 'foobar', + 'bar foo', + 'baz foo bar', + 'fooquux', + 'foo' + }, '\n')) + -- Normal search. + ui.find.find_entry_text = 'foo' + ui.find.find_next() + assert_indics{ + buffer:position_from_line(LINE(1)), + buffer:position_from_line(LINE(3)) + 4, + buffer:position_from_line(LINE(4)) + 4, + buffer:position_from_line(LINE(6)) + } + -- Regex search. + ui.find.find_entry_text = 'ba.' + ui.find.regex = true + ui.find.find_next() + assert_indics{ + buffer:position_from_line(LINE(2)) + 3, + buffer:position_from_line(LINE(3)), + buffer:position_from_line(LINE(4)), + buffer:position_from_line(LINE(4)) + 8, + } + ui.find.regex = false -- reset + -- Do not highlight short searches (potential performance issue). + ui.find.find_entry_text = 'f' + ui.find.find_next() + local pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2) + assert_equal(pos, 1) + ui.find.find_entry_text = '' -- reset + buffer:close(true) +end + function test_ui_find_incremental() if not rawget(ui.find.find_incremental_keys, '\n') then -- Overwritten in _USERHOME. @@ -2052,6 +2114,36 @@ function test_ui_find_incremental() assert_raises(function() ui.find.find_incremental(1) end, 'string/nil expected, got number') end +function test_ui_find_incremental_highlight() + buffer.new() + buffer:set_text(table.concat({ + ' foo', + 'foobar', + 'FOObaz', + 'FOOquux' + }, '\n')) + ui.find.find_incremental() + events.emit(events.KEYPRESS, string.byte('f')) + ui.command_entry:add_text('f') -- simulate keypress + local pos = buffer:indicator_end(ui.INDIC_HIGHLIGHT, 2) + assert_equal(pos, 1) -- too short + events.emit(events.KEYPRESS, string.byte('o')) + ui.command_entry:add_text('o') -- simulate keypress + local indics = { + buffer:position_from_line(LINE(1)) + 1, + buffer:position_from_line(LINE(2)), + buffer:position_from_line(LINE(3)), + buffer:position_from_line(LINE(4)) + } + local bit = 1 << ui.INDIC_HIGHLIGHT - 1 + for _, pos in ipairs(indics) do + local mask = buffer:indicator_all_on_for(pos) + assert(mask & bit > 0, 'no indicator on line %d', buffer:line_from_position(pos)) + end + ui.find.find_entry_text = '' -- reset + buffer:close(true) +end + function test_ui_find_find_in_files() ui.find.find_entry_text = 'foo' ui.find.match_case = true diff --git a/themes/dark.lua b/themes/dark.lua index 89f8b99d..4d5d2087 100644 --- a/themes/dark.lua +++ b/themes/dark.lua @@ -118,11 +118,11 @@ for i = buffer.MARKNUM_FOLDEREND, buffer.MARKNUM_FOLDEROPEN do -- fold margin end -- Indicators. +view.indic_fore[ui.INDIC_HIGHLIGHT] = colors.grey +view.indic_alpha[ui.INDIC_HIGHLIGHT] = 128 view.indic_fore[ui.find.INDIC_FIND] = colors.dark_yellow view.indic_alpha[ui.find.INDIC_FIND] = 255 view.indic_fore[textadept.editing.INDIC_BRACEMATCH] = colors.light_grey -view.indic_fore[textadept.editing.INDIC_HIGHLIGHT] = colors.orange -view.indic_alpha[textadept.editing.INDIC_HIGHLIGHT] = 255 view.indic_fore[textadept.snippets.INDIC_PLACEHOLDER] = colors.grey -- Call tips. diff --git a/themes/light.lua b/themes/light.lua index a78dbe96..70afaf9b 100644 --- a/themes/light.lua +++ b/themes/light.lua @@ -118,11 +118,11 @@ for i = buffer.MARKNUM_FOLDEREND, buffer.MARKNUM_FOLDEROPEN do -- fold margin end -- Indicators. +view.indic_fore[ui.INDIC_HIGHLIGHT] = colors.light_grey +view.indic_alpha[ui.INDIC_HIGHLIGHT] = 128 view.indic_fore[ui.find.INDIC_FIND] = colors.yellow view.indic_alpha[ui.find.INDIC_FIND] = 255 view.indic_fore[textadept.editing.INDIC_BRACEMATCH] = colors.grey -view.indic_fore[textadept.editing.INDIC_HIGHLIGHT] = colors.orange -view.indic_alpha[textadept.editing.INDIC_HIGHLIGHT] = 255 local INDIC_PLACEHOLDER = textadept.snippets.INDIC_PLACEHOLDER view.indic_fore[INDIC_PLACEHOLDER] = colors.grey_black diff --git a/themes/term.lua b/themes/term.lua index ec2fd53a..d9c67c78 100644 --- a/themes/term.lua +++ b/themes/term.lua @@ -75,8 +75,8 @@ view.marker_back[textadept.run.MARK_WARNING] = colors.yellow view.marker_back[textadept.run.MARK_ERROR] = colors.red -- Indicators. +view.indic_fore[ui.INDIC_HIGHLIGHT] = colors.yellow view.indic_fore[ui.find.INDIC_FIND] = colors.yellow -view.indic_fore[textadept.editing.INDIC_HIGHLIGHT] = colors.yellow view.indic_fore[textadept.snippets.INDIC_PLACEHOLDER] = colors.magenta -- Call tips. |