From cc8460d36613bed4e066e305049f93a649a9774a Mon Sep 17 00:00:00 2001 From: deepend-tildeclub Date: Tue, 5 May 2026 17:22:56 -0600 Subject: [PATCH] Fix auto-replace to respect whole-word matches --- plugins/lua/meson.build | 14 +++++++++++++- src/fe-gtk/fkeys.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/lua/meson.build b/plugins/lua/meson.build index d6563172..010863bc 100644 --- a/plugins/lua/meson.build +++ b/plugins/lua/meson.build @@ -1,7 +1,19 @@ if cc.get_id() == 'msvc' lua_dep = cc.find_library('lua51') else - lua_dep = dependency(get_option('with-lua')) + lua_opt = get_option('with-lua') + lua_dep = dependency(lua_opt, required: false) + if not lua_dep.found() and lua_opt == 'lua-5.4' + foreach lua_name : ['lua5.4', 'lua-5.3', 'lua5.3', 'lua'] + lua_dep = dependency(lua_name, required: false) + if lua_dep.found() + break + endif + endforeach + endif + if not lua_dep.found() + error('Dependency "' + lua_opt + '" not found') + endif endif shared_module('lua', 'lua.c', diff --git a/src/fe-gtk/fkeys.c b/src/fe-gtk/fkeys.c index a87f3108..5add39a9 100644 --- a/src/fe-gtk/fkeys.c +++ b/src/fe-gtk/fkeys.c @@ -1973,8 +1973,37 @@ replace_handle (GtkWidget *t) { ptrdiff_t found_offset = found - text; ptrdiff_t found_end_offset = found_offset + (ptrdiff_t) pop_len; + gboolean start_ok; + gboolean end_ok; int rank; ptrdiff_t distance; + const char *before = found; + const char *after = found + pop_len; + + if (before > text) + { + before = g_utf8_find_prev_char (text, before); + start_ok = !before || (!g_unichar_isalnum (g_utf8_get_char (before)) && g_utf8_get_char (before) != '_'); + } + else + { + start_ok = TRUE; + } + + if (*after != '\0') + { + end_ok = !g_unichar_isalnum (g_utf8_get_char (after)) && g_utf8_get_char (after) != '_'; + } + else + { + end_ok = TRUE; + } + + if (!start_ok || !end_ok) + { + found++; + continue; + } if (cursor_byte_offset >= found_offset && cursor_byte_offset <= found_end_offset) {