-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add title to footer #11
Open
gerazov
wants to merge
4
commits into
sotte:main
Choose a base branch
from
gerazov:add_title_to_footer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,8 @@ Presenting.start = function(separator) | |
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) | ||
Presenting._state.slides = H.parse_slides(lines, separator) | ||
Presenting._state.n_slides = #Presenting._state.slides | ||
-- extract presentation title from first non-empty line of first slide | ||
Presenting._state.title = H.extract_title(Presenting._state.slides[1]) | ||
|
||
H.create_slide_view(Presenting._state) | ||
end | ||
|
@@ -346,7 +348,21 @@ H.set_slide_content = function(state, slide) | |
) | ||
vim.api.nvim_buf_set_option(state.slide_buf, "modifiable", orig_modifiable) | ||
|
||
local footer_text = "presenting.nvim | " .. state.slide .. "/" .. state.n_slides | ||
-- create slide numbers for footer | ||
local footer_nrs = state.slide .. "/" .. state.n_slides | ||
|
||
local presentation_title = state.title | ||
-- get presentation title with unicode in mind | ||
local title_len = vim.str_utfindex(presentation_title) | ||
|
||
-- if title is too long shorten with elipsis | ||
local width = Presenting.config.options.width | ||
if title_len > width - #footer_nrs - 3 then | ||
presentation_title = presentation_title:sub(1, width - #footer_nrs - 3) .. "..." | ||
end | ||
-- add white spaces between title and slide number | ||
local white_space_fill = string.rep(" ", width - title_len - #footer_nrs) | ||
local footer_text = presentation_title .. white_space_fill .. footer_nrs | ||
vim.api.nvim_buf_set_lines(state.footer_buf, 0, -1, false, { footer_text }) | ||
end | ||
|
||
|
@@ -368,4 +384,21 @@ end | |
---@return boolean | ||
H.in_presenting_mode = function() return Presenting._state ~= nil end | ||
|
||
H.extract_title = function(slide) | ||
local title = "" | ||
for _, line in pairs(vim.split(slide, "\n")) do | ||
-- if line is nonempty set it as title | ||
if line:match("%S") then | ||
title = line | ||
break | ||
end | ||
end | ||
-- strip any trailing whitespace | ||
title = title:gsub("%s+$", "") | ||
-- strip any starting * or # for org and md | ||
title = title:gsub("^%*+%s*", "") | ||
title = title:gsub("^#+%s*", "") | ||
return title | ||
end | ||
|
||
Comment on lines
+387
to
+403
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return Presenting |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always wanted to have this, but I was too lazy. Nice!