diff options
author | garret <garret@airmail.cc> | 2022-12-22 19:02:00 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2022-12-22 19:06:42 +0000 |
commit | ff4d6f2902bbe1654af748b1af013cb38473938c (patch) | |
tree | 77ace5f12981223debb5919f8462c94c5b99dcf7 /macros/garret.a-b.lua | |
parent | e8e7dc9909482897c6e7c4212a28cb99cf7bed02 (diff) | |
download | aegisub-scripts-ff4d6f2902bbe1654af748b1af013cb38473938c.tar.gz aegisub-scripts-ff4d6f2902bbe1654af748b1af013cb38473938c.tar.bz2 aegisub-scripts-ff4d6f2902bbe1654af748b1af013cb38473938c.zip |
A-B: escape magic characters in the indicator
Diffstat (limited to 'macros/garret.a-b.lua')
-rw-r--r-- | macros/garret.a-b.lua | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/macros/garret.a-b.lua b/macros/garret.a-b.lua index ddbfde4..45f133f 100644 --- a/macros/garret.a-b.lua +++ b/macros/garret.a-b.lua @@ -33,6 +33,11 @@ local function get_indicator(letter, actor) return indicator end +local function escape_pattern(txt) + local magic_chars = "%^%$%(%)%%.%[%]%*%+%-%?" + return txt:gsub("(["..magic_chars.."])", "%%%1") +end + local function main(sub, sel) local i = "a" for _,li in ipairs(sel) do @@ -60,7 +65,8 @@ local function undo(sub, sel) if line.text == indicator then line.text = "" else - line.text = line.text:gsub(indicator.."$", "") + local escaped = escape_pattern(indicator) + line.text = line.text:gsub(escaped, "") end sub[li] = line i = switch_indicator(i) |