[go: up one dir, main page]

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 ability to seek in the main pane #1327

Closed
1 task done
yousef8192 opened this issue Jul 22, 2024 · 4 comments
Closed
1 task done

Add ability to seek in the main pane #1327

yousef8192 opened this issue Jul 22, 2024 · 4 comments
Labels
feature New feature request

Comments

@yousef8192
Copy link
yousef8192 commented Jul 22, 2024

Please describe the problem you're trying to solve

Most of the file managers has an option to scroll the main pane. By scroll I mean the cursor doesn't move while the pane itself scrolls up/down. It would be really nice If yazi introduces these features for the main panes.

This option in available for the preview pane which is "seek [n]". However it seems that n can't be set to a number below 5 (Maybe this is related to scrolloff? Although I did set scrolloff = 0 and still n can't get below 5) and setting it below 5 has no effect and the seek value is still 5. I opened a separate issue for this please check it out.

Thanks a lot in advance!

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

Described earlier, for any further clarification please do let me know.

Additional context

No response

@yousef8192 yousef8192 added the feature New feature request label Jul 22, 2024
@sxyazi
Copy link
Owner
sxyazi commented Jul 23, 2024

By scroll I mean the cursor doesn't move while the pane itself scrolls up/down

What if the cursor is scrolled to the edge of the page? In that case, doesn't the cursor have to be moved anyway?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jul 23, 2024
@yousef8192
Copy link
Author
yousef8192 commented Jul 23, 2024

By scroll I mean the cursor doesn't move while the pane itself scrolls up/down

What if the cursor is scrolled to the edge of the page? In that case, doesn't the cursor have to be moved anyway?

Yes exactly, the expected behavior is similar to vim's ctrl+e and ctrl+y.
And if scrolloff is set to a value more than 0 then the cursor should start moving according to the scrolloff value.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jul 23, 2024
@yousef8192
Copy link
Author

Something to mention though, it would be nice if the scroll unit is in number of cells and not in terms of the available window space.

@sxyazi
Copy link
Owner
sxyazi commented Sep 30, 2024

I wrote a plugin for it, which basically moves the cursor to the edge of the list to make the list scroll, and then restores the cursor to its original position.

Save it as ~/.config/yazi/plugins/list-seek.yazi/init.lua:

return {
  entry = function(_, args)
    local folder = cx.active.current
    local total = #folder.files - 1
    if total <= 0 then
      return
    end

    local step = tonumber(args[1])
    local start = folder.window[1].idx - 1 + MANAGER.scrolloff
    local end_ = folder.window[#folder.window].idx - 1 - MANAGER.scrolloff

    local bound
    if step > 0 then
      bound = { math.min(total, start + step), math.min(total, end_ + step) }
    else
      bound = { math.max(0, start + step), math.max(0, end_ + step) }
    end

    local target = step > 0 and bound[2] or bound[1]
    local delta = target - folder.cursor
    for _ = 1, math.abs(delta) do
      ya.manager_emit("arrow", { delta > 0 and 1 or -1 })
    end

    ya.manager_emit("arrow", {
      ya.clamp(bound[1], folder.cursor, bound[2]) - target,
    })
  end,
}

And bind these keys to it:

{ on = "<C-j>", run = 'plugin --sync list-seek --args="5"' },
{ on = "<C-k>", run = 'plugin --sync list-seek --args="-5"' },

This plugin also handles scrolloff well, this is what it looks like when I set scrolloff = 0:

screenshot-002046.mp4

@sxyazi sxyazi closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants