]> git.lizzy.rs Git - micro.git/blobdiff - src/messenger.go
Add simple commands
[micro.git] / src / messenger.go
index 0a90ca74b70c1e090b98b031e936f539fcff357b..ca80b1b4278e8fde3c5b31324fc3a4becfe3f634 100644 (file)
@@ -104,6 +104,11 @@ func (m *Messenger) Prompt(prompt string) (string, bool) {
                }
 
                m.HandleEvent(event)
+
+               if m.cursorx < 0 {
+                       // Cancel
+                       m.hasPrompt = false
+               }
        }
 
        m.Reset()
@@ -116,14 +121,18 @@ func (m *Messenger) HandleEvent(event tcell.Event) {
        case *tcell.EventKey:
                switch e.Key() {
                case tcell.KeyLeft:
-                       m.cursorx--
+                       if m.cursorx > 0 {
+                               m.cursorx--
+                       }
                case tcell.KeyRight:
-                       m.cursorx++
+                       if m.cursorx < Count(m.response) {
+                               m.cursorx++
+                       }
                case tcell.KeyBackspace2:
                        if m.cursorx > 0 {
                                m.response = string([]rune(m.response)[:Count(m.response)-1])
-                               m.cursorx--
                        }
+                       m.cursorx--
                case tcell.KeySpace:
                        m.response += " "
                        m.cursorx++
@@ -132,9 +141,6 @@ func (m *Messenger) HandleEvent(event tcell.Event) {
                        m.cursorx++
                }
        }
-       if m.cursorx < 0 {
-               m.cursorx = 0
-       }
 }
 
 // Reset resets the messenger's cursor, message and response