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

Feature request: "goto -1" to move cursor to end of document #1682

Closed
zoomosis opened this issue May 25, 2020 · 3 comments
Closed

Feature request: "goto -1" to move cursor to end of document #1682

zoomosis opened this issue May 25, 2020 · 3 comments

Comments

@zoomosis
Copy link
Contributor

I would like if micro allowed the command "goto -1" to move the cursor to the end of the document.

"goto -2" would move the cursor to the second-to-last line of the document, etc.

This is consistent with nano and mcedit.

Thanks.

@zoomosis
Copy link
Contributor Author

I notice "goto -1" was effectively also mentioned here: #1082 (comment)

@zoomosis
Copy link
Contributor Author

This patch works for me:

diff --git a/internal/action/command.go b/internal/action/command.go
index cae2b3f..b85117b 100644
--- a/internal/action/command.go
+++ b/internal/action/command.go
@@ -701,6 +701,9 @@ func (h *BufPane) GotoCmd(args []string) {
                                InfoBar.Error(err)
                                return
                        }
+                       if line < 0 {
+                               line = h.Buf.LinesNum() + 1 + line
+                       }
                        line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
                        col = util.Clamp(col-1, 0, util.CharacterCount(h.Buf.LineBytes(line)))
                        h.Cursor.GotoLoc(buffer.Loc{col, line})
@@ -710,6 +713,9 @@ func (h *BufPane) GotoCmd(args []string) {
                                InfoBar.Error(err)
                                return
                        }
+                       if line < 0 {
+                               line = h.Buf.LinesNum() + 1 + line
+                       }
                        line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
                        h.Cursor.GotoLoc(buffer.Loc{0, line})
                }

@semilin
Copy link
Contributor

semilin commented May 29, 2020

Seems like a cool functionality. You should open a PR.

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

3 participants