1
0
Эх сурвалжийг харах

Add foundations of find and replace mode

Johan Rong 1 сар өмнө
parent
commit
e01f75be2a

+ 13 - 0
internal/editor/action.go

@@ -113,6 +113,15 @@ func DefaultActionManager() ActionManager {
 					m.BM.PaletteBuffer.Insert('/')
 				},
 			},
+			Action{
+				Binding: "Rune[f]",
+				AskArgs: true,
+				Callback: func(m *Model, args []string) {
+					m.Mode = ModePalette
+					m.BM.PaletteBuffer.Clear()
+					m.BM.PaletteBuffer.Insert('?')
+				},
+			},
 		},
 		Insert:  []Action{
 			Action{
@@ -228,6 +237,10 @@ func DefaultActionManager() ActionManager {
 						m.Mode = ModeNormal
 						m.BM.PaletteBuffer.Clear()
 						m.BM.PaletteBuffer.Paste("moose.error:Unknown command \"" + cmd + "\"")
+					} else if strings.HasPrefix(args[0], "?") {
+						m.Mode = ModeFind
+						m.BM.PaletteBuffer.Clear()
+						m.BM.PaletteBuffer.Paste("moose.error:Find mode unimplemented \"" + cmd + "\"")
 					} else {
 						m.Mode = ModeNormal
 						m.BM.PaletteBuffer.Clear()

+ 2 - 0
internal/editor/keyinput.go

@@ -13,6 +13,8 @@ func (m *Model) HandleKeyInput(ev *tcell.EventKey) {
 				m.BM.PaletteBuffer.Clear()
 				m.BM.PaletteBuffer.Paste("/" + action.Command)
 				return
+			} else if action.Command == "" && action.AskArgs == true {
+				m.Mode = ModePalette
 			}
 
 			action.Callback(m, []string{})

+ 3 - 1
internal/editor/mode.go

@@ -5,13 +5,15 @@ const (
 	ModeNormal Mode = iota
 	ModeWrite
 	ModePalette
+	ModeFind
 )
 
 func (mode Mode) String() string {
 	switch mode {
 	case ModeNormal:  return "normal"
-	case ModeWrite:  return "write"
+	case ModeWrite:   return "write"
 	case ModePalette: return "palette"
+	case ModeFind:    return "find"
 	}
 
 	return "unknown"

+ 4 - 2
internal/editor/render.go

@@ -49,9 +49,11 @@ func (m Model) Render() {
 	modeStr := m.Mode.String()
 	if m.Mode == ModePalette {
 		if strings.HasPrefix(m.BM.PaletteBuffer.String(), "/") {
-			modeStr += " (cmd)"
+			modeStr = "command"
 		} else if strings.HasPrefix(m.BM.PaletteBuffer.String(), "?") {
-			modeStr += " (find)"
+			modeStr = "find"
+		} else if strings.HasPrefix(m.BM.PaletteBuffer.String(), "=") {
+			modeStr = "replace"
 		}
 	}