diff options
author | garret <garret@airmail.cc> | 2023-01-26 00:35:20 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-01-26 00:35:20 +0000 |
commit | 78033c041f83f1868a98551931a53735f5154cbc (patch) | |
tree | a13528648fedcd4ea239a769b9913b9004f99db6 | |
parent | 8451de1b2e4631ff29f1d48ae34367ea0ac4a3eb (diff) | |
download | aegisub-scripts-78033c041f83f1868a98551931a53735f5154cbc.tar.gz aegisub-scripts-78033c041f83f1868a98551931a53735f5154cbc.tar.bz2 aegisub-scripts-78033c041f83f1868a98551931a53735f5154cbc.zip |
em-dash: add insert (at cursor) function
-rw-r--r-- | macros/em-dash.lua | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/macros/em-dash.lua b/macros/em-dash.lua index f175ba4..c52aa1b 100644 --- a/macros/em-dash.lua +++ b/macros/em-dash.lua @@ -1,10 +1,24 @@ script_name = "Em-dash" script_description = "I do not have an em-dash key on my keyboard" script_author = "garret" -script_version = "2.0.1" +script_version = "2.1.0" local em = "—" +local function have_cursor_funcs() + return aegisub.gui and aegisub.gui.get_cursor and aegisub.gui.set_cursor +end + +local function insert(sub, sel, act) + local line = sub[act] + local pos = aegisub.gui.get_cursor() + local start = string.sub(line.text, 1, pos - 1) + local end_ = string.sub(line.text, pos) + line.text = start .. em .. end_ + aegisub.gui.set_cursor(pos + 1) + sub[act] = line +end + local function append(sub, sel) for si, li in ipairs(sel) do local line = sub[li] @@ -30,3 +44,6 @@ end aegisub.register_macro(script_name.."/Append", "Appends an Em-dash to the selected line(s)", append) aegisub.register_macro(script_name.."/Replace", "Replaces -- with "..em, replace) +if have_cursor_funcs() then + aegisub.register_macro(script_name.."/Insert", "Inserts an em-dash at the cursor position", insert) +end |