little bit overhaul here and there :))
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user