Add center action to center the view on the cursor
This commit is contained in:
parent
b818011715
commit
dbdfef632e
3 changed files with 21 additions and 1 deletions
|
@ -44,6 +44,25 @@ func PostActionCall(funcName string) bool {
|
|||
return relocate
|
||||
}
|
||||
|
||||
// Center centers the view on the cursor
|
||||
func (v *View) Center(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("Center") {
|
||||
return false
|
||||
}
|
||||
|
||||
v.Topline = v.Cursor.Y - v.height/2
|
||||
if v.Topline < 0 {
|
||||
v.Topline = 0
|
||||
} else if v.Topline+v.height > v.Buf.NumLines {
|
||||
v.Topline = v.Buf.NumLines - v.height
|
||||
}
|
||||
|
||||
if usePlugin {
|
||||
return PostActionCall("Center")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CursorUp moves the cursor up
|
||||
func (v *View) CursorUp(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("CursorUp") {
|
||||
|
|
|
@ -44,6 +44,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
|||
"Find": (*View).Find,
|
||||
"FindNext": (*View).FindNext,
|
||||
"FindPrevious": (*View).FindPrevious,
|
||||
"Center": (*View).Center,
|
||||
"Undo": (*View).Undo,
|
||||
"Redo": (*View).Redo,
|
||||
"Copy": (*View).Copy,
|
||||
|
|
|
@ -249,7 +249,7 @@ func main() {
|
|||
tabs = append(tabs, tab)
|
||||
for _, t := range tabs {
|
||||
for _, v := range t.views {
|
||||
v.Relocate()
|
||||
v.Center(false)
|
||||
if settings["syntax"].(bool) {
|
||||
v.matches = Match(v)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue