]> git.lizzy.rs Git - micro.git/commitdiff
Add the text member back.
authorZachary Yedidia <zyedidia@gmail.com>
Fri, 6 May 2016 23:15:10 +0000 (19:15 -0400)
committerZachary Yedidia <zyedidia@gmail.com>
Fri, 6 May 2016 23:15:10 +0000 (19:15 -0400)
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

cmd/micro/buffer.go
cmd/micro/command.go
cmd/micro/cursor.go
cmd/micro/search.go

index 0a044341a1b5e381ad2939790e0ec00c1ec30394..8fa620f00a6108d3b1d00b03c464927afbdcf146 100644 (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++
index 1e41a7b25b636ad857391140800f479ccdb8f838..e5565a375759b8354445830801efdde246c05312 100644 (file)
@@ -141,7 +141,7 @@ func HandleCommand(input string, view *View) {
 
                found := false
                for {
-                       match := regex.FindStringIndex(view.Buf.String())
+                       match := regex.FindStringIndex(view.Buf.Text)
                        if match == nil {
                                break
                        }
index e48abb7f4124822ce721953fa4d1ecebb8b9cf2e..bba0f2ff9e685f9f397c10da539723512c3b0878 100644 (file)
@@ -102,9 +102,9 @@ func (c *Cursor) DeleteSelection() {
 // GetSelection returns the cursor's selection
 func (c *Cursor) GetSelection() string {
        if c.curSelection[0] > c.curSelection[1] {
-               return c.v.Buf.r.Report(c.curSelection[1]+1, c.curSelection[0]-c.curSelection[1])
+               return string([]rune(c.v.Buf.Text)[c.curSelection[1]:c.curSelection[0]])
        }
-       return c.v.Buf.r.Report(c.curSelection[0]+1, c.curSelection[1]-c.curSelection[0])
+       return string([]rune(c.v.Buf.Text)[c.curSelection[0]:c.curSelection[1]])
 }
 
 // SelectLine selects the current line
index 4253a316026dc3e0c7338a1411c6ece71b6ebc48..041718ace0d4a65b8bec9d5488b97ff2e42e2b08 100644 (file)
@@ -76,7 +76,7 @@ func Search(searchStr string, v *View, down bool) {
        }
        var str string
        var charPos int
-       text := v.Buf.String()
+       text := v.Buf.Text
        if down {
                str = text[searchStart:]
                charPos = searchStart