Skip to content

Commit 4497095

Browse files
authored
fix: avoid duplicate subtitle filtering in autoclip methods (#161)
1 parent 746b68d commit 4497095

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

mpvacious/subtitles/autoclip_methods.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,19 @@ local function new_autoclip_method_selector()
2121
end
2222

2323
function self.call(current_subtitle_lines)
24-
-- current_subtitle_lines = { primary="some text", secondary="some text" }
24+
-- current_subtitle_lines = {
25+
-- get_prepared = function()
26+
-- return {
27+
-- primary = "some text",
28+
-- secondary = "some text"
29+
-- }
30+
-- end,
31+
-- raw = {
32+
-- primary = "some text",
33+
-- secondary = "some text"
34+
-- }
35+
-- }
36+
2537
if h.is_empty(current_subtitle_lines) then
2638
return
2739
else

mpvacious/subtitles/observer.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ local function external_command_args(cur_lines)
5050
end
5151

5252
autoclip_method.register_handler('clipboard', function(current_subtitle_lines)
53-
self.copy_to_clipboard("autocopy action", current_subtitle_lines.primary)
53+
self.copy_to_clipboard("autocopy action", current_subtitle_lines.raw.primary)
5454
end)
5555

5656
autoclip_method.register_handler('goldendict', function(current_subtitle_lines)
5757
h.subprocess_detached {
58-
args = { 'goldendict', current_subtitle_lines.primary },
58+
args = {'goldendict', current_subtitle_lines.get_prepared().primary},
5959
completion_fn = on_external_finish
6060
}
6161
end)
6262

6363
autoclip_method.register_handler('custom_command', function(current_subtitle_lines)
6464
if not h.is_empty(self.config.autoclip_custom_args) then
6565
h.subprocess {
66-
args = external_command_args(current_subtitle_lines),
66+
args = external_command_args(current_subtitle_lines.get_prepared()),
6767
completion_fn = on_external_finish
6868
}
6969
end
@@ -86,7 +86,18 @@ local function current_subtitle_lines()
8686
secondary = mp.get_property("secondary-sub-text") or ""
8787
end
8888

89-
return { primary = self.clipboard_prepare(primary), secondary = secondary }
89+
return {
90+
get_prepared = function()
91+
return {
92+
primary = self.clipboard_prepare(primary),
93+
secondary = secondary
94+
}
95+
end,
96+
raw = {
97+
primary = primary,
98+
secondary = secondary
99+
}
100+
}
90101
end
91102

92103
local function copy_primary_sub()

0 commit comments

Comments
 (0)