Add the text member back.

It seems rope.Report is not acting how I expected it to. I need to look
into this in more detail but for now I am adding the Text variable back
to the Buffer.

Fixes #98
This commit is contained in:
Zachary Yedidia
2016-05-06 19:15:10 -04:00
parent aeff0f8170
commit 8670a03973
4 changed files with 13 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ type Buffer struct {
// Provide efficient and easy access to text and lines so the rope String does not
// need to be constantly recalculated
// These variables are updated in the update() function
Text string
Lines []string
NumLines int
@@ -61,16 +62,17 @@ func (b *Buffer) UpdateRules() {
}
func (b *Buffer) String() string {
text := ""
if b.r.Len() != 0 {
text = b.r.String()
}
return text
return b.Text
}
// Update fetches the string from the rope and updates the `text` and `lines` in the buffer
func (b *Buffer) Update() {
b.Lines = strings.Split(b.String(), "\n")
if b.r.Len() != 0 {
b.Text = b.r.String()
} else {
b.Text = ""
}
b.Lines = strings.Split(b.Text, "\n")
b.NumLines = len(b.Lines)
}
@@ -123,7 +125,7 @@ func (b *Buffer) Remove(start, end int) string {
if end > b.Len() {
end = b.Len()
}
removed := b.r.Report(start+1, end-start)
removed := b.Text[start:end]
// The rope implenentation I am using wants indicies starting at 1 instead of 0
start++
end++