-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathdiff_1.lua
162 lines (139 loc) · 3.79 KB
/
diff_1.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
local Layout = require("diffview.scene.layout").Layout
local lazy = require("diffview.lazy")
local oop = require("diffview.oop")
local Diff3 = lazy.access("diffview.scene.layouts.diff_3", "Diff3") ---@type Diff3|LazyModule
local Diff4 = lazy.access("diffview.scene.layouts.diff_4", "Diff4") ---@type Diff4|LazyModule
local File = lazy.access("diffview.vcs.file", "File") ---@type vcs.File|LazyModule
local Rev = lazy.access("diffview.vcs.rev", "Rev") ---@type Rev|LazyModule
local RevType = lazy.access("diffview.vcs.rev", "RevType") ---@type RevType|LazyModule
local Window = lazy.access("diffview.scene.window", "Window") ---@type Window|LazyModule
local api = vim.api
local M = {}
---@class Diff1 : Layout
---@field b Window
local Diff1 = oop.create_class("Diff1", Layout)
---@alias Diff1.WindowSymbol "b"
---@class Diff1.init.Opt
---@field b vcs.File
---@field winid_b integer
---@param opt Diff1.init.Opt
function Diff1:init(opt)
Diff1:super().init(self)
self.b = Window({ file = opt.b, id = opt.winid_b })
self:use_windows(self.b)
end
---@override
---@param pivot integer?
function Diff1:create(pivot)
self.emitter:emit("create_pre", self)
local curwin
pivot = pivot or self:find_pivot()
assert(api.nvim_win_is_valid(pivot), "Layout creation requires a valid window pivot!")
for _, win in ipairs(self.windows) do
if win.id ~= pivot then
win:close(true)
end
end
api.nvim_win_call(pivot, function()
vim.cmd("aboveleft vsp")
curwin = api.nvim_get_current_win()
if self.b then
self.b:set_id(curwin)
else
self.b = Window({ id = curwin })
end
end)
api.nvim_win_close(pivot, true)
self.windows = { self.b }
self.emitter:emit("create_post", self)
end
---@param file vcs.File
function Diff1:set_file_b(file)
self.b:set_file(file)
file.symbol = "b"
end
---@param entry FileEntry
function Diff1:use_entry(entry)
local layout = entry.layout --[[@as Diff1 ]]
assert(layout:instanceof(Diff1))
self:set_file_b(layout.b.file)
if self:is_valid() then
self:open_files()
end
end
function Diff1:get_main_win()
return self.b
end
---@param layout Diff3
---@return Diff3
function Diff1:to_diff3(layout)
assert(layout:instanceof(Diff3.__get()))
local main = self:get_main_win().file
return layout({
a = File({
adapter = main.adapter,
path = main.path,
kind = main.kind,
commit = main.commit,
get_data = main.get_data,
rev = Rev(RevType.STAGE, 2),
nulled = false, -- FIXME
}),
b = self.b.file,
c = File({
adapter = main.adapter,
path = main.path,
kind = main.kind,
commit = main.commit,
get_data = main.get_data,
rev = Rev(RevType.STAGE, 3),
nulled = false, -- FIXME
}),
})
end
---@param layout Diff4
---@return Diff4
function Diff1:to_diff4(layout)
assert(layout:instanceof(Diff4.__get()))
local main = self:get_main_win().file
return layout({
a = File({
adapter = main.adapter,
path = main.path,
kind = main.kind,
commit = main.commit,
get_data = main.get_data,
rev = Rev(RevType.STAGE, 2),
nulled = false, -- FIXME
}),
b = self.b.file,
c = File({
adapter = main.adapter,
path = main.path,
kind = main.kind,
commit = main.commit,
get_data = main.get_data,
rev = Rev(RevType.STAGE, 3),
nulled = false, -- FIXME
}),
d = File({
adapter = main.adapter,
path = main.path,
kind = main.kind,
commit = main.commit,
get_data = main.get_data,
rev = Rev(RevType.STAGE, 1),
nulled = false, -- FIXME
})
})
end
---FIXME
---@override
---@param rev Rev
---@param status string Git status symbol.
---@param sym Diff1.WindowSymbol
function Diff1.should_null(rev, status, sym)
return false
end
M.Diff1 = Diff1
return M