mirror of
https://github.com/zyedidia/micro
synced 2024-11-05 17:41:24 +00:00
add actions: CursorToViewTop, CursorToViewCenter, CursorToViewBottom (#3506)
This commit is contained in:
parent
2c6dc32f5d
commit
b3227d6049
3 changed files with 52 additions and 0 deletions
|
@ -160,6 +160,52 @@ func (h *BufPane) Center() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// CursorToViewTop moves the cursor to the top of the view,
|
||||
// offset by scrollmargin unless at the beginning or end of the file
|
||||
func (h *BufPane) CursorToViewTop() bool {
|
||||
v := h.GetView()
|
||||
h.Buf.ClearCursors()
|
||||
scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
|
||||
bStart := display.SLoc{0, 0}
|
||||
if v.StartLine == bStart {
|
||||
scrollmargin = 0
|
||||
}
|
||||
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
|
||||
SLoc: h.Scroll(v.StartLine, scrollmargin),
|
||||
VisualX: 0,
|
||||
}))
|
||||
return true
|
||||
}
|
||||
|
||||
// CursorToViewCenter moves the cursor to the center of the view
|
||||
func (h *BufPane) CursorToViewCenter() bool {
|
||||
v := h.GetView()
|
||||
h.Buf.ClearCursors()
|
||||
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
|
||||
SLoc: h.Scroll(v.StartLine, h.BufView().Height/2),
|
||||
VisualX: 0,
|
||||
}))
|
||||
return true
|
||||
}
|
||||
|
||||
// CursorToViewBottom moves the cursor to the bottom of the view,
|
||||
// offset by scrollmargin unless at the beginning or end of the file
|
||||
func (h *BufPane) CursorToViewBottom() bool {
|
||||
v := h.GetView()
|
||||
h.Buf.ClearCursors()
|
||||
scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
|
||||
bEnd := h.SLocFromLoc(h.Buf.End())
|
||||
lastLine := h.Scroll(v.StartLine, h.BufView().Height-1)
|
||||
if lastLine == bEnd {
|
||||
scrollmargin = 0
|
||||
}
|
||||
h.Cursor.GotoLoc(h.LocFromVLoc(display.VLoc{
|
||||
SLoc: h.Scroll(lastLine, -scrollmargin),
|
||||
VisualX: 0,
|
||||
}))
|
||||
return true
|
||||
}
|
||||
|
||||
// MoveCursorUp is not an action
|
||||
func (h *BufPane) MoveCursorUp(n int) {
|
||||
if !h.Buf.Settings["softwrap"].(bool) {
|
||||
|
|
|
@ -738,6 +738,9 @@ var BufKeyActions = map[string]BufKeyAction{
|
|||
"CursorRight": (*BufPane).CursorRight,
|
||||
"CursorStart": (*BufPane).CursorStart,
|
||||
"CursorEnd": (*BufPane).CursorEnd,
|
||||
"CursorToViewTop": (*BufPane).CursorToViewTop,
|
||||
"CursorToViewCenter": (*BufPane).CursorToViewCenter,
|
||||
"CursorToViewBottom": (*BufPane).CursorToViewBottom,
|
||||
"SelectToStart": (*BufPane).SelectToStart,
|
||||
"SelectToEnd": (*BufPane).SelectToEnd,
|
||||
"SelectUp": (*BufPane).SelectUp,
|
||||
|
|
|
@ -168,6 +168,9 @@ CursorLeft
|
|||
CursorRight
|
||||
CursorStart
|
||||
CursorEnd
|
||||
CursorToViewTop
|
||||
CursorToViewCenter
|
||||
CursorToViewBottom
|
||||
SelectToStart
|
||||
SelectToEnd
|
||||
SelectUp
|
||||
|
|
Loading…
Reference in a new issue