From 561108803e54ce8a9572b68a6f389b128a05b248 Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Sun, 6 May 2018 19:58:18 +0100 Subject: [PATCH] added super/ctrl left/right to switch buffers --- cfg/config_any.go | 6 ++++++ cfg/config_linux.go | 6 ++++++ cfg/config_mac.go | 6 ++++++ gui/action.go | 18 ++++++++++++++++++ gui/buffer.go | 34 ++++++++++++++++++++++------------ gui/view.go | 29 ++++++++++++++++++++++++++--- main.go | 10 ++++++++++ 7 files changed, 94 insertions(+), 15 deletions(-) diff --git a/cfg/config_any.go b/cfg/config_any.go index ee70a27..2d30fad 100644 --- a/cfg/config_any.go +++ b/cfg/config_any.go @@ -65,6 +65,12 @@ flash = true [commands.save] shortcut = "ctrl+s" +[commands.focus_left] +shortcut = "ctrl+left" + +[commands.focus_right] +shortcut = "ctrl+right" + [commands.show_palette] shortcut = "ctrl+p" diff --git a/cfg/config_linux.go b/cfg/config_linux.go index 22451f3..dd5fc81 100644 --- a/cfg/config_linux.go +++ b/cfg/config_linux.go @@ -68,6 +68,12 @@ shortcut = "ctrl+q" [commands.show_palette] shortcut = "ctrl+p" +[commands.focus_left] +shortcut = "ctrl+left" + +[commands.focus_right] +shortcut = "ctrl+right" + [commands.save] shortcut = "ctrl+s" diff --git a/cfg/config_mac.go b/cfg/config_mac.go index 0e199dc..548bf68 100644 --- a/cfg/config_mac.go +++ b/cfg/config_mac.go @@ -71,6 +71,12 @@ shortcut = "super+s" [commands.show_palette] shortcut = "super+p" +[commands.focus_left] +shortcut = "super+left" + +[commands.focus_right] +shortcut = "super+right" + [commands.paste] shortcut = "super+v" diff --git a/gui/action.go b/gui/action.go index 3674028..bc1b311 100644 --- a/gui/action.go +++ b/gui/action.go @@ -53,7 +53,25 @@ func GotoLine(v *View, commands []string) bool { return false } +func focusLeft(v *View, commands []string) bool { + if v == nil { + return false + } + v.ChangeFocus(-1) + return false +} + +func focusRight(v *View, commands []string) bool { + if v == nil { + return false + } + v.ChangeFocus(1) + return false +} + var actions = map[string]BufferAction{ + "focus_left": NewBufferAction("focus_left", focusLeft), + "focus_right": NewBufferAction("focus_right", focusRight), "goto": NewBufferAction("goto", GotoLine), "new": NewBufferAction("new", NewFile), "save": NewBufferAction("save", Save), diff --git a/gui/buffer.go b/gui/buffer.go index ca7765c..6da7559 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -360,8 +360,28 @@ func (b *Buffer) processTextInput(r rune) bool { } } - if SUPER_DOWN { - actionName, actionExists := cfg.Shortcuts.Supers[string(unicode.ToLower(r))] + mainSuper := CONTROL_DOWN + if runtime.GOOS == "darwin" { + mainSuper = SUPER_DOWN + } + + if mainSuper { + left := 1073741903 + right := 1073741904 + + // map to left/right/etc. + // FIXME + var key string + switch int(r) { + case left: + key = "left" + case right: + key = "right" + default: + key = string(unicode.ToLower(r)) + } + + actionName, actionExists := cfg.Shortcuts.Supers[key] if actionExists { if action, ok := actions[actionName]; ok { return action.proc(b.parent, []string{}) @@ -750,11 +770,6 @@ func (b *Buffer) processActionKey(key int) bool { case sdl.K_RIGHT: currLineLength := b.contents[b.curs.y].Len() - if CONTROL_DOWN && b.parent != nil { - b.parent.ChangeFocus(1) - break - } - if SUPER_DOWN { for b.curs.x < currLineLength { b.curs.move(1, 0) @@ -784,11 +799,6 @@ func (b *Buffer) processActionKey(key int) bool { b.moveRight() case sdl.K_LEFT: - if CONTROL_DOWN && b.parent != nil { - b.parent.ChangeFocus(-1) - break - } - if SUPER_DOWN { // TODO go to the nearest \t // if no \t (i.e. start of line) go to diff --git a/gui/view.go b/gui/view.go index 8db10a1..975aeac 100644 --- a/gui/view.go +++ b/gui/view.go @@ -5,6 +5,7 @@ import ( "github.com/felixangell/strife" "github.com/veandco/go-sdl2/sdl" "log" + "runtime" "unicode" ) @@ -130,17 +131,39 @@ func (n *View) OnUpdate() bool { dirty := false CONTROL_DOWN = strife.KeyPressed(sdl.K_LCTRL) || strife.KeyPressed(sdl.K_RCTRL) - if CONTROL_DOWN && strife.PollKeys() { + SUPER_DOWN = strife.KeyPressed(sdl.K_LGUI) || strife.KeyPressed(sdl.K_RGUI) + + mainSuper := CONTROL_DOWN + if runtime.GOOS == "darwin" { + mainSuper = SUPER_DOWN + } + + if mainSuper && strife.PollKeys() { r := rune(strife.PopKey()) - actionName, actionExists := cfg.Shortcuts.Controls[string(unicode.ToLower(r))] + left := 1073741904 + right := 1073741903 + + // map to left/right/etc. + // FIXME + var key string + switch int(r) { + case left: + key = "left" + case right: + key = "right" + default: + key = string(unicode.ToLower(r)) + } + + actionName, actionExists := cfg.Shortcuts.Controls[key] if actionExists { if action, ok := actions[actionName]; ok { log.Println("Executing action '" + actionName + "'") return action.proc(n, []string{}) } } else { - log.Println("warning, unimplemented shortcut ctrl +", string(unicode.ToLower(r)), " #", int(r), actionName) + log.Println("warning, unimplemented shortcut ctrl +", string(unicode.ToLower(r)), " #", int(r), actionName, key) } } diff --git a/main.go b/main.go index f6fee36..4589d6c 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "runtime/pprof" "time" "github.com/felixangell/phi/cfg" @@ -67,6 +68,15 @@ func (n *PhiEditor) render(ctx *strife.Renderer) { } func main() { + f, err := os.Create("cpu.prof") + if err != nil { + log.Fatal("could not create CPU profile: ", err) + } + if err := pprof.StartCPUProfile(f); err != nil { + log.Fatal("could not start CPU profile: ", err) + } + defer pprof.StopCPUProfile() + config := cfg.Setup() ww, wh := 1280, 720