Skip to content

Commit

Permalink
cleanup buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofer committed Nov 24, 2018
1 parent 80f3f37 commit 3cec80e
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions tkg/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import (
"runtime"
)

/*
* Buffer
*/

// Buffer main struct
type Buffer struct {
data []rune
Expand All @@ -36,9 +32,6 @@ type Buffer struct {
modified bool
}

// var RootBuffer *Buffer = nil
// var CurrentBuffer *Buffer = nil

// MarkModified xxx
func (bp *Buffer) MarkModified() {
bp.modified = true
Expand All @@ -63,10 +56,8 @@ func (bp *Buffer) SetText(s string) {
// GetText xxx
func (bp *Buffer) GetText() string {
ret := make([]rune, bp.preLen+bp.postLen)

copy(ret, bp.data)
copy(ret[bp.preLen:], bp.data[bp.postStart():])

return string(ret)
}

Expand All @@ -81,7 +72,7 @@ func (bp *Buffer) logBufferEOB(pt int) {
}
}

// RuneAt finally have a reliable!!
// RuneAt finally reliable!!
func (bp *Buffer) RuneAt(pt int) (rune, error) {
bp.logBufferEOB(pt)
if pt >= len(bp.data) {
Expand Down Expand Up @@ -373,9 +364,6 @@ func (bp *Buffer) LineForPoint(point int) (line int) {
doIncr = true
}
}
// if pt == bp.BufferLen() {
// line--
// }
return
}

Expand Down Expand Up @@ -459,23 +447,19 @@ func (bp *Buffer) SegNext(start, finish, limit int) int {
}
rch, err := bp.RuneAt(scan)
checkErr(err)
//if (bp.b_ebuf <= p || COLS <= c)
if limit <= c {
break
}
//scan += utf8_size(*ptr(bp,scan));
scan++
if rch == '\n' {
break
}
//c += *p == '\t' ? 8 - (c & 7) : 1;
if rch == '\t' {
c += 4 //8 - (c % 7)
} else {
c++
}
}
//(p < bp.b_ebuf ? scan : );
if scan < bp.BufferLen() {
return scan
}
Expand Down Expand Up @@ -526,7 +510,6 @@ func (bp *Buffer) PointDown() {
if l2l < c1 {
npt = l2 + l2l - 1
}
//bp.logBufferEOB(npt)
if npt > bp.PageEnd {
bp.Reframe = true
}
Expand All @@ -539,11 +522,9 @@ func (bp *Buffer) PointNext() {
if bp.postLen <= 1 { //== 0 {
return
}
//log.Printf("PointNext>> preLen %d postLen %d buflen %d\n", bp.preLen, bp.postLen, bp.BufferLen())
bp.data[bp.preLen] = bp.data[bp.postStart()]
bp.preLen++
bp.postLen--
//bp.logBufferEOB(bp.preLen)
}

// PointPrevious move point right one
Expand All @@ -561,29 +542,20 @@ func (bp *Buffer) PointPrevious() {

// UpUp Move up one screen line
func (bp *Buffer) UpUp(pt, cc int) int {
//bp := e.CurrentBuffer
curr := bp.LineStart(pt)
seg := bp.SegStart(curr, pt, cc)
if curr < seg {
pt = bp.SegStart(curr, seg-1, cc)
} else {
pt = bp.SegStart(bp.LineStart(curr-1), curr-1, cc)
}
// x, y := bp.XYForPoint(pt)
// if (y - 1) >= 1 {
// pt = bp.PointForXY(x, y-1)
// }
return pt
}

// DownDown Move down one screen line
func (bp *Buffer) DownDown(pt, cc int) int {
//bp := e.CurrentBuffer
return bp.SegNext(bp.LineStart(pt), pt, cc)
// x, y := bp.XYForPoint(pt)
// npt := bp.PointForXY(x, y+1)
// log.Printf("npt %d pt %d x %d y %d\n", npt, pt, x, y)
// return npt
}

// GetLineStats scan buffer and fill in curline and lastline
Expand Down

0 comments on commit 3cec80e

Please sign in to comment.