mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
added super/ctrl left/right to switch buffers; fixes #73
This commit is contained in:
parent
e8d7d947d7
commit
7e4cdf11c5
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
29
gui/view.go
29
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
10
main.go
10
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
|
||||
|
Loading…
Reference in New Issue
Block a user