mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Add center action to center the view on the cursor
This commit is contained in:
@@ -44,6 +44,25 @@ func PostActionCall(funcName string) bool {
|
|||||||
return relocate
|
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
|
// CursorUp moves the cursor up
|
||||||
func (v *View) CursorUp(usePlugin bool) bool {
|
func (v *View) CursorUp(usePlugin bool) bool {
|
||||||
if usePlugin && !PreActionCall("CursorUp") {
|
if usePlugin && !PreActionCall("CursorUp") {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ var bindingActions = map[string]func(*View, bool) bool{
|
|||||||
"Find": (*View).Find,
|
"Find": (*View).Find,
|
||||||
"FindNext": (*View).FindNext,
|
"FindNext": (*View).FindNext,
|
||||||
"FindPrevious": (*View).FindPrevious,
|
"FindPrevious": (*View).FindPrevious,
|
||||||
|
"Center": (*View).Center,
|
||||||
"Undo": (*View).Undo,
|
"Undo": (*View).Undo,
|
||||||
"Redo": (*View).Redo,
|
"Redo": (*View).Redo,
|
||||||
"Copy": (*View).Copy,
|
"Copy": (*View).Copy,
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ func main() {
|
|||||||
tabs = append(tabs, tab)
|
tabs = append(tabs, tab)
|
||||||
for _, t := range tabs {
|
for _, t := range tabs {
|
||||||
for _, v := range t.views {
|
for _, v := range t.views {
|
||||||
v.Relocate()
|
v.Center(false)
|
||||||
if settings["syntax"].(bool) {
|
if settings["syntax"].(bool) {
|
||||||
v.matches = Match(v)
|
v.matches = Match(v)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user