aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/textadept.c
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-11-16 19:48:46 -0500
committerGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-11-16 19:48:46 -0500
commit4d661eb109e242db21deb2667b60b3a3f48c2fc7 (patch)
treea1a5b061880c73bee6bdf6d672b4bfe73f3d570f /src/textadept.c
parentb421b229cf3c5f23f297ca9195e84b616a27b4ad (diff)
Added `events.UNFOCUS` for when Textadept loses focus.
Do not emit this event when a dialog is active.
Diffstat (limited to 'src/textadept.c')
-rw-r--r--src/textadept.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/textadept.c b/src/textadept.c
index da141388..6873cc72 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -189,7 +189,7 @@ static lua_State *lua;
#if CURSES
static bool quitting;
#endif
-static bool initing, closing, show_tabs = true, tab_sync;
+static bool initing, closing, show_tabs = true, tab_sync, dialog_active;
enum {SVOID, SINT, SLEN, SINDEX, SCOLOR, SBOOL, SKEYMOD, SSTRING, SSTRINGRET};
// Forward declarations.
@@ -590,7 +590,8 @@ static int dialog(lua_State *L) {
gtdialog_set_progressbar_callback(work, L);
} else argv[i++] = luaL_checkstring(L, j);
argv[argc] = NULL;
- char *out = gtdialog(type, argc, argv);
+ char *out;
+ dialog_active = true, out = gtdialog(type, argc, argv), dialog_active = false;
return (lua_pushstring(L, out), free(out), 1);
}
@@ -2278,13 +2279,17 @@ static GtkWidget *new_findbox() {
}
/**
+ * Signal for window or command entry focus loss.
* Emit "Escape" key for the command entry on focus lost unless the window is
* losing focus or the application is quitting.
*/
static bool focus_lost(GtkWidget *widget, GdkEvent *_, void *L) {
- if (widget == window && command_entry_active) return true; // halt
- if (widget != command_entry || closing) return false;
- return (emit(L, "keypress", LUA_TNUMBER, GDK_KEY_Escape, -1), false);
+ if (widget == window) {
+ if (!dialog_active) emit(L, "unfocus", -1);
+ if (command_entry_active) return true; // keep focus if window losing focus
+ } else if (!closing)
+ emit(L, "keypress", LUA_TNUMBER, GDK_KEY_Escape, -1);
+ return false;
}
#endif // if GTK