simplify scrollmargins

This commit is contained in:
Camille Scholtz
2016-05-20 20:06:01 +02:00
parent 9791f192f8
commit 52f1be5725
3 changed files with 10 additions and 12 deletions

View File

@@ -149,8 +149,7 @@ func HandleCommand(input string, view *View) {
if strings.Contains(flags, "c") {
// The 'check' flag was used
Search(search, view, true)
scrollmargin := int(settings["scrollmargin"].(float64))
view.Relocate(scrollmargin)
view.Relocate()
Redraw(view)
choice, canceled := messenger.YesNoPrompt("Perform replacement? (y,n)")
if canceled {

View File

@@ -121,8 +121,7 @@ func Search(searchStr string, v *View, down bool) {
v.Cursor.curSelection[0] = charPos + match[0]
v.Cursor.curSelection[1] = charPos + match[1]
v.Cursor.x, v.Cursor.y = FromCharPos(charPos+match[1]-1, v.Buf)
scrollmargin := int(settings["scrollmargin"].(float64))
if v.Relocate(scrollmargin) {
if v.Relocate() {
v.matches = Match(v)
}
lastSearch = searchStr

View File

@@ -196,24 +196,25 @@ func (v *View) ReOpen() {
v.Buf = buf
v.matches = Match(v)
v.Cursor.Relocate()
v.Relocate(0)
v.Relocate()
}
}
// Relocate moves the view window so that the cursor is in view
// This is useful if the user has scrolled far away, and then starts typing
func (v *View) Relocate(x int) bool {
func (v *View) Relocate() bool {
ret := false
cy := v.Cursor.y
if cy < v.Topline+x && cy > x-1 {
v.Topline = cy - x
scrollmargin := int(settings["scrollmargin"].(float64))
if cy < v.Topline+scrollmargin && cy > scrollmargin-1 {
v.Topline = cy - scrollmargin
ret = true
} else if cy < v.Topline {
v.Topline = cy
ret = true
}
if cy > v.Topline+v.height-1-x {
v.Topline = cy - v.height + 1 + x
if cy > v.Topline+v.height-1-scrollmargin {
v.Topline = cy - v.height + 1 + scrollmargin
ret = true
}
@@ -381,8 +382,7 @@ func (v *View) HandleEvent(event tcell.Event) {
}
if relocate {
scrollmargin := int(settings["scrollmargin"].(float64))
v.Relocate(scrollmargin)
v.Relocate()
}
if settings["syntax"].(bool) {
v.matches = Match(v)