mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
@@ -27,8 +27,7 @@ type View struct {
|
|||||||
Cursor *Cursor
|
Cursor *Cursor
|
||||||
|
|
||||||
// The topmost line, used for vertical scrolling
|
// The topmost line, used for vertical scrolling
|
||||||
Topline int
|
Topline int
|
||||||
Bottomline int
|
|
||||||
// The leftmost column, used for horizontal scrolling
|
// The leftmost column, used for horizontal scrolling
|
||||||
leftCol int
|
leftCol int
|
||||||
|
|
||||||
@@ -292,7 +291,7 @@ func (v *View) GetSoftWrapLocation(vx, vy int) (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screenX, screenY := 0, v.Topline
|
screenX, screenY := 0, v.Topline
|
||||||
for lineN := v.Topline; lineN < v.Bottomline; lineN++ {
|
for lineN := v.Topline; lineN < v.height; lineN++ {
|
||||||
line := v.Buf.Line(lineN)
|
line := v.Buf.Line(lineN)
|
||||||
|
|
||||||
colN := 0
|
colN := 0
|
||||||
@@ -323,10 +322,41 @@ func (v *View) GetSoftWrapLocation(vx, vy int) (int, int) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *View) Bottomline() int {
|
||||||
|
screenX, screenY := 0, 0
|
||||||
|
numLines := 0
|
||||||
|
for lineN := v.Topline; lineN < v.Topline+v.height; lineN++ {
|
||||||
|
line := v.Buf.Line(lineN)
|
||||||
|
|
||||||
|
colN := 0
|
||||||
|
for _, ch := range line {
|
||||||
|
if screenX >= v.width-v.lineNumOffset {
|
||||||
|
screenX = 0
|
||||||
|
screenY++
|
||||||
|
}
|
||||||
|
|
||||||
|
if ch == '\t' {
|
||||||
|
screenX += int(v.Buf.Settings["tabsize"].(float64)) - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
screenX++
|
||||||
|
colN++
|
||||||
|
}
|
||||||
|
screenX = 0
|
||||||
|
screenY++
|
||||||
|
numLines++
|
||||||
|
|
||||||
|
if screenY >= v.height {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return numLines + v.Topline
|
||||||
|
}
|
||||||
|
|
||||||
// Relocate moves the view window so that the cursor is in view
|
// 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
|
// This is useful if the user has scrolled far away, and then starts typing
|
||||||
func (v *View) Relocate() bool {
|
func (v *View) Relocate() bool {
|
||||||
height := v.Bottomline - v.Topline
|
height := v.Bottomline() - v.Topline
|
||||||
ret := false
|
ret := false
|
||||||
cy := v.Cursor.Y
|
cy := v.Cursor.Y
|
||||||
scrollmargin := int(v.Buf.Settings["scrollmargin"].(float64))
|
scrollmargin := int(v.Buf.Settings["scrollmargin"].(float64))
|
||||||
@@ -911,10 +941,6 @@ func (v *View) DisplayView() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.Bottomline = curLineN
|
|
||||||
if !v.Buf.Settings["softwrap"].(bool) {
|
|
||||||
v.Bottomline++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplayCursor draws the current buffer's cursor to the screen
|
// DisplayCursor draws the current buffer's cursor to the screen
|
||||||
|
|||||||
Reference in New Issue
Block a user