aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2025-07-22 22:52:33 +0100
committergarret <garret@airmail.cc>2025-07-23 11:12:41 +0100
commit144dd17c9c8939798c6abf10778b8ea56070503b (patch)
tree13301c8bf7fbd584dd850fa0b68c3348fa0e1050
parent997146248fd202cd2a3eac67c5117ee573732e4d (diff)
downloadaegisub-scripts-144dd17c9c8939798c6abf10778b8ea56070503b.tar.gz
aegisub-scripts-144dd17c9c8939798c6abf10778b8ea56070503b.tar.bz2
aegisub-scripts-144dd17c9c8939798c6abf10778b8ea56070503b.zip
em-dash: allow overwriting selection
-rw-r--r--em-dash.lua22
1 files changed, 18 insertions, 4 deletions
diff --git a/em-dash.lua b/em-dash.lua
index 7ca18fd..d0e94d2 100644
--- a/em-dash.lua
+++ b/em-dash.lua
@@ -1,7 +1,7 @@
script_name = "Em-dash"
script_description = "I do not have an em-dash key on my keyboard"
script_author = "garret"
-script_version = "2.1.1"
+script_version = "2.2.0"
local em = "—"
@@ -12,10 +12,24 @@ 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)
+
+ local highlight_start, highlight_end = aegisub.gui.get_selection()
+ local replace_start, replace_end
+ if highlight_start ~= highlight_end then
+ replace_start = highlight_start -1
+ replace_end = highlight_end
+ else
+ replace_start = pos - 1
+ replace_end = pos
+ end
+
+ local start = string.sub(line.text, 1, replace_start)
+ local end_ = string.sub(line.text, replace_end)
line.text = start .. em .. end_
- aegisub.gui.set_cursor(pos + #em)
+ cursor_pos = replace_start + #em
+
+ aegisub.gui.set_cursor(cursor_pos)
+-- aegisub.gui.set_selection(cursor_pos + 1, cursor_pos + 1)
sub[act] = line
end