diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index bd1918b7..734539de 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -4,7 +4,6 @@ import ( "flag" "fmt" "io/ioutil" - "log" "os" "sort" @@ -246,6 +245,5 @@ func main() { } else { action.Tabs.HandleEvent(event) } - log.Println("Done event cycle") } } diff --git a/internal/action/actions.go b/internal/action/actions.go index f8b02b66..da802c70 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -46,6 +46,8 @@ func (h *BufPane) MousePress(e *tcell.EventMouse) bool { if b.NumCursors() > 1 { b.ClearCursors() h.Relocate() + h.Cursor = h.Buf.GetActiveCursor() + h.Cursor.Loc = mouseLoc } if time.Since(h.lastClickTime)/time.Millisecond < config.DoubleClickThreshold && (mouseLoc.X == h.lastLoc.X && mouseLoc.Y == h.lastLoc.Y) { if h.doubleClick { @@ -88,6 +90,7 @@ func (h *BufPane) MousePress(e *tcell.EventMouse) bool { } } + h.Cursor.StoreVisualX() h.lastLoc = mouseLoc return false } @@ -269,11 +272,12 @@ func (h *BufPane) SelectWordLeft() bool { // StartOfLine moves the cursor to the start of the line func (h *BufPane) StartOfLine() bool { h.Cursor.Deselect(true) - if h.Cursor.X != 0 { - h.Cursor.Start() - } else { - h.Cursor.StartOfText() - } + h.Cursor.StartOfText() + // if h.Cursor.X != 0 { + // h.Cursor.Start() + // } else { + // h.Cursor.StartOfText() + // } return true } @@ -1189,6 +1193,33 @@ func (h *BufPane) Quit() bool { // QuitAll quits the whole editor; all splits and tabs func (h *BufPane) QuitAll() bool { + anyModified := false + for _, b := range buffer.OpenBuffers { + if b.Modified() { + anyModified = true + break + } + } + + quit := func() { + for _, b := range buffer.OpenBuffers { + b.Close() + } + screen.Screen.Fini() + InfoBar.Close() + os.Exit(0) + } + + if anyModified { + InfoBar.YNPrompt("Quit micro? (all open buffers will be closed without saving)", func(yes, canceled bool) { + if !canceled && yes { + quit() + } + }) + } else { + quit() + } + return false } @@ -1271,16 +1302,34 @@ func (h *BufPane) PreviousSplit() bool { return false } -var curMacro []interface{} -var recordingMacro bool +var curmacro []interface{} +var recording_macro bool // ToggleMacro toggles recording of a macro func (h *BufPane) ToggleMacro() bool { + recording_macro = !recording_macro + if recording_macro { + curmacro = []interface{}{} + InfoBar.Message("Recording") + } else { + InfoBar.Message("Stopped recording") + } return true } // PlayMacro plays back the most recently recorded macro func (h *BufPane) PlayMacro() bool { + if recording_macro { + return false + } + for _, action := range curmacro { + switch t := action.(type) { + case rune: + h.DoRuneInsert(t) + case Event: + h.DoKeyEvent(t) + } + } return true } diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 969ed956..9709fa52 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -289,6 +289,12 @@ func (h *BufPane) DoKeyEvent(e Event) bool { if h.PluginCB("on"+estr) && rel { h.Relocate() } + + if recording_macro { + if estr != "ToggleMacro" && estr != "PlayMacro" { + curmacro = append(curmacro, e) + } + } } return true } @@ -331,6 +337,7 @@ func (h *BufPane) DoRuneInsert(r rune) { for _, c := range cursors { // Insert a character h.Buf.SetCurCursor(c.Num) + h.Cursor = c if !h.PluginCBRune("preRune", r) { continue } @@ -346,6 +353,9 @@ func (h *BufPane) DoRuneInsert(r rune) { } else { h.Buf.Insert(c.Loc, string(r)) } + if recording_macro { + curmacro = append(curmacro, r) + } h.PluginCBRune("onRune", r) } }