Skip to content

Commit 7d2081d

Browse files
committed
feat(edit): add multi line experimental support
add multi line experimental support Signed-off-by: mritd <mritd@linux.com>
1 parent 10e604e commit 7d2081d

File tree

3 files changed

+2
-62
lines changed

3 files changed

+2
-62
lines changed

consts.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const commitMessageCheckFailedMsg = `
3838
╰──────────────────────────────────────────────────╯`
3939

4040
const editorKey = "//edit"
41+
const newLineKey = `\\n `
4142

4243
const luckyCommitEnv = "MMH_LUCKY_COMMIT"
4344
const strictHostKey = "MMH_STRICT_HOST_KEY"

ui_commit.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,11 @@ func (m commitModel) commit() tea.Msg {
9595
Type: m.views[SELECTOR].(selectorModel).choice,
9696
Scope: m.views[INPUTS].(inputsModel).inputs[0].input.Value(),
9797
Subject: m.views[INPUTS].(inputsModel).inputs[1].input.Value(),
98-
Body: m.views[INPUTS].(inputsModel).inputs[2].input.Value(),
98+
Body: strings.Replace(m.views[INPUTS].(inputsModel).inputs[2].input.Value(), newLineKey, "\n", -1),
9999
Footer: m.views[INPUTS].(inputsModel).inputs[3].input.Value(),
100100
SOB: sob,
101101
}
102102

103-
//if msg.Scope == editorKey {
104-
// msg.Scope = m.views[INPUTS].(inputsModel).editorInputs[0]
105-
//}
106-
//if msg.Subject == editorKey {
107-
// msg.Subject = m.views[INPUTS].(inputsModel).editorInputs[1]
108-
//}
109-
//if msg.Body == editorKey {
110-
// msg.Body = m.views[INPUTS].(inputsModel).editorInputs[2]
111-
//}
112-
//if msg.Footer == editorKey {
113-
// msg.Footer = m.views[INPUTS].(inputsModel).editorInputs[3]
114-
//}
115-
116103
if msg.Body == "" {
117104
msg.Body = msg.Subject
118105
}

ui_commit_inputs.go

-48
Original file line numberDiff line numberDiff line change
@@ -72,46 +72,6 @@ var (
7272
spinnerMetaFrame3 = lipgloss.NewStyle().Foreground(lipgloss.Color("2")).Render("❯")
7373
)
7474

75-
//
76-
//func openEditor() string {
77-
// f, err := ioutil.TempFile("", "gitflow-toolkit")
78-
// if err != nil {
79-
// panic(err)
80-
// }
81-
// defer func() {
82-
// _ = f.Close()
83-
// _ = os.Remove(f.Name())
84-
// }()
85-
//
86-
// // write utf8 bom
87-
// _, err = f.Write([]byte{0xEF, 0xBB, 0xBF})
88-
// if err != nil {
89-
// panic(err)
90-
// }
91-
//
92-
// editor := "vim"
93-
// if runtime.GOOS == "windows" {
94-
// editor = "notepad"
95-
// }
96-
// if v := os.Getenv("VISUAL"); v != "" {
97-
// editor = v
98-
// } else if e := os.Getenv("EDITOR"); e != "" {
99-
// editor = e
100-
// }
101-
//
102-
// cmd := exec.Command(editor, f.Name())
103-
// cmd.Stdin = os.Stdin
104-
// cmd.Stdout = os.Stdout
105-
// cmd.Stderr = os.Stderr
106-
// _ = cmd.Run()
107-
// raw, err := ioutil.ReadFile(f.Name())
108-
// if err != nil {
109-
// panic(err)
110-
// }
111-
//
112-
// return strings.TrimSpace(string(bytes.TrimPrefix(raw, []byte{0xEF, 0xBB, 0xBF})))
113-
//}
114-
11575
type inputWithCheck struct {
11676
input textinput.Model
11777
checker func(s string) error
@@ -121,7 +81,6 @@ type inputsModel struct {
12181
focusIndex int
12282
title string
12383
inputs []inputWithCheck
124-
//editorInputs []string
12584
err error
12685
errSpinner spinner.Model
12786
editMode bool
@@ -154,12 +113,6 @@ func (m inputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
154113
}
155114
return m, func() tea.Msg { return done{nextView: COMMIT} }
156115
}
157-
//if m.inputs[m.focusIndex].input.Value() == editorKey {
158-
// m.editMode = true
159-
// m.editorInputs[m.focusIndex] = openEditor()
160-
// m.editMode = false
161-
// return m, tea.HideCursor
162-
//}
163116
fallthrough
164117
case "tab", "down":
165118
m.focusIndex++
@@ -256,7 +209,6 @@ func (m inputsModel) View() string {
256209
func newInputsModel() inputsModel {
257210
m := inputsModel{
258211
inputs: make([]inputWithCheck, 4),
259-
//editorInputs: make([]string, 4),
260212
}
261213

262214
for i := range m.inputs {

0 commit comments

Comments
 (0)