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

Improve mouse support #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions filemanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,24 @@ function onCursorUp(view)
selectline_if_tree(view)
end

--scroll cursor when mousewheel is scrolled
function onScrollDown(view)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This & onScrollUp should be pre instead of on. This is because a pre action is triggered before performing the action, while on means it's triggered after the action occurs.

Think of it in the sequence of actions:

  1. You try to scroll down, triggering the preScrollDown, but not actually performing the action.
  2. If preScrollDown has return false in it, the scroll down action is canceled, stopping here. Otherwise, it continues to 3.
  3. The scroll action is actually performed.
  4. The onScrollDown callback is triggered. This doesn't listen for any return's

if view == tree_view then
tree_view.Buf.Cursor:Down()
select_line()
-- not sure if return false is required, I'm new to this
return false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false tells Micro to not actually perform the action, but that doesn't work if it's on.

end
end

function onScrollUp(view)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, pre instead of on

if view == tree_view then
tree_view.Buf.Cursor:Up()
select_line()
return false
end
end

-- Alt-Shift-{
-- Go to target's parent directory (if exists)
function preParagraphPrevious(view)
Expand Down Expand Up @@ -1095,9 +1113,13 @@ function preMousePress(view, event)
local x, y = event:Position()
-- Fixes the y because softwrap messes with it
local new_x, new_y = tree_view:GetMouseClickLocation(x, y)
-- Try to open whatever is at the click's y index
-- Will go into/back dirs based on what's clicked, nothing gets expanded
try_open_at_y(new_y)

--open item if it is selected, otherwise select it.
if tree_view.Buf.Cursor.Loc.Y == new_y then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this chunk really necessary? I feel having to double-click to open is kind of pointless, although I am used to single-click's on my linux DE.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer double click but it also solves the problem that if you use a mouse click to switch to the tree pane it will enter whatever directory the cursor is on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That problem could be solved without requiring double-click, I think?

Possibly by adding in a section to the pre callbacks to check for if view ~= tree_view, getting cursor xy position, then checking if it's anywhere inside the dimensions of the tree. If it is, you could set the current view to the tree_view, then perform the scroll action.

But I'm not exactly sure how you'd get the xy of the tree. Probably possible..

try_open_at_y(new_y)
else
select_line(new_y)
end
-- Don't actually allow the mousepress to trigger, so we avoid highlighting stuff
return false
end
Expand Down