little bit overhaul here and there :))

This commit is contained in:
2026-03-21 15:55:58 +01:00
parent 37e4ba19f8
commit 650ef78405
19 changed files with 601 additions and 428 deletions

View File

@@ -42,8 +42,12 @@ return {
if handle then
while true do
local name = vim.loop.fs_scandir_next(handle)
if not name then break end
if name:match '^page%-%d+%.png$' then page_count = page_count + 1 end
if not name then
break
end
if name:match '^page%-%d+%.png$' then
page_count = page_count + 1
end
end
end
@@ -51,7 +55,9 @@ return {
local function show_page(page_num)
local state = pdf_state[bufnr]
if not state then return end
if not state then
return
end
image.clear()
vim.bo[bufnr].modifiable = true
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { '' })
@@ -68,9 +74,13 @@ return {
local function change_page(delta)
local state = pdf_state[bufnr]
if not state then return end
if not state then
return
end
local new_page = state.current_page + delta
if new_page < 1 or new_page > state.total_pages then return end
if new_page < 1 or new_page > state.total_pages then
return
end
state.current_page = new_page
show_page(new_page)
end
@@ -79,10 +89,18 @@ return {
local map = function(lhs, fn, desc)
vim.keymap.set('n', lhs, fn, { buffer = bufnr, desc = desc })
end
map('j', function() change_page(1) end, 'PDF: next page')
map('k', function() change_page(-1) end, 'PDF: previous page')
map('<Right>', function() change_page(1) end, 'PDF: next page')
map('<Left>', function() change_page(-1) end, 'PDF: previous page')
map('j', function()
change_page(1)
end, 'PDF: next page')
map('k', function()
change_page(-1)
end, 'PDF: previous page')
map('<Right>', function()
change_page(1)
end, 'PDF: next page')
map('<Left>', function()
change_page(-1)
end, 'PDF: previous page')
map('q', '<cmd>bd!<cr>', 'PDF: close')
show_page(1)