-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreaddocview.lua
92 lines (77 loc) · 2.4 KB
/
readdocview.lua
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local core = require "core"
---@type core.doc
local Doc = require "core.doc"
---@type core.docview
local DocView = require "core.docview"
--------------------------------------------------------------------------------
-- Read Only Document
--------------------------------------------------------------------------------
---A readonly core.doc.
---@class plugins.scm.readdoc : core.doc
---@overload fun(title?:string, text?:string):plugins.scm.readdoc
local ReadDoc = Doc:extend()
function ReadDoc:new(title, text)
ReadDoc.super.new(self, title, title)
self:set_text(text or "")
end
---Set the text.
---@param text string
function ReadDoc:set_text(text)
self.lines = {}
local i = 1
for line in text:gmatch("([^\n]*)\n?") do
if line:byte(-1) == 13 then
line = line:sub(1, -2)
self.crlf = true
end
table.insert(self.lines, line .. "\n")
self.highlighter.lines[i] = false
i = i + 1
end
self:reset_syntax()
end
function ReadDoc:raw_insert(...) end
function ReadDoc:raw_remove(...) end
function ReadDoc:load(...) end
function ReadDoc:reload() end
function ReadDoc:save(...) end
--------------------------------------------------------------------------------
-- Read Only Document View
--------------------------------------------------------------------------------
---A readonly core.docview
---@class plugins.scm.readdocview : core.docview
---@overload fun(title?:string, text?:string):plugins.scm.readdocview
local ReadDocView = DocView:extend()
---Constructor
---@param title? string
---@param text? string
function ReadDocView:new(title, text)
self.visible = false
-- close when automatically loaded from workspace plugin
if not title or not text then
ReadDocView.super.new(self, Doc())
core.add_thread(function()
-- core should offer a function to easily close a view...
local parent = core.root_view.root_node:get_node_for_view(self)
if parent then
parent:close_view(core.root_view.root_node, self)
end
end)
return
end
ReadDocView.super.new(self, ReadDoc(title, text))
self.visible = true
end
function ReadDocView:draw()
if not self.visible then return end
ReadDocView.super.draw(self)
end
function ReadDocView:update()
if not self.visible then return end
ReadDocView.super.update(self)
end
function ReadDocView:get_name()
if not self.visible then return end
return ReadDocView.super.get_name(self)
end
return ReadDocView