mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Merge pull request #94 from aerth/line-jump
Add Ctrl+L jump to line #, JumpLine()
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ func InitBindings() {
|
|||||||
"StartOfLine": (*View).StartOfLine,
|
"StartOfLine": (*View).StartOfLine,
|
||||||
"EndOfLine": (*View).EndOfLine,
|
"EndOfLine": (*View).EndOfLine,
|
||||||
"ToggleRuler": (*View).ToggleRuler,
|
"ToggleRuler": (*View).ToggleRuler,
|
||||||
|
"JumpLine": (*View).JumpLine,
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := map[string]tcell.Key{
|
keys := map[string]tcell.Key{
|
||||||
@@ -287,6 +289,7 @@ func DefaultBindings() map[string]string {
|
|||||||
"CtrlU": "HalfPageUp",
|
"CtrlU": "HalfPageUp",
|
||||||
"CtrlD": "HalfPageDown",
|
"CtrlD": "HalfPageDown",
|
||||||
"CtrlR": "ToggleRuler",
|
"CtrlR": "ToggleRuler",
|
||||||
|
"CtrlL": "JumpLine",
|
||||||
"Delete": "Delete",
|
"Delete": "Delete",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -848,6 +851,30 @@ func (v *View) ToggleRuler() bool {
|
|||||||
return false
|
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
|
// None is no action
|
||||||
func None() bool {
|
func None() bool {
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user