diff options
author | 2021-02-15 00:29:20 -0500 | |
---|---|---|
committer | 2021-02-15 00:29:20 -0500 | |
commit | 7def99140aa8d9e3a4cdd0b678afed9adea95b69 (patch) | |
tree | d6124487ae272adf1a32cf5ed027a1c6c411c466 | |
parent | a81fbc0b621aef0eae640be3dc453eda409c70c2 (diff) | |
download | textadept-7def99140aa8d9e3a4cdd0b678afed9adea95b69.tar.gz textadept-7def99140aa8d9e3a4cdd0b678afed9adea95b69.zip |
Fixed inability to replace found text with escapes like '\n' and '\t'.
-rw-r--r-- | modules/textadept/find.lua | 7 | ||||
-rw-r--r-- | test/test.lua | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 72c806fa..31624503 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -372,13 +372,14 @@ function M.find_in_files(dir, filter) end local P, V, C, upper, lower = lpeg.P, lpeg.V, lpeg.C, string.upper, string.lower +local esc = {b = '\b', f = '\f', n = '\n', r = '\r', t = '\t', v = '\v'} local re_patt = lpeg.Cs(P{ - (V('text') + V('u') + V('l') + V('U') + V('L'))^1, - text = (1 - '\\' * lpeg.S('uUlLE'))^1, + (V('text') + V('u') + V('l') + V('U') + V('L') + V('esc'))^1, + text = (1 - '\\' * lpeg.S('uUlLEbfnrtv'))^1, u = '\\u' * C(1) / upper, l = '\\l' * C(1) / lower, U = P('\\U') / '' * (V('text') / upper + V('u') + V('l'))^0 * V('E')^-1, L = P('\\L') / '' * (V('text') / lower + V('u') + V('l'))^0 * V('E')^-1, - E = P('\\E') / '' + E = P('\\E') / '', esc = '\\' * C(1) / esc }) -- Returns string *text* with the following sequences unescaped: -- * "\uXXXX" sequences replaced with the equivalent UTF-8 character. diff --git a/test/test.lua b/test/test.lua index 5d09a514..3bd20223 100644 --- a/test/test.lua +++ b/test/test.lua @@ -2653,7 +2653,8 @@ function test_find_replace_regex_transforms() ['f\\1ba\\L\\2'] = 'foObarbaz', ['f\\1ba\\U\\l\\2'] = 'foObarBaz', [''] = 'az', - ['\\0'] = 'foObaRbaz' + ['\\0'] = 'foObaRbaz', + ['\\r\\n\\t'] = '\r\n\taz' } for regex, replacement in pairs(replacements) do ui.find.replace_entry_text = regex |