Skip to content
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

change highlight of a given node #6

Closed
pwntester opened this issue Dec 16, 2021 · 2 comments
Closed

change highlight of a given node #6

pwntester opened this issue Dec 16, 2021 · 2 comments

Comments

@pwntester
Copy link

Hi,

Im reviewing the code for node and tree but can figure out how to change a node highlight. I want to add a global mapping that search for the node in the tree (✅), goes to the node (✅), and adds a special highlight. I cant figure out this last part, could you please show me an example?

Thanks

@Xuyuanp
Copy link
Owner

Xuyuanp commented Dec 18, 2021

-- consider create a stateful decorator saves the node's path
local MyDefault = {}

function MyDefault:decorator()
    return function(node)
        if self.selected and self.selected == node.abs_path then
            return node.name, '<YourAwesomeHighlight>'
        end
        return decorators.default(node)
    end
end

-- use this decorator replacing the default
tree:setup({
    draw_opts = {
        decorators = {
		    -- ...
            -- decorators.default,
            MyDefault:decorator(),
			-- ...
        },
    },
	-- ...
})

-- setting `selected` when you find your target file
 	MyDefault.selected = node.abs_path
	tree:force_refresh_node(node)

-- dont forget to clear `selected` when you don't need the special highlight

@pwntester
Copy link
Author

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants