diff options
Diffstat (limited to 'core')
-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 |
11 files changed, 40 insertions, 16 deletions
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) |