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

Rerender crashes when updating Tree’s data. #44

Open
gregorias opened this issue Jun 29, 2024 · 0 comments
Open

Rerender crashes when updating Tree’s data. #44

gregorias opened this issue Jun 29, 2024 · 0 comments

Comments

@gregorias
Copy link

Description

In a tree component, when I set the data property to a signal value and update it, no changes happen.

This behaviour is associated with an error thrown in

The error is: "...ek/.local/share/nvim/lazy/nui.nvim/lua/nui/tree/init.lua:450: attempt to index field 'linenr' (a nil value)" and it comes from Nui’s tree component.

It might be that NuiComponents incorrectly modifies the _ property and removes the linenr property.

Repro

local n = require("nui-components")

local my_menu = function(items_signal)
  return n.tree({
    flex = 1,
    border_label = " Options ",
    data = items_signal.items:map(function(items_val)
			local nodes = {}
			for _, item in pairs(items_val) do
				table.insert(nodes, n.node({ text = item }))
			end
			return nodes
    end),
    prepare_node = function(node, line, component)
      line:append(node.text)
      return line
    end,
  })
end

local my_dashboard = function()
  local renderer = n.create_renderer({
    width = 60,
    height = 12,
  })
  local base_items = { "a", "ab", "abc" }
  local items_signal = n.create_signal({ items = base_items })
  local menu_component = my_menu(items_signal)

  local body = function()
    return n.rows(
      menu_component,
      n.text_input({
        autofocus = true,
        max_lines = 1,
        on_change = function(value)
          local new_items = {}
          for _, item in pairs(items_signal.items:get_value()) do
            if item:find(value) then
              table.insert(new_items, item)
            end
          end
          items_signal.items = new_items
        end,
      })
    )
  end

  renderer:render(body)
end

my_dashboard()

Current Behavior

When writing filter text, the tree component remains unchanged.

Expected Behavior

When writing filter text, the tree component updates with new entries.

NuiComponents version

1.5.2

Neovim version

0.10

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

1 participant