-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathkeyfunc.go
More file actions
46 lines (41 loc) · 1.14 KB
/
keyfunc.go
File metadata and controls
46 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package csvi
import (
"errors"
"io"
"github.com/nyaosorg/go-readline-ny"
)
func cmdEditCellWith(editor func(string, *Application) (string, error), app *Application) string {
if m := app.checkWriteProtect(app.cursorRow); m != "" {
return m
}
cursor := &app.cursorRow.Cell[app.cursorCol]
modifiedBefore := cursor.Modified()
q := cursor.IsQuoted()
app.clearCache()
if text, err := editor(cursor.Text(), app); err == nil {
app.cursorRow.Replace(app.cursorCol, text, app.Mode)
if q {
*cursor = cursor.Quote(app.Mode)
}
} else {
return err.Error()
}
modifiedAfter := cursor.Modified()
app.updateSoftDirty(modifiedBefore, modifiedAfter)
return ""
}
func cmdEditCell(app *Application) string {
return cmdEditCellWith(func(text string, app *Application) (string, error) {
text, err := app.readlineAndValidate("replace cell>", text, app.cursorRow, app.cursorCol)
if errors.Is(err, io.EOF) || errors.Is(err, readline.CtrlC) {
err = errCanceled
}
return text, err
}, app)
}
func cmdEditCellExtEditor(app *Application) string {
if app.ExtEditor == nil {
return cmdEditCell(app)
}
return cmdEditCellWith(app.ExtEditor, app)
}