]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/command.go
Add scrollmargin option, rename scrollSpeed to scrollspeed for consistency, make...
[micro.git] / cmd / micro / command.go
index 041ae46fff4b11b195a53c874347e826bd9067e1..00badd61caf9885ca7eff985bb9a625f84880b01 100644 (file)
@@ -46,6 +46,7 @@ func HandleShellCommand(input string, view *View, openTerm bool) {
                }()
        } else {
                screen.Fini()
+               screen = nil
 
                args := strings.Split(input, " ")[1:]
 
@@ -140,20 +141,42 @@ 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)
+                               scrollmargin := int(settings["scrollmargin"].(float64))
+                               view.Relocate(scrollmargin)
+                               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)