Skip to content

Commit

Permalink
refactor: Find nodes from predicate arg
Browse files Browse the repository at this point in the history
  • Loading branch information
kristijanhusak committed Oct 3, 2023
1 parent 2c128fa commit ff7d4bc
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions lua/orgmode/colors/markup_highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,10 @@ local get_tree = ts_utils.memoize_by_buf_tick(function(bufnr)
return tree[1]:root()
end)

local function get_predicate_nodes(match, n)
local total = n or 2
local counter = 1
local nodes = {}
for _, node in pairs(match) do
nodes[counter] = node
counter = counter + 1
if counter > total then
break
end
end
return unpack(nodes)
end
local function is_valid_markup_range(match, _, source, predicates)
local start_node = match[predicates[2]]
local end_node = match[predicates[3]]

local function is_valid_markup_range(match, _, source, _)
local start_node, end_node = get_predicate_nodes(match)
if not start_node or not end_node then
return
end
Expand All @@ -150,8 +138,10 @@ local function is_valid_markup_range(match, _, source, _)
and end_text:sub(1, 1) ~= ' '
end

local function is_valid_hyperlink_range(match, _, source, _)
local start_node, end_node = get_predicate_nodes(match)
local function is_valid_hyperlink_range(match, _, source, predicates)
local start_node = match[predicates[2]]
local end_node = match[predicates[3]]

if not start_node or not end_node then
return
end
Expand All @@ -171,8 +161,10 @@ local function is_valid_hyperlink_range(match, _, source, _)
return is_valid_start and is_valid_end
end

local function is_valid_latex_range(match, _, source, _)
local start_node_left, start_node_right, end_node = get_predicate_nodes(match, 3)
local function is_valid_latex_range(match, _, source, predicates)
local start_node_left = match[predicates[2]]
local start_node_right = match[predicates[3]]
local end_node = match[predicates[4]]
if not start_node_right or not end_node then
return
end
Expand Down

0 comments on commit ff7d4bc

Please sign in to comment.