-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature: add random verse querying #20
Changes from all commits
2b30c41
a95d35a
deec2a1
826aec0
1cd023a
cf424f3
8f8e26e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ local Utils = require("bible-verse.utils") | |
local Diatheke = require("bible-verse.core.diatheke") | ||
local Ui = require("bible-verse.core.ui") | ||
local Highlight = require("bible-verse.core.highlight") | ||
local random_verse = require("bible-verse.core.random-verse") | ||
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. Rename to |
||
|
||
local M = {} | ||
|
||
|
@@ -110,4 +111,32 @@ function M.query_and_insert() | |
Ui:input(input_conf, on_submit) | ||
end | ||
|
||
--- Returns a random verse | ||
function M.random_query() | ||
return process_query(random_verse(), Config.options.query_format, 0) | ||
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. I'm not sure whether it would be easy to use A user who has set Do you think it would be better to create a separate 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. It's true, I haven't played enough with the config to know about this. I'll let you be the judge, it's probably a good idea :) |
||
end | ||
|
||
--- Query and shows a random verse | ||
function M.query_and_show_random() | ||
local popup_conf = vim.deepcopy(Config.options.ui.popup) | ||
local relative_size = Utils.get_relative_size(popup_conf.relative) | ||
|
||
local popup_width = math.ceil( | ||
math.min( | ||
relative_size.width * popup_conf.size.max_width_percentage, | ||
relative_size.width * popup_conf.size.width_percentage | ||
) | ||
) | ||
local popup_max_height = math.ceil(relative_size.height * popup_conf.size.max_height_percentage) | ||
|
||
local query_result = M.random_query() | ||
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. Need to pass in the |
||
|
||
popup_conf.size.width = popup_width | ||
popup_conf.size.height = Utils.clamp(#query_result, 1, popup_max_height) | ||
|
||
Ui:popup(popup_conf, query_result, function(bufnr, first, last) | ||
Highlight.highlight_buf(bufnr, Config.options.highlighter[Config.options.query_format], first, last) | ||
end) | ||
end | ||
|
||
return M |
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.
Doesn't seem that any of the new commands need to accept >1 arguments 🤔
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.
Indeed, I forgot to change it back