Skip to content

Commit

Permalink
Merge pull request #65 from FluxxField/dev
Browse files Browse the repository at this point in the history
fix: changes to hl_group_value and fixed missmatch between all and any
  • Loading branch information
FluxxField authored Apr 6, 2024
2 parents 2f6cd72 + f953b86 commit 418a81c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Example using lazy.nvim

```lua
{
'FlexxField/bionic-reading.nvim',
'FluxxField/bionic-reading.nvim',
config = function()
require('bionic-reading').setup({
-- determines if the file types below will be
Expand All @@ -124,19 +124,16 @@ Example using lazy.nvim
-- the node types you would like to target
-- using treesitter
file_types = {
["text"] = {
"any", -- highlight any node
},
["text"] = "any" -- highlight any node
-- EX: only highlights comments in lua files
["lua"] = {
"comment",
},
},
-- the highlighting styles applied
-- IMPORTANT - if link is present, no other
-- styles are applied
-- the highlighting styles applied as val to nvim_set_hl()
-- Please see :help nvim_set_hl() to see vals that can be passed
hl_group_value = {
link = "Bold",
bold = true
},
-- Flag used to control if the user is prompted
-- if BRToggle is called on a file type that is not
Expand Down
12 changes: 5 additions & 7 deletions lua/bionic-reading/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ local Config = {}
local defaults = {
auto_highlight = true,
file_types = {
['text'] = {
'all'
},
['lua'] = {
'comment',
["text"] = "any",
["lua"] = {
"comment",
},
},
hl_group_value = {
link = "Bold",
bold = true,
},
prompt_user = true,
treesitter = true,
Expand All @@ -47,7 +45,7 @@ function Config._setup(opts)

vim.validate({
auto_highlight = { Config.opts.auto_highlight, "boolean" },
file_types = { Config.opts.file_types, "table" },
file_types = { Config.opts.file_types, { "table", "string" } },
hl_group_value = { Config.opts.hl_group_value, "table" },
prompt_user = { Config.opts.prompt_user, "boolean" },
treesitter = { Config.opts.treesitter, "boolean" },
Expand Down
15 changes: 11 additions & 4 deletions lua/bionic-reading/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ local function _treesitter_highlight(bufnr, line_start, line_end)
end
end

Utils.navigate_tree(root, function(node)
local config_node_types = Config.opts.file_types[vim.bo.filetype]
local filetype_node_types = Config.opts.file_types[vim.bo.filetype]

-- Early return, if node_type is 'any' then highlight to line_end
if type(filetype_node_types) == 'string' and filetype_node_types == 'any' then
_apply_highlighting(bufnr, line_start, line_end);

for _, node_type in ipairs(config_node_types) do
if node_type == 'all' or node_type == node:type() then
return true
end

Utils.navigate_tree(root, function(node)
for _, node_type in ipairs(filetype_node_types) do
if node_type == 'any' or node_type == node:type() then
local row_start = node:range()

_apply_highlighting(bufnr, row_start, row_start + 1)
Expand Down

0 comments on commit 418a81c

Please sign in to comment.