Giter Club home page Giter Club logo

Comments (7)

gokcehan avatar gokcehan commented on July 17, 2024

The general gist of this proposal is to make lf more like vim. Currently lf does not have a way to show empty lines as in vim (i.e. lines starting with ~ in vim). Also it is not possible to manually change the position without changing the index of the selected file. These are the limitations that makes it difficult to replicate the behavior of vim. However, I don't see why an exact replication is neccessary anyway. In vim, it is important to be able to change the view since above and below context can be important when viewing a line. This may not have the same analogy when working with files. In lf, page-up and page-down commands are simply used to skip over multiple files quickly. Is there a strong rationale for implementing the exact vim behavior?

As an exception to this, the last part actually make sense to me:

  1. ii. leaves no context like at least 2 lines (think of it as a counterpart of scrolloff)

Currently lf skips over all displayed files and select the first non-displayed file. We may add an offset value to leave some context. It is probably wiser just to simply use the value of scrolloff instead of adding another option value like jumpoff to avoid confusion.

from lf.

dumblob avatar dumblob commented on July 17, 2024

The reason why I would like to see the Vim-like behavior is, that I find it significantly more user-friendly to scroll the whole view (and maintain the cursor position) instead of move the cursor by a larger number of items than 1.

Otherwise this issue wouldn't even appear to me and I wouldn't report it (I really do not care about "being like Vim", but rather about plain usability - I can tell you in general I dislike quite a lot of things about Vim, but this proposal is not one of them 😉).

from lf.

davmaz avatar davmaz commented on July 17, 2024

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

Ok so it started to make sense to me either to keep the position fixed for these movements. However, I have been working on this for a couple of hours and I still couldn't make it work. Index and position logic is tricky to get right in all cases. I lost my interest for now so if anyone wants to work on this, feel free to do so.

Also I realized vim has different behaviors for half page movement and full page movement. Half page movements keeps the position fixed at the beginning whereas full page movement moves it to the scroll offset. Also full page movement moves past the last line. It would be nice if these can be implemented similar to vim. We do not actually need a ~ character for blank lines as I thought before. Those lines are simply left empty.

from lf.

dumblob avatar dumblob commented on July 17, 2024

@gokcehan could you maybe upload the partial work you've done on this feature already (I've found just the master branch)?

You're right with the vim behavior. But maybe for the first version of this feature, we could skip the half page movement as well as the move to the scroll offset.

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

@dumblob below you can find a partial patch though I doubt it would be any useful. Fixing what is not working may require a complete change in the logic. I was working on halfDown and pageDown before I gave up, so I think they are partially working, but up commands are mostly broken. You can also try implementing these in up and down functions for code reusability but it may be much more difficult. You should be testing these with at least two cases, one with lots of files, and another on a shorter list. In the latter case, this should behave identical to the current implementation.

diff --git a/eval.go b/eval.go
index 65078e9..4849260 100644
--- a/eval.go
+++ b/eval.go
@@ -233,11 +233,11 @@ func (e *callExpr) eval(app *app, args []string) {
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "half-up":
-		app.nav.up(e.count * app.nav.height / 2)
+		app.nav.halfUp(e.count * app.nav.height / 2)
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "page-up":
-		app.nav.up(e.count * app.nav.height)
+		app.nav.pageUp(e.count * app.nav.height)
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "down":
@@ -245,11 +245,11 @@ func (e *callExpr) eval(app *app, args []string) {
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "half-down":
-		app.nav.down(e.count * app.nav.height / 2)
+		app.nav.halfDown(e.count * app.nav.height / 2)
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "page-down":
-		app.nav.down(e.count * app.nav.height)
+		app.nav.pageDown(e.count * app.nav.height)
                app.ui.loadFile(app.nav)
                app.ui.loadFileInfo(app.nav)
        case "updir":
diff --git a/nav.go b/nav.go
index 701764c..729fddd 100644
--- a/nav.go
+++ b/nav.go
@@ -435,6 +435,48 @@ func (nav *nav) down(dist int) {
        dir.pos = min(dir.pos, maxind)
 }
 
+func (nav *nav) halfUp(dist int) {
+	dir := nav.currDir()
+	pos := dir.pos
+	nav.up(dist)
+	dir.pos = pos
+	edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
+	dir.pos = min(dir.pos, edge)
+}
+
+func (nav *nav) halfDown(dist int) {
+	dir := nav.currDir()
+	pos := dir.pos
+	nav.down(dist)
+	dir.pos = pos
+
+	edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
+	dir.pos = max(dir.pos, edge)
+
+	maxind := len(dir.files) - 1
+	edge = maxind-dir.ind
+	if edge < nav.height-dir.pos {
+		dir.pos = nav.height - edge - 1
+	}
+}
+
+func (nav *nav) pageUp(dist int) {
+	dir := nav.currDir()
+	pos := dir.pos
+	nav.up(dist)
+	dir.pos = pos
+	edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
+	dir.pos = min(dir.pos, edge)
+}
+
+func (nav *nav) pageDown(dist int) {
+	dir := nav.currDir()
+	pos := dir.pos
+	nav.down(dist)
+	edge := min(min(nav.height/2, gOpts.scrolloff), dir.ind)
+	dir.pos = max(pos, edge)
+}
+
 func (nav *nav) updir() error {
        if len(nav.dirs) <= 1 {
                return nil

from lf.

dumblob avatar dumblob commented on July 17, 2024

I forgot to thank you for the snippet, so please accept my thanks now.

Could we leave this issue open as I forgot to update lf for a while and I'll need to look into this again?

from lf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.