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

cursor rendering in palette, cursor movement in palette, ++

Johan Rong 1 сар өмнө
parent
commit
81838b7af2

+ 12 - 0
internal/editor/action.go

@@ -202,6 +202,18 @@ func DefaultActionManager() ActionManager {
 					m.BM.PaletteBuffer.Delete()
 				},
 			},
+			Action{
+				Binding: "left",
+				Callback: func(m *Model, args []string) {
+					m.BM.PaletteBuffer.MoveHoriz(-1)	
+				},
+			},
+			Action{
+				Binding: "right",
+				Callback: func(m *Model, args []string) {
+					m.BM.PaletteBuffer.MoveHoriz(1)
+				},
+			},
 			Action{
 				Binding: "enter",
 				Callback: func(m *Model, _ []string) {

+ 1 - 1
internal/editor/mode.go

@@ -11,7 +11,7 @@ func (mode Mode) String() string {
 	switch mode {
 	case ModeNormal:  return "normal"
 	case ModeInsert:  return "insert"
-	case ModePalette: return "command"
+	case ModePalette: return "palette"
 	}
 
 	return "unknown"

+ 9 - 1
internal/editor/model.go

@@ -85,13 +85,21 @@ func (m Model) Render() {
 
 	if m.Mode == ModePalette {
 		m.Screen.PutStrStyled(0, maxHeight + 1, m.BM.PaletteBuffer.String(), m.Style)
+
+		for _, cur := range m.BM.PaletteBuffer.CM.Cursors {
+			line, col := buffer.LineCol(m.BM.PaletteBuffer.Rope, cur.Offset)
+			if line + maxHeight != maxHeight { continue }
+			if col + 1 > sWidth { continue }
+
+			m.Screen.SetContent(col, maxHeight + 1, ' ', nil, m.Style.Reverse(true))
+		}
 	} else if strings.HasPrefix(m.BM.PaletteBuffer.String(), "moose.error:") {
 		m.Screen.PutStrStyled(0, maxHeight + 1, string([]rune(m.BM.PaletteBuffer.String())[12:]), m.Style.Foreground(tcell.ColorRed))
 	}
 }
 
 func (m *Model) HandleKeyInput(ev *tcell.EventKey) {
-	for _, action := range append(m.AM.Common, m.CurrentActionSet()...) {
+	for _, action := range append(m.CurrentActionSet(), m.AM.Common...) {
 		if action.Binding != "" && strings.ToLower(ev.Name()) == strings.ToLower(action.Binding) {
 			if action.Command != "" && action.NeedsArgs == true {
 				m.Mode = ModePalette