Skip to content

Commit

Permalink
Add delete handler
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Jan 3, 2018
1 parent b488a71 commit 8c0b956
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"math/rand"
"time"

"github.com/esimov/diagram/canvas"
"github.com/esimov/diagram/io"
"github.com/esimov/diagram/ui"
Expand Down
2 changes: 1 addition & 1 deletion ui/editor.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ui

import (
"github.com/jroimartin/gocui"
"strings"
"github.com/jroimartin/gocui"
)

type editor struct {
Expand Down
23 changes: 19 additions & 4 deletions ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package ui
import (
"bytes"
"fmt"
"github.com/esimov/diagram/io"
"github.com/jroimartin/gocui"
"log"
"runtime"
"path/filepath"
"text/tabwriter"
"github.com/esimov/diagram/io"
"github.com/jroimartin/gocui"
)

type Fn func(*gocui.Gui, *gocui.View) error
Expand All @@ -29,13 +30,21 @@ var keyHandlers = &handlers{
{nil, gocui.KeyPgdn, "PgDown", "Jump to the bottom", nil},
{nil, gocui.KeyHome, "Home", "Jump to the start", nil},
{nil, gocui.KeyEnd, "End", "Jump to the end", nil},
*getDeleteHandler(),
{nil, gocui.KeyCtrlX, "Ctrl+x", "Clear editor content", nil},
{nil, gocui.KeyCtrlZ, "Ctrl+z", "Restore editor content", nil},
{nil, gocui.KeyCtrlS, "Ctrl+s", "Save diagram", onSaveDiagram},
{nil, gocui.KeyCtrlD, "Ctrl+d", "Draw diagram", onDrawDiagram},
{nil, gocui.KeyCtrlC, "Ctrl+c", "Quit", onQuit},
}

func getDeleteHandler() *handler {
if runtime.GOOS == "Darwin" {
return &handler{nil, gocui.KeyBackspace2, "Backspace", "Delete diagram", nil}
}
return &handler{nil, gocui.KeyDelete, "Delete", "Delete diagram", nil}
}

func onNextPanel(ui *UI, wrap bool) Fn {
return func(*gocui.Gui, *gocui.View) error {
return ui.nextView(wrap)
Expand Down Expand Up @@ -131,8 +140,14 @@ func (handlers handlers) ApplyKeyBindings(ui *UI, g *gocui.Gui) error {
return err
}

if err := g.SetKeybinding(SAVED_DIAGRAMS_PANEL, gocui.KeyDelete, gocui.ModNone, onDelete); err != nil {
return err
if runtime.GOOS == "darwin" {
if err := g.SetKeybinding(SAVED_DIAGRAMS_PANEL, gocui.KeyBackspace2, gocui.ModNone, onDelete); err != nil {
return err
}
} else {
if err := g.SetKeybinding(SAVED_DIAGRAMS_PANEL, gocui.KeyDelete, gocui.ModNone, onDelete); err != nil {
return err
}
}

return g.SetKeybinding("", gocui.KeyCtrlH, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
Expand Down

0 comments on commit 8c0b956

Please sign in to comment.