]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/command.go
Use the new and updated version of tcell
[micro.git] / cmd / micro / command.go
index 58512ed8aa164dc5f817cb17889d74b01a39e13d..1e41a7b25b636ad857391140800f479ccdb8f838 100644 (file)
@@ -103,7 +103,7 @@ func HandleCommand(input string, view *View) {
                        os.Exit(0)
                }
        case "save":
-               Save(view)
+               view.Save()
        case "replace":
                r := regexp.MustCompile(`"[^"\\]*(?:\\.[^"\\]*)*"|[^\s]*`)
                replaceCmd := r.FindAllString(strings.Join(args, " "), -1)
@@ -141,20 +141,41 @@ func HandleCommand(input string, view *View) {
 
                found := false
                for {
-                       match := regex.FindStringIndex(view.buf.text)
+                       match := regex.FindStringIndex(view.Buf.String())
                        if match == nil {
                                break
                        }
                        found = true
                        if strings.Contains(flags, "c") {
-                               //      // The 'check' flag was used
-                               //      if messenger.YesNoPrompt("Perform replacement?") {
-                               //              view.eh.Replace(match[0], match[1], replace)
-                               //      } else {
-                               //              continue
-                               //      }
+                               // The 'check' flag was used
+                               Search(search, view, true)
+                               view.Relocate()
+                               Redraw(view)
+                               choice, canceled := messenger.YesNoPrompt("Perform replacement? (y,n)")
+                               if canceled {
+                                       if view.Cursor.HasSelection() {
+                                               view.Cursor.SetLoc(view.Cursor.curSelection[0])
+                                               view.Cursor.ResetSelection()
+                                       }
+                                       messenger.Reset()
+                                       return
+                               }
+                               if choice {
+                                       view.Cursor.DeleteSelection()
+                                       view.eh.Insert(match[0], replace)
+                                       view.Cursor.ResetSelection()
+                                       messenger.Reset()
+                               } else {
+                                       if view.Cursor.HasSelection() {
+                                               searchStart = view.Cursor.curSelection[1]
+                                       } else {
+                                               searchStart = ToCharPos(view.Cursor.x, view.Cursor.y, view.Buf)
+                                       }
+                                       continue
+                               }
+                       } else {
+                               view.eh.Replace(match[0], match[1], replace)
                        }
-                       view.eh.Replace(match[0], match[1], replace)
                }
                if !found {
                        messenger.Message("Nothing matched " + search)