Skip to content

Commit

Permalink
core/internalcmd: fix crash launching internal cmd async.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigpin committed Feb 22, 2024
1 parent 462c002 commit 642e813
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions core/internalcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,36 @@ func internalCmdFromRowTbFirstPart(erow *ERow, part *toolbarparser.Part) bool {

// erow can be nil (ex: a root toolbar cmd)
func internalExternalCmd(ed *Editor, part *toolbarparser.Part, optERow *ERow) {
// run with busy cursor
node := ed.UI.RootNode
if optERow != nil {
node = optERow.Row

// TODO: remove sync dependency or it will crash
// TODO: also, need active row check here instead of internalcmd2
//// run with busy cursor
//node := ed.UI.RootNode
//if optERow != nil {
// node = optERow.Row
//}
//ed.RunAsyncBusyCursor(node, func() {

if err := internalCmd2(ed, part, optERow); err != nil {
arg0 := part.Args[0].UnquotedString()
ed.Errorf("%s: %w", arg0, err)
}
ed.RunAsyncBusyCursor(node, func() {

if err := internalCmd2(ed, part, optERow); err != nil {
arg0 := part.Args[0].UnquotedString()
ed.Errorf("%s: %w", arg0, err)
}
})
//})
}

func internalCmd2(ed *Editor, part *toolbarparser.Part, optERow *ERow) error {
if optERow == nil {
if ae, ok := ed.ActiveERow(); ok {
optERow = ae
}
}

if handled, err := internalCmd3(ed, part, optERow); err != nil {
if err, handled := internalCmd3(ed, part, optERow); handled {
return err
} else if handled {
return nil
}

// have a plugin handle the cmd
handled := ed.Plugins.RunToolbarCmd(optERow, part)
if handled {
if handled := ed.Plugins.RunToolbarCmd(optERow, part); handled {
return nil
}

Expand All @@ -179,11 +180,11 @@ func internalCmd2(ed *Editor, part *toolbarparser.Part, optERow *ERow) error {
ExternalCmd(erow, part)
return nil
}
func internalCmd3(ed *Editor, part *toolbarparser.Part, optERow *ERow) (bool, error) {
func internalCmd3(ed *Editor, part *toolbarparser.Part, optERow *ERow) (error, bool) {
arg0 := part.Args[0].UnquotedString()
cmd, ok := InternalCmds[arg0]
if !ok {
return false, nil
return nil, false
}
ctx := context.Background()
args := &InternalCmdArgs{cmd, ctx, ed, part, optERow}
Expand All @@ -192,7 +193,7 @@ func internalCmd3(ed *Editor, part *toolbarparser.Part, optERow *ERow) (bool, er
defer cancel()
args.Ctx = ctx2
}
return true, cmd.Fn(args)
return cmd.Fn(args), true
}

//----------
Expand Down

0 comments on commit 642e813

Please sign in to comment.