mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 07:15:34 -04:00
implement nano-like page up/page down functionality
This commit is contained in:
parent
eb880d8841
commit
b2dbcb3eab
@ -1669,63 +1669,77 @@ func (h *BufPane) End() bool {
|
|||||||
|
|
||||||
// PageUp scrolls the view up a page
|
// PageUp scrolls the view up a page
|
||||||
func (h *BufPane) PageUp() bool {
|
func (h *BufPane) PageUp() bool {
|
||||||
h.ScrollUp(h.BufView().Height)
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
|
h.ScrollUp(h.BufView().Height - pageOverlap)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// PageDown scrolls the view down a page
|
// PageDown scrolls the view down a page
|
||||||
func (h *BufPane) PageDown() bool {
|
func (h *BufPane) PageDown() bool {
|
||||||
h.ScrollDown(h.BufView().Height)
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
|
h.ScrollDown(h.BufView().Height - pageOverlap)
|
||||||
h.ScrollAdjust()
|
h.ScrollAdjust()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectPageUp selects up one page
|
// SelectPageUp selects up one page
|
||||||
func (h *BufPane) SelectPageUp() bool {
|
func (h *BufPane) SelectPageUp() bool {
|
||||||
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
|
scrollAmount := h.BufView().Height - pageOverlap
|
||||||
if !h.Cursor.HasSelection() {
|
if !h.Cursor.HasSelection() {
|
||||||
h.Cursor.OrigSelection[0] = h.Cursor.Loc
|
h.Cursor.OrigSelection[0] = h.Cursor.Loc
|
||||||
}
|
}
|
||||||
h.MoveCursorUp(h.BufView().Height)
|
h.MoveCursorUp(scrollAmount)
|
||||||
h.Cursor.SelectTo(h.Cursor.Loc)
|
h.Cursor.SelectTo(h.Cursor.Loc)
|
||||||
|
if h.Cursor.Num == 0 {
|
||||||
|
h.ScrollUp(scrollAmount)
|
||||||
|
}
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectPageDown selects down one page
|
// SelectPageDown selects down one page
|
||||||
func (h *BufPane) SelectPageDown() bool {
|
func (h *BufPane) SelectPageDown() bool {
|
||||||
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
|
scrollAmount := h.BufView().Height - pageOverlap
|
||||||
if !h.Cursor.HasSelection() {
|
if !h.Cursor.HasSelection() {
|
||||||
h.Cursor.OrigSelection[0] = h.Cursor.Loc
|
h.Cursor.OrigSelection[0] = h.Cursor.Loc
|
||||||
}
|
}
|
||||||
h.MoveCursorDown(h.BufView().Height)
|
h.MoveCursorDown(scrollAmount)
|
||||||
h.Cursor.SelectTo(h.Cursor.Loc)
|
h.Cursor.SelectTo(h.Cursor.Loc)
|
||||||
|
if h.Cursor.Num == 0 {
|
||||||
|
h.ScrollDown(scrollAmount)
|
||||||
|
h.ScrollAdjust()
|
||||||
|
}
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorPageUp places the cursor a page up
|
// CursorPageUp places the cursor a page up,
|
||||||
|
// moving the view to keep cursor at the same relative position in the view
|
||||||
func (h *BufPane) CursorPageUp() bool {
|
func (h *BufPane) CursorPageUp() bool {
|
||||||
h.Cursor.Deselect(true)
|
h.Cursor.Deselect(true)
|
||||||
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
if h.Cursor.HasSelection() {
|
scrollAmount := h.BufView().Height - pageOverlap
|
||||||
h.Cursor.Loc = h.Cursor.CurSelection[0]
|
h.MoveCursorUp(scrollAmount)
|
||||||
h.Cursor.ResetSelection()
|
if h.Cursor.Num == 0 {
|
||||||
h.Cursor.StoreVisualX()
|
h.ScrollUp(scrollAmount)
|
||||||
}
|
}
|
||||||
h.MoveCursorUp(h.BufView().Height)
|
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// CursorPageDown places the cursor a page up
|
// CursorPageDown places the cursor a page down,
|
||||||
|
// moving the view to keep cursor at the same relative position in the view
|
||||||
func (h *BufPane) CursorPageDown() bool {
|
func (h *BufPane) CursorPageDown() bool {
|
||||||
h.Cursor.Deselect(false)
|
h.Cursor.Deselect(false)
|
||||||
|
pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64))
|
||||||
if h.Cursor.HasSelection() {
|
scrollAmount := h.BufView().Height - pageOverlap
|
||||||
h.Cursor.Loc = h.Cursor.CurSelection[1]
|
h.MoveCursorDown(scrollAmount)
|
||||||
h.Cursor.ResetSelection()
|
if h.Cursor.Num == 0 {
|
||||||
h.Cursor.StoreVisualX()
|
h.ScrollDown(scrollAmount)
|
||||||
|
h.ScrollAdjust()
|
||||||
}
|
}
|
||||||
h.MoveCursorDown(h.BufView().Height)
|
|
||||||
h.Relocate()
|
h.Relocate()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ var optionValidators = map[string]optionValidator{
|
|||||||
"helpsplit": validateChoice,
|
"helpsplit": validateChoice,
|
||||||
"matchbracestyle": validateChoice,
|
"matchbracestyle": validateChoice,
|
||||||
"multiopen": validateChoice,
|
"multiopen": validateChoice,
|
||||||
|
"pageoverlap": validateNonNegativeValue,
|
||||||
"reload": validateChoice,
|
"reload": validateChoice,
|
||||||
"scrollmargin": validateNonNegativeValue,
|
"scrollmargin": validateNonNegativeValue,
|
||||||
"scrollspeed": validateNonNegativeValue,
|
"scrollspeed": validateNonNegativeValue,
|
||||||
@ -76,6 +77,7 @@ var defaultCommonSettings = map[string]interface{}{
|
|||||||
"matchbraceleft": true,
|
"matchbraceleft": true,
|
||||||
"matchbracestyle": "underline",
|
"matchbracestyle": "underline",
|
||||||
"mkparents": false,
|
"mkparents": false,
|
||||||
|
"pageoverlap": float64(2),
|
||||||
"permbackup": false,
|
"permbackup": false,
|
||||||
"readonly": false,
|
"readonly": false,
|
||||||
"reload": "prompt",
|
"reload": "prompt",
|
||||||
|
@ -285,6 +285,13 @@ Here are the available options:
|
|||||||
|
|
||||||
default value: `tab`
|
default value: `tab`
|
||||||
|
|
||||||
|
* `pageoverlap`: the number of lines from the current view to keep in view
|
||||||
|
when paging up or down. If this is set to 2, for instance, and you page
|
||||||
|
down, the last two lines of the previous page will be the first two lines
|
||||||
|
of the next page.
|
||||||
|
|
||||||
|
default value: `2`
|
||||||
|
|
||||||
* `paste`: treat characters sent from the terminal in a single chunk as a paste
|
* `paste`: treat characters sent from the terminal in a single chunk as a paste
|
||||||
event rather than a series of manual key presses. If you are pasting using
|
event rather than a series of manual key presses. If you are pasting using
|
||||||
the terminal keybinding (not `Ctrl-v`, which is micro's default paste
|
the terminal keybinding (not `Ctrl-v`, which is micro's default paste
|
||||||
|
Loading…
Reference in New Issue
Block a user