-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathline_text_select.lua
More file actions
76 lines (64 loc) · 1.95 KB
/
line_text_select.lua
File metadata and controls
76 lines (64 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Immersive is licensed under the terms of the GNU GPL v3: https://www.gnu.org/licenses/; © 2020 Ben Kerman
local LineSelect = require "interface.line_select"
local ssa = require "systems.ssa"
local TextSelect = require "interface.text_select"
local LineTextSelect = {}
LineTextSelect.__index = LineTextSelect
function LineTextSelect:delete_sel()
self._line_select:delete_sel()
end
function LineTextSelect:new(lines, line_conv, sel_conv, limit, init, change_handler)
local lts
local function _sel_conv() return lts.sel_ssa_def end
local function update_handler(line)
if line ~= lts.active_line then
lts.active_line = line
if lts._text_select then lts._text_select:finish() end
local txt_change_handler
if change_handler then
txt_change_handler = function(text)
change_handler(line, text)
end
end
lts._text_select = TextSelect:new(sel_conv(line), function(self, visible, has_sel, curs_pos, segments)
if visible then
lts.sel_ssa_def = self:default_generator(has_sel, curs_pos, segments)
lts._line_select:update()
else lts.sel_ssa_def = {} end
end, ssa.query{"line_select", "selection", "font_size"}, true, nil, txt_change_handler)
lts._text_select:show()
end
end
lts = {
lines = lines,
converter = converter,
limit = limit,
sel_ssa_def = {}
}
lts._line_select = LineSelect:new(lines, line_conv, _sel_conv, update_handler, limit, init)
return setmetatable(lts, LineTextSelect)
end
function LineTextSelect:show()
if self._text_select then
self._text_select:show()
end
self._line_select:show()
end
function LineTextSelect:hide()
if self._text_select then
self._text_select:hide()
end
self._line_select:hide()
end
function LineTextSelect:selection(force)
if #self.lines > 0 then
return self._text_select:selection(force)
else return nil end
end
function LineTextSelect:finish(force)
local sel = self:selection(force)
if not sel then return end
self:hide()
return sel
end
return LineTextSelect