mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-27 01:10:30 +09:00
Add Ctrl+L jump to line #, JumpLine()
Converts input to integer Returns error if any Only jumps to possible lines Returns number of lines available
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -65,6 +66,7 @@ func InitBindings() {
|
||||
"StartOfLine": (*View).StartOfLine,
|
||||
"EndOfLine": (*View).EndOfLine,
|
||||
"ToggleRuler": (*View).ToggleRuler,
|
||||
"JumpLine": (*View).JumpLine,
|
||||
}
|
||||
|
||||
keys := map[string]tcell.Key{
|
||||
@@ -287,6 +289,7 @@ func DefaultBindings() map[string]string {
|
||||
"CtrlU": "HalfPageUp",
|
||||
"CtrlD": "HalfPageDown",
|
||||
"CtrlR": "ToggleRuler",
|
||||
"CtrlL": "JumpLine",
|
||||
"Delete": "Delete",
|
||||
}
|
||||
}
|
||||
@@ -848,6 +851,30 @@ func (v *View) ToggleRuler() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// JumpLine jumps to a line and moves the view accordingly.
|
||||
func (v *View) JumpLine() bool {
|
||||
// Prompt for line number
|
||||
linestring, canceled := messenger.Prompt("Jump to line # ")
|
||||
if canceled {
|
||||
return true
|
||||
}
|
||||
lineint, err := strconv.Atoi(linestring)
|
||||
lineint = lineint - 1 // fix offset
|
||||
if err != nil {
|
||||
messenger.Error(err) // return errors
|
||||
return true
|
||||
}
|
||||
// Move cursor and view if possible.
|
||||
if lineint < len(v.buf.lines) {
|
||||
v.cursor.x = 0
|
||||
v.cursor.y = lineint
|
||||
v.topline = lineint
|
||||
return false
|
||||
}
|
||||
messenger.Error("Only ", len(v.buf.lines), " lines to jump")
|
||||
return true
|
||||
}
|
||||
|
||||
// None is no action
|
||||
func None() bool {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user