2 Commits

Author SHA1 Message Date
deepend-tildeclub
ad67af2f8f Merge pull request #222 from ZoiteChat/fix-autocorrect-replace
Fix auto-replace to respect whole-word matches
2026-05-05 17:32:29 -06:00
cc8460d366 Fix auto-replace to respect whole-word matches 2026-05-05 17:22:56 -06:00
2 changed files with 42 additions and 1 deletions

View File

@@ -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',

View File

@@ -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)
{