aboutsummaryrefslogtreecommitdiffstats
path: root/macros
diff options
context:
space:
mode:
Diffstat (limited to 'macros')
-rw-r--r--macros/em-dash.lua19
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