diff options
-rw-r--r-- | core/events.lua | 5 | ||||
-rw-r--r-- | docs/api.md | 6 | ||||
-rw-r--r-- | docs/manual.md | 2 | ||||
-rw-r--r-- | modules/lua/ta_api | 1 | ||||
-rw-r--r-- | modules/lua/ta_tags | 1 | ||||
-rw-r--r-- | src/textadept.c | 11 | ||||
-rw-r--r-- | test/test.lua | 13 |
7 files changed, 35 insertions, 4 deletions
diff --git a/core/events.lua b/core/events.lua index 0870afce..0c4b16a5 100644 --- a/core/events.lua +++ b/core/events.lua @@ -86,6 +86,9 @@ local M = {} -- Arguments: -- -- * _`code`_: The text character's character code. +-- @field COMMAND_TEXT_CHANGED (string) +-- Emitted when the text in the command entry changes. +-- `ui.command_entry:get_text()` contains the current text. -- @field DOUBLE_CLICK (string) -- Emitted after double-clicking the mouse button. -- Arguments: @@ -397,7 +400,7 @@ end) -- Set event constants. for _, v in pairs(_SCINTILLA.events) do M[v[1]:upper()] = v[1] end -local textadept_events = {'appleevent_odoc','buffer_after_switch','buffer_before_switch','buffer_deleted','buffer_new','csi','error','find','find_text_changed','focus','initialized','keypress','menu_clicked','mouse','quit','replace','replace_all','reset_after','reset_before','resume','suspend', 'tab_clicked','view_after_switch','view_before_switch','view_new'} +local textadept_events = {'appleevent_odoc','buffer_after_switch','buffer_before_switch','buffer_deleted','buffer_new','csi','command_text_changed','error','find','find_text_changed','focus','initialized','keypress','menu_clicked','mouse','quit','replace','replace_all','reset_after','reset_before','resume','suspend', 'tab_clicked','view_after_switch','view_before_switch','view_new'} for _, v in pairs(textadept_events) do M[v:upper()] = v end return M diff --git a/docs/api.md b/docs/api.md index 99ca01ac..1d615343 100644 --- a/docs/api.md +++ b/docs/api.md @@ -3916,6 +3916,12 @@ Emitted after the user types a text character into the buffer. * _`code`_: The text character's character code. +<a id="events.COMMAND_TEXT_CHANGED"></a> +#### `events.COMMAND_TEXT_CHANGED` (string) + +Emitted when the text in the command entry changes. + `ui.command_entry:get_text()` contains the current text. + <a id="events.CSI"></a> #### `events.CSI` (string) diff --git a/docs/manual.md b/docs/manual.md index 3a2f91b5..afc419d3 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -1860,6 +1860,7 @@ set\_fold\_margin\_\*colour|Renamed |set\_fold\_margin\_\*color vertical\_centre\_caret |Renamed |vertical\_center\_caret **events** | | AUTO\_C\_CANCELLED |Renamed |AUTO\_C\_CANCELED +N/A |Added |[COMMAND_TEXT_CHANGED][] N/A |Added |[FILE_BEFORE_RELOAD][] N/A |Added |[FILE_AFTER_RELOAD][] N/A |Added |[SESSION_SAVE][] @@ -1918,6 +1919,7 @@ section below. [view:set_theme()]: api.html#view.set_theme [name_of_style]: api.html#buffer.name_of_style +[COMMAND_TEXT_CHANGED]: api.html#events.COMMAND_TEXT_CHANGED [FILE_BEFORE_RELOAD]: api.html#events.FILE_BEFORE_RELOAD [FILE_AFTER_RELOAD]: api.html#events.FILE_AFTER_RELOAD [SESSION_SAVE]: api.html#events.SESSION_SAVE diff --git a/modules/lua/ta_api b/modules/lua/ta_api index 315fe204..dbc2b418 100644 --- a/modules/lua/ta_api +++ b/modules/lua/ta_api @@ -39,6 +39,7 @@ CHAR_ADDED events.CHAR_ADDED (string)\nEmitted after the user types a text chara CLASS lexer.CLASS (string)\nThe token name for class tokens. CLASS textadept.editing.XPM_IMAGES.CLASS (table)\nThe image number for classes. CLEAR keys.CLEAR (string)\nThe key that clears the current key chain.\nIt cannot be part of a key chain.\nThe default value is `'esc'` for the `Esc` key. +COMMAND_TEXT_CHANGED events.COMMAND_TEXT_CHANGED (string)\nEmitted when the text in the command entry changes.\n`ui.command_entry:get_text()` contains the current text. COMMENT lexer.COMMENT (string)\nThe token name for comment tokens. COMPILE_OUTPUT events.COMPILE_OUTPUT (string)\nEmitted when executing a language's compile shell command.\nBy default, compiler output is printed to the message buffer. In order to\noverride this behavior, connect to the event with an index of `1` and\nreturn `true`.\nArguments:\n\n* `output`: A line of string output from the command.\n* `ext_or_lexer`: The file extension or lexer name associated with the\n executed compile command. CONSTANT lexer.CONSTANT (string)\nThe token name for constant tokens. diff --git a/modules/lua/ta_tags b/modules/lua/ta_tags index feb359d0..6a3bbde2 100644 --- a/modules/lua/ta_tags +++ b/modules/lua/ta_tags @@ -39,6 +39,7 @@ CHAR_ADDED _HOME/core/events.lua /^module('events')]]$/;" F class:events CLASS _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer CLASS _HOME/modules/textadept/editing.lua /^M.XPM_IMAGES = {not CURSES and '/* XPM */static char *class[] = {/* columns rows colors chars-per-pixel */"16 16 10 1 "," c #000000",". c #001CD0","X c #008080","o c #0080E8","O c #00C0C0","+ c #24D0FC","@ c #00FFFF","# c #A4E8FC","$ c #C0FFFF","% c None",/* pixels */"%%%%% %%%%%%%%%","%%%% ## %%%%%%%","%%% ###++ %%%%%%","%% +++++. %%%%","%% oo++.. $$ %%","%% ooo.. $$$@@ %","%% ooo. @@@@@X %","%%% . OO@@XX %","%%% ## OOOXXX %","%% ###++ OOXX %%","% +++++. OX %%%","% oo++.. % %%%%","% ooo... %%%%%%%","% ooo.. %%%%%%%%","%% o. %%%%%%%%%","%%%% %%%%%%%%%%"};' or '*',not CURSES and '/* XPM */static char *namespace[] = {/* columns rows colors chars-per-pixel */"16 16 7 1 "," c #000000",". c #1D1D1D","X c #393939","o c #555555","O c #A8A8A8","+ c #AAAAAA","@ c None",/* pixels */"@@@@@@@@@@@@@@@@","@@@@+@@@@@@@@@@@","@@@.o@@@@@@@@@@@","@@@ +@@@@@@@@@@@","@@@ +@@@@@@@@@@@","@@+.@@@@@@@+@@@@","@@+ @@@@@@@o.@@@","@@@ +@@@@@@+ @@@","@@@ +@@@@@@+ @@@","@@@.X@@@@@@@.+@@","@@@@+@@@@@@@ @@@","@@@@@@@@@@@+ @@@","@@@@@@@@@@@+ @@@","@@@@@@@@@@@X.@@@","@@@@@@@@@@@+@@@@","@@@@@@@@@@@@@@@@"};' or '@',not CURSES and '/* XPM */static char *method[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #E0BC38","X c #F0DC5C","o c #FCFC80","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOO OOOO","OOOOOOOOO oo OO","OOOOOOOO ooooo O","OOOOOOO ooooo. O","OOOO O XXoo.. O","OOO oo XXX... O","OO ooooo XX.. OO","O ooooo. X. OOO","O XXoo.. O OOOO","O XXX... OOOOOOO","O XXX.. OOOOOOOO","OO X. OOOOOOOOO","OOOO OOOOOOOOOO"};' or '+',not CURSES and '/* XPM */static char *signal[] = {/* columns rows colors chars-per-pixel */"16 16 6 1 "," c #000000",". c #FF0000","X c #E0BC38","o c #F0DC5C","O c #FCFC80","+ c None",/* pixels */"++++++++++++++++","++++++++++++++++","++++++++++++++++","++++++++++ ++++","+++++++++ OO ++","++++++++ OOOOO +","+++++++ OOOOOX +","++++ + ooOOXX +","+++ OO oooXXX +","++ OOOOO ooXX ++","+ OOOOOX oX +++","+ ooOOXX + ++++","+ oooXXX +++++++","+ oooXX +++++..+","++ oX ++++++..+","++++ ++++++++++"};' or '~',not CURSES and '/* XPM */static char *slot[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #E0BC38","X c #F0DC5C","o c #FCFC80","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOO OOOO","OOOOOOOOO oo OO","OOOOOOOO ooooo O","OOOOOOO ooooo. O","OOOO O XXoo.. O","OOO oo XXX... O","OO ooooo XX.. OO","O ooooo. X. OOO","O XXoo.. O OOOO","O XXX... OOOOOOO","O XXX.. OOOOO ","OO X. OOOOOO O ","OOOO OOOOOOO "};' or '-',not CURSES and '/* XPM */static char *variable[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #8C748C","X c #9C94A4","o c #ACB4C0","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOO OOOOO","OOOOOOOO oo OOO","OOOOOOO ooooo OO","OOOOOO ooooo. OO","OOOOOO XXoo.. OO","OOOOOO XXX... OO","OOOOOO XXX.. OOO","OOOOOOO X. OOOO","OOOOOOOOO OOOOO","OOOOOOOOOOOOOOOO"};' or '.',not CURSES and '/* XPM */static char *struct[] = {/* columns rows colors chars-per-pixel */"16 16 14 1 "," c #000000",". c #008000","X c #00C000","o c #00FF00","O c #808000","+ c #C0C000","@ c #FFFF00","# c #008080","$ c #00C0C0","% c #00FFFF","& c #C0FFC0","* c #FFFFC0","= c #C0FFFF","- c None",/* pixels */"----- ---------","---- && -------","--- &&&oo ------","-- ooooo. ----","-- XXoo.. == --","-- XXX.. ===%% -","-- XXX. %%%%%# -","--- . $$%%## -","--- ** $$$### -","-- ***@@ $$## --","- @@@@@O $# ---","- ++@@OO - ----","- +++OOO -------","- +++OO --------","-- +O ---------","---- ----------"};' or '}',not CURSES and '/* XPM */static char *typedef[] = {/* columns rows colors chars-per-pixel */"16 16 10 1 "," c #000000",". c #404040","X c #6D6D6D","o c #777777","O c #949494","+ c #ACACAC","@ c #BBBBBB","# c #DBDBDB","$ c #EEEEEE","% c None",/* pixels */"%%%%% %%%%%%%%%","%%%% ## %%%%%%%","%%% ###++ %%%%%%","%% +++++. %%%%","%% oo++.. $$ %%","%% ooo.. $$$@@ %","%% ooo. @@@@@X %","%%% . OO@@XX %","%%% ## OOOXXX %","%% ###++ OOXX %%","% +++++. OX %%%","% oo++.. % %%%%","% ooo... %%%%%%%","% ooo.. %%%%%%%%","%% o. %%%%%%%%%","%%%% %%%%%%%%%%"};' or ':',CLASS=1,NAMESPACE=2,METHOD=3,SIGNAL=4,SLOT=5,VARIABLE=6,STRUCT=7,TYPEDEF=8}$/;" F class:textadept.editing.XPM_IMAGES CLEAR _HOME/core/keys.lua /^module('keys')]]$/;" F class:keys +COMMAND_TEXT_CHANGED _HOME/core/events.lua /^module('events')]]$/;" F class:events COMMENT _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer COMPILE_OUTPUT _HOME/modules/textadept/run.lua /^module('textadept.run')]]$/;" F class:events CONSTANT _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer diff --git a/src/textadept.c b/src/textadept.c index 9b1a8b8a..d0edf402 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -1913,8 +1913,12 @@ static void emit_notification(lua_State *L, SCNotification *n) { /** Signal for a Scintilla notification. */ static void notified(Scintilla *view, int _, SCNotification *n, void *L) { - if (focused_view == view || n->nmhdr.code == SCN_URIDROPPED) { - if (focused_view != view) view_focused(view, L); + if (view == command_entry) { + if (n->nmhdr.code == SCN_MODIFIED && + (n->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))) + emit(L, "command_text_changed", -1); + } else if (view == focused_view || n->nmhdr.code == SCN_URIDROPPED) { + if (view != focused_view) view_focused(view, L); emit_notification(L, n); } else if (n->nmhdr.code == SCN_FOCUSIN) view_focused(view, L); @@ -2348,6 +2352,7 @@ static void new_window() { command_entry = scintilla_new(); gtk_widget_set_size_request(command_entry, 1, 1); + g_signal_connect(command_entry, SCINTILLA_NOTIFY, G_CALLBACK(notified), lua); g_signal_connect(command_entry, "key-press-event", G_CALLBACK(keypress), lua); g_signal_connect( command_entry, "focus-out-event", G_CALLBACK(focus_lost), lua); @@ -2371,7 +2376,7 @@ static void new_window() { dummy_view = scintilla_new(); #elif CURSES pane = new_pane(new_view(0)), resize_pane(pane, LINES - 2, COLS, 1, 0); - command_entry = scintilla_new(NULL, NULL); + command_entry = scintilla_new(notified, lua); wresize(scintilla_get_window(command_entry), 1, COLS); mvwin(scintilla_get_window(command_entry), LINES - 2, 0); dummy_view = scintilla_new(NULL, NULL); diff --git a/test/test.lua b/test/test.lua index f3715a16..270aaa7b 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1325,6 +1325,19 @@ function test_command_entry_mode_restore() keys.mode = nil end +function test_command_entry_text_changed_event() + local changed = false + events.connect(events.COMMAND_TEXT_CHANGED, function() changed = true end) + ui.command_entry.run() + assert(not changed, 'changed event emitted') + ui.command_entry:set_text('foo') + assert(changed, 'changed event not emitted') + changed = false + ui.command_entry:undo() + assert(changed, 'changed event not emitted') + ui.command_entry:focus() -- hide +end + function test_editing_auto_pair() buffer.new() -- Single selection. |