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

add selections in treeview #732

Closed
wants to merge 13 commits into from

Conversation

takase1121
Copy link
Member

This would allow keyboard navigation (and maybe multiple selection in the future).

Fixes #718

@Guldoman
Copy link
Member

Mmm, this is interesting, but having to double click to open a file doesn't feel right to me (but I'd probably get used to it quickly). This may cause trouble with plugins like ephemeral_tabs (that uses the double click to remove the ephemeral status from a tab), but I'd need to test.

The alternative would be to use single click to open the doc, but avoid giving it the focus, and keeping it on the TreeView. This would also cause problems if what one wanted to do was just selecting an item without opening it.

In the end using double click is probably the best way to allow keyboard navigation.

We should have different styles for hovered and selected, and also apply all the commands to the selected item(s), not the hovered one.

An issue I noticed is that clicking on an item, then immediately clicking another is interpreted as a double click on the second item.

@adamharrison
Copy link
Member

I also like the single-click, but the other IDE I use (Code::Blocks) does use the double-click. If that is the standard, we should support that.

Have this be a configurable option? I know we want to reduce the amount of configurable options, but this is a plugin technically, and so not part of the core config.

Mmm, this is interesting, but having to double click to open a file doesn't feel right to me (but I'd probably get used to it quickly). This may cause trouble with plugins like ephemeral_tabs (that uses the double click to remove the ephemeral status from a tab), but I'd need to test.

Could have it only make things non-emphemeral only if it's already the active document. That strikes me as reasonable, and would work with both styles.

@takase1121
Copy link
Member Author

Mmm, this is interesting, but having to double click to open a file doesn't feel right to me (but I'd probably get used to it quickly).

Same, I'm used to how it is, but I think this is the more common way to implement keyboard access, so if anyone has a better idea to implement we can go with that.

Have this be a configurable option? I know we want to reduce the amount of configurable options, but this is a plugin technically, and so not part of the core config.

I'm not sure what to configure here?

@adamharrison
Copy link
Member

Another option: we could detect where the user clicked; on the text, or only on the row. If on the text, we treat as a double click, otherwise as a single click?

@adamharrison
Copy link
Member

I'm not sure what to configure here?

I meant the single click vs. double click.

@Guldoman
Copy link
Member

Another option: we could detect where the user clicked; on the text, or only on the row. If on the text, we treat as a double click, otherwise as a single click?

Not having a clear interactability indication would be bad UX, tho.

@takase1121
Copy link
Member Author

Another option: we could detect where the user clicked; on the text, or only on the row. If on the text, we treat as a double click, otherwise as a single click?

I think this could cause confusion, since there's 2 different outcomes while doing something quite similiar.

@adamharrison
Copy link
Member

Yeah, that's fair. And I suppose if we don't want to add the single click as a config, I can always add a plugin to modify the plugin.

@takase1121
Copy link
Member Author

Yeah, that's fair. And I suppose if we don't want to add the single click as a config, I can always add a plugin to modify the plugin.

I can try doing that, actually before this I got singleclick working, but it wasn't the behavior I intended so I fixed it.

@takase1121
Copy link
Member Author

Actually, I just tested the thing and it works perfectly with single click. Should I just go with single click instead?

@Guldoman
Copy link
Member

Actually, I just tested the thing and it works perfectly with single click. Should I just go with single click instead?

How does it behave? Do you need to open a file/show subdirs to be able to control via keyboard?

@takase1121
Copy link
Member Author

How does it behave? Do you need to open a file/show subdirs to be able to control via keyboard?

If you don't have any selection, pressing up or down will select the 1st (usually your project folder). After that you can navigate around, and then enter to expand/open files.

@Guldoman
Copy link
Member

Yeah, but my problem with that is having to find an empty space in the TreeView to click, to give it focus. Missing that, you are forced to click a directory (and not a file because it would move the focus to its View).

@Guldoman
Copy link
Member

In the end it's not too bad, as this is adding more controls without removing anything.

If a config option to switch between single and double click is simple to add, it would satisfy both old users that are used to single click, and users that want to use more keyboard navigation.

@Guldoman
Copy link
Member

Also considering that we have commands to move focus from a Node to a neighboring one, the keyboard users wouldn't even need to use the mouse to move to the TreeView.
The problem with those commands is that they ignore locked Nodes, so it wouldn't work right now.
We could either allow moving focus to locked Nodes with our current commands, or add a new one to move focus to the TreeView.

@takase1121
Copy link
Member Author

We could either allow moving focus to locked Nodes with our current commands, or add a new one to move focus to the TreeView.

Is there any problems with the former approach? I think having treeview:focus is way too specific.

If a config option to switch between single and double click is simple to add, it would satisfy both old users that are used to single click, and users that want to use more keyboard navigation.

no problem. I can add clicks_to_open = 2

Yeah, but my problem with that is having to find an empty space in the TreeView to click, to give it focus. Missing that, you are forced to click a directory (and not a file because it would move the focus to its View).

That was an intended feature, but it seems it's not very good. I can try removing it.

@Guldoman
Copy link
Member

We could either allow moving focus to locked Nodes with our current commands, or add a new one to move focus to the TreeView.

Is there any problems with the former approach? I think having treeview:focus is way too specific.

I don't know, I'd need to test.

Yeah, but my problem with that is having to find an empty space in the TreeView to click, to give it focus. Missing that, you are forced to click a directory (and not a file because it would move the focus to its View).

That was an intended feature, but it seems it's not very good. I can try removing it.

I mean, clicking in an empty space is mostly fine (and is an action done in file managers), no need to remove that.

Also, the scroll should follow the selected item.

@takase1121
Copy link
Member Author

Also, the scroll should follow the selected item.

What do you mean by this?

@Guldoman
Copy link
Member

When selecting a file with the arrow keys, if the selected file is outside the visible area, the View should scroll to make it visible.

@takase1121
Copy link
Member Author

When selecting a file with the arrow keys, if the selected file is outside the visible area, the View should scroll to make it visible.

Sorry for the late follow up but I've implemented this. Now selection / moving (with mouse or keyboard) will center the file.

@Guldoman
Copy link
Member

It looks like manually scrolling isn't working anymore.

@takase1121
Copy link
Member Author

It looks like manually scrolling isn't working anymore.

Fixed.

@Guldoman
Copy link
Member

Would it be better to not scroll if the item is already in view? Or at least not scrolling when using the mouse to select the item.
This made me notice that we are updating the hovered item only on mouse move, not on mouse pressed.

Also, do you think we could introduce a visual difference between hovered and selected?

@takase1121
Copy link
Member Author

takase1121 commented Dec 18, 2021

Would it be better to not scroll if the item is already in view? Or at least not scrolling when using the mouse to select the item.
This made me notice that we are updating the hovered item only on mouse move, not on mouse pressed.

Fixed.

Also, do you think we could introduce a visual difference between hovered and selected?

I can do this. I can turn selection alpha to 160, so there's distinction between selection and hovering.

@Guldoman
Copy link
Member

Mmmm, scrolling the selected item to the middle is a bit weird.
I think that it would look better if we either

  • always scroll to the middle if using the keyboard to change the selected item, or
  • scroll just enough to show the selected item

This made me notice that we are updating the hovered item only on mouse move, not on mouse pressed.

What can be done to solve this?

@takase1121
Copy link
Member Author

takase1121 commented Dec 19, 2021

What can be done to solve this?

It's possible to just iterate each_item on mouse click again, but then you'd need to iterate even if cursor in hovered_item already.

Perhaps you can cache hovered_item dimensions and check against that?

EDIT:
I actually ended up checking |scroll.to.y - scroll.y| and call on_mouse_moved appropriately.

@AlexSol
Copy link
Contributor

AlexSol commented Jan 29, 2022

I would like you to add these changes.
behavior VScode and Sublime Text

-- Register the TreeView commands and keymap
command.add(nil, {
  ["treeview:active"] = function()
    if not core.active_view:is(TreeView) then
      core.set_active_view(view)
      if not view.selected_item then
        for it, _, y in view:each_item() do
          view:set_selection(it, y)
          break
        end
      end

    else
      core.set_active_view(core.last_active_view)
    end
  end,
})

command.add(TreeView, {
  ["treeview:narrow"] = function()
    local item = view.selected_item
    if not item then return end
    if item.type == "dir" then
      item.expanded = false
    else
      local last_item
      local last_item_y
      local last_dir = {}
      for it, _, y in view:each_item() do
        if it.type == "dir" and it.expanded then
          last_dir = {it, y}
        end
        if it == view.selected_item then
          if not last_item then
            last_item = it
            last_item_y = y
          end
          break
        end
        last_item = it
        last_item_y = y
      end
      view:set_selection(last_dir[1], last_dir[2])
    end
  end,

  ["treeview:expand"] = function()
    local item = view.selected_item
    if not item then return end
    if item.type == "dir" then
      item.expanded = not item.expanded
    end
  end,
})


keymap.add {
  ["ctrl+0"]      = "treeview:active",
  ["up"]          = "treeview:previous",
  ["down"]        = "treeview:next",
  ["left"]        = "treeview:narrow",
  ["right"]       = "treeview:expand",
}

@jgmdev
Copy link
Member

jgmdev commented Mar 18, 2022

Adapted to new tree view changes and merged also included @AlexSol suggestions so closing this PR.

@jgmdev jgmdev closed this Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete file by pressing button
5 participants