Skip to content

Commit 58f14a5

Browse files
authored
fix: more misc. bug fixes (#21)
* Fix get_style() returning only the first matching style attribute instead of all of them (e.g. "bold" instead of "bold,strikethrough"). * Fix inverted guard conditions in FilePanel and FileHistoryPanel get_item_at_cursor/get_dir_at_cursor that could crash when the panel buffer wasn't loaded. * Fix unconditional break in deprecated config warning loop that prevented "multi_file" from ever being checked. * Fix HgAdapter.parse_revs error check that silently skipped failures when exec_sync returned nil. * Fix typo: merge_layuots -> merge_layouts in config validation * Fix Diff3Ver type annotation (was incorrectly Diff3Hor).
1 parent 1b778b6 commit 58f14a5

6 files changed

Lines changed: 15 additions & 16 deletions

File tree

lua/diffview/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local Diff2Hor = lazy.access("diffview.scene.layouts.diff_2_hor", "Diff2Hor") --
1818
local Diff2Ver = lazy.access("diffview.scene.layouts.diff_2_ver", "Diff2Ver") ---@type Diff2Ver|LazyModule
1919
local Diff3 = lazy.access("diffview.scene.layouts.diff_3", "Diff3") ---@type Diff3|LazyModule
2020
local Diff3Hor = lazy.access("diffview.scene.layouts.diff_3_hor", "Diff3Hor") ---@type Diff3Hor|LazyModule
21-
local Diff3Ver = lazy.access("diffview.scene.layouts.diff_3_ver", "Diff3Ver") ---@type Diff3Hor|LazyModule
21+
local Diff3Ver = lazy.access("diffview.scene.layouts.diff_3_ver", "Diff3Ver") ---@type Diff3Ver|LazyModule
2222
local Diff3Mixed = lazy.access("diffview.scene.layouts.diff_3_mixed", "Diff3Mixed") ---@type Diff3Mixed|LazyModule
2323
local Diff4 = lazy.access("diffview.scene.layouts.diff_4", "Diff4") ---@type Diff4|LazyModule
2424
local Diff4Mixed = lazy.access("diffview.scene.layouts.diff_4_mixed", "Diff4Mixed") ---@type Diff4Mixed|LazyModule

lua/diffview/config.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ function M.setup(user_config)
590590
for _, name in ipairs(top_options) do
591591
if user_log_options[name] ~= nil then
592592
utils.warn("Global config of 'file_panel.log_options' has been deprecated. See ':h diffview.changelog-271'.")
593+
break
593594
end
594-
break
595595
end
596596

597597
local option_names = {
@@ -640,7 +640,7 @@ function M.setup(user_config)
640640
-- Validate layouts
641641
local view = M._config.view
642642
local standard_layouts = { "diff1_plain", "diff2_horizontal", "diff2_vertical", -1 }
643-
local merge_layuots = {
643+
local merge_layouts = {
644644
"diff1_plain",
645645
"diff3_horizontal",
646646
"diff3_vertical",
@@ -650,7 +650,7 @@ function M.setup(user_config)
650650
}
651651
local valid_layouts = {
652652
default = standard_layouts,
653-
merge_tool = merge_layuots,
653+
merge_tool = merge_layouts,
654654
file_history = standard_layouts,
655655
}
656656

lua/diffview/hl.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ function M.get_style(groups, no_trans)
176176
local res = {}
177177

178178
for _, attr in ipairs(style_attrs) do
179-
if hl[attr] then table.insert(res, attr)
180-
end
179+
if hl[attr] then table.insert(res, attr) end
180+
end
181181

182-
if #res > 0 then
183-
return table.concat(res, ",")
184-
end
182+
if #res > 0 then
183+
return table.concat(res, ",")
185184
end
186185
end
187186
end

lua/diffview/scene/views/diff/file_panel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ end
244244
---Get the file entry under the cursor.
245245
---@return (FileEntry|DirData)?
246246
function FilePanel:get_item_at_cursor()
247-
if not self:is_open() and self:buf_loaded() then return end
247+
if not (self:is_open() and self:buf_loaded()) then return end
248248

249249
local line = api.nvim_win_get_cursor(self.winid)[1]
250250
local comp = self.components.comp:get_comp_on_line(line)
@@ -260,7 +260,7 @@ end
260260
---@return RenderComponent?
261261
function FilePanel:get_dir_at_cursor()
262262
if self.listing_style ~= "tree" then return end
263-
if not self:is_open() and self:buf_loaded() then return end
263+
if not (self:is_open() and self:buf_loaded()) then return end
264264

265265
local line = api.nvim_win_get_cursor(self.winid)[1]
266266
local comp = self.components.comp:get_comp_on_line(line)

lua/diffview/scene/views/file_history/file_history_panel.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ end
319319
---Get the log or file entry under the cursor.
320320
---@return (LogEntry|FileEntry)?
321321
function FileHistoryPanel:get_item_at_cursor()
322-
if not self:is_open() and self:buf_loaded() then return end
322+
if not (self:is_open() and self:buf_loaded()) then return end
323323

324324
local cursor = api.nvim_win_get_cursor(self.winid)
325325
local line = cursor[1]

lua/diffview/vcs/adapters/hg/init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,15 +940,15 @@ function HgAdapter:parse_revs(rev_arg, opt)
940940
right = HgRev(RevType.COMMIT, to)
941941
else
942942
local node, code, stderr = self:exec_sync({"log", "--limit=1", "--template={node}", "--rev=" .. rev_arg}, self.ctx.toplevel)
943-
if code ~= 0 and node then
944-
utils.err(fmt("Failed to parse rev %s: %s", utils.str_quote(rev_arg), stderr))
943+
if not code or code ~= 0 then
944+
utils.err(fmt("Failed to parse rev %s: %s", utils.str_quote(rev_arg), table.concat(stderr or {}, "\n")))
945945
return
946946
end
947947
left = HgRev(RevType.COMMIT, node[1])
948948

949949
node, code, stderr = self:exec_sync({"log", "--limit=1", "--template={node}", "--rev=reverse(" .. rev_arg .. ")"}, self.ctx.toplevel)
950-
if code ~= 0 and node then
951-
utils.err(fmt("Failed to parse rev %s: %s", utils.str_quote(rev_arg), stderr))
950+
if not code or code ~= 0 then
951+
utils.err(fmt("Failed to parse rev %s: %s", utils.str_quote(rev_arg), table.concat(stderr or {}, "\n")))
952952
return
953953
end
954954

0 commit comments

Comments
 (0)