Fix another issue with horizontal scrolling

This commit is contained in:
Zachary Yedidia
2017-03-22 12:28:02 -04:00
parent 04b4dbbfee
commit bea1c5dc28
3 changed files with 8 additions and 37 deletions

View File

@@ -65,7 +65,7 @@ type CellView struct {
lines [][]*Char
}
func (c *CellView) Draw(buf *Buffer, scrollInfo []*scrollInfo, top, height, left, width int) {
func (c *CellView) Draw(buf *Buffer, top, height, left, width int) {
tabsize := int(buf.Settings["tabsize"].(float64))
softwrap := buf.Settings["softwrap"].(bool)
indentchar := []rune(buf.Settings["indentchar"].(string))[0]
@@ -96,9 +96,7 @@ func (c *CellView) Draw(buf *Buffer, scrollInfo []*scrollInfo, top, height, left
lineStr := buf.Line(lineN)
line := []rune(lineStr)
// colN, startOffset, startStyle := visualToCharPos(left, lineN, lineStr, buf, tabsize)
info := scrollInfo[lineN-top]
colN, startOffset, startStyle := info.left, info.offset, info.style
colN, startOffset, startStyle := visualToCharPos(left, lineN, lineStr, buf, tabsize)
if colN < 0 {
colN = len(line)
}

File diff suppressed because one or more lines are too long

View File

@@ -22,12 +22,6 @@ var (
vtScratch = ViewType{false, true}
)
type scrollInfo struct {
left int
offset int
style *tcell.Style
}
// The View struct stores information about a view into a buffer.
// It stores information about the cursor, and the viewport
// that the user sees the buffer from.
@@ -38,8 +32,7 @@ type View struct {
// The topmost line, used for vertical scrolling
Topline int
// The leftmost column, used for horizontal scrolling
leftCol int
hScrollInfo []*scrollInfo
leftCol int
// Specifies whether or not this view holds a help buffer
Type ViewType
@@ -166,23 +159,6 @@ func (v *View) ToggleTabbar() {
}
}
func (v *View) calcHScrollInfo() {
v.hScrollInfo = make([]*scrollInfo, v.Height)
for i := v.Topline; i < v.Topline+v.Height; i++ {
if i >= v.Buf.NumLines {
break
}
left, offset, style := visualToCharPos(v.leftCol, i, v.Buf.Line(i), v.Buf, int(v.Buf.Settings["tabsize"].(float64)))
v.hScrollInfo[i-v.Topline] = &scrollInfo{left, offset, style}
}
}
func (v *View) SetLeftCol(n int) {
v.leftCol = n
v.calcHScrollInfo()
}
func (v *View) paste(clip string) {
leadingWS := GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y))
@@ -251,8 +227,7 @@ func (v *View) OpenBuffer(buf *Buffer) {
v.Buf = buf
v.Cursor = &buf.Cursor
v.Topline = 0
// v.leftCol = 0
v.SetLeftCol(0)
v.leftCol = 0
v.Cursor.ResetSelection()
v.Relocate()
v.Center(false)
@@ -431,13 +406,11 @@ func (v *View) Relocate() bool {
if !v.Buf.Settings["softwrap"].(bool) {
cx := v.Cursor.GetVisualX()
if cx < v.leftCol {
// v.leftCol = cx
v.SetLeftCol(cx)
v.leftCol = cx
ret = true
}
if cx+v.lineNumOffset+1 > v.leftCol+v.Width {
// v.leftCol = cx - v.Width + v.lineNumOffset + 1
v.SetLeftCol(cx - v.Width + v.lineNumOffset + 1)
v.leftCol = cx - v.Width + v.lineNumOffset + 1
ret = true
}
}
@@ -715,7 +688,7 @@ func (v *View) DisplayView() {
left := v.leftCol
top := v.Topline
v.cellview.Draw(v.Buf, v.hScrollInfo, top, height, left, width-v.lineNumOffset)
v.cellview.Draw(v.Buf, top, height, left, width-v.lineNumOffset)
screenX := v.x
realLineN := top - 1