From 78033c041f83f1868a98551931a53735f5154cbc Mon Sep 17 00:00:00 2001 From: garret Date: Thu, 26 Jan 2023 00:35:20 +0000 Subject: em-dash: add insert (at cursor) function --- macros/em-dash.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-70-g09d2