]> git.lizzy.rs Git - micro.git/commitdiff
Add more option support
authorZachary Yedidia <zyedidia@gmail.com>
Thu, 24 Jan 2019 23:25:59 +0000 (18:25 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Wed, 25 Dec 2019 22:05:10 +0000 (17:05 -0500)
cmd/micro/action/actions.go
cmd/micro/action/command.go
cmd/micro/buffer/buffer.go
cmd/micro/buffer/save.go

index d66991e4e01579d15244e0a241484ccff322f82b..f567cb2405b934e7d1b15901a0455d6aa8be8b55 100644 (file)
@@ -471,7 +471,7 @@ func (h *BufPane) IndentSelection() bool {
                                h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY})
                        }
                }
-               h.Cursor.Relocate()
+               h.Buf.RelocateCursors()
 
                return true
        }
@@ -490,7 +490,7 @@ func (h *BufPane) OutdentLine() bool {
                }
                h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y}, buffer.Loc{X: 1, Y: h.Cursor.Y})
        }
-       h.Cursor.Relocate()
+       h.Buf.RelocateCursors()
        return true
 }
 
@@ -515,7 +515,7 @@ func (h *BufPane) OutdentSelection() bool {
                                h.Buf.Remove(buffer.Loc{X: 0, Y: y}, buffer.Loc{X: 1, Y: y})
                        }
                }
-               h.Cursor.Relocate()
+               h.Buf.RelocateCursors()
 
                return true
        }
index 7a34c6deeb855d12b755ce5cd8d7fe1c52bc163d..bcec0ee8227719ff53dbe463ff210741ad044f02 100644 (file)
@@ -587,7 +587,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
                        }
                        if !found || !inRange(locs[0]) || !inRange(locs[1]) {
                                h.Cursor.ResetSelection()
-                               h.Cursor.Relocate()
+                               h.Buf.RelocateCursors()
                                return
                        }
 
@@ -606,7 +606,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
                                        searchLoc.X += utf8.RuneCount(replace)
                                } else if canceled {
                                        h.Cursor.ResetSelection()
-                                       h.Cursor.Relocate()
+                                       h.Buf.RelocateCursors()
                                        return
                                }
                                if searching {
@@ -617,8 +617,7 @@ func (h *BufPane) ReplaceCmd(args []string) {
                doReplacement()
        }
 
-       // TODO: relocate all cursors?
-       h.Cursor.Relocate()
+       h.Buf.RelocateCursors()
 
        if nreplaced > 1 {
                InfoBar.Message("Replaced ", nreplaced, " occurrences of ", search)
index 83b22549d2e53ddf0e89906f2b02992a92601254..9de2b96776fc8c8d3ec51a8fc7249429b49229ed 100644 (file)
@@ -306,10 +306,14 @@ func (b *Buffer) ReOpen() error {
 
        b.ModTime, err = GetModTime(b.Path)
        b.isModified = false
+       b.RelocateCursors()
+       return err
+}
+
+func (b *Buffer) RelocateCursors() {
        for _, c := range b.cursors {
                c.Relocate()
        }
-       return err
 }
 
 // RuneAt returns the rune at a given location in the buffer
index 7337baadd24bdb9358ebccdade6c4de862733412..a6e34f6ecf6bdc989119df77506ee5b1bc0d088f 100644 (file)
@@ -8,6 +8,8 @@ import (
        "os/exec"
        "os/signal"
        "path/filepath"
+       "unicode"
+       "unicode/utf8"
 
        "github.com/zyedidia/micro/cmd/micro/config"
        . "github.com/zyedidia/micro/cmd/micro/util"
@@ -58,19 +60,17 @@ func (b *Buffer) SaveAs(filename string) error {
                return errors.New("Cannot save scratch buffer")
        }
 
-       // TODO: rmtrailingws and updaterules
        b.UpdateRules()
-       // if b.Settings["rmtrailingws"].(bool) {
-       //      for i, l := range b.lines {
-       //              pos := len(bytes.TrimRightFunc(l.data, unicode.IsSpace))
-       //
-       //              if pos < len(l.data) {
-       //                      b.deleteToEnd(Loc{pos, i})
-       //              }
-       //      }
-       //
-       //      b.Cursor.Relocate()
-       // }
+       if b.Settings["rmtrailingws"].(bool) {
+               for i, l := range b.lines {
+                       leftover := utf8.RuneCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
+
+                       linelen := utf8.RuneCount(l.data)
+                       b.Remove(Loc{leftover, i}, Loc{linelen, i})
+               }
+
+               b.RelocateCursors()
+       }
 
        if b.Settings["eofnewline"].(bool) {
                end := b.End()