From edbe6843068918925f131f255ea81bac0a841ce8 Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Wed, 16 May 2018 21:52:17 +0100 Subject: [PATCH] undo and redo of text, closes #53 --- cfg/config.go | 3 ++- cfg/config_any.go | 6 ++++++ cfg/config_linux.go | 6 ++++++ cfg/config_mac.go | 6 ++++++ gui/action.go | 3 +++ gui/shortcuts.go | 18 ++++++++++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) diff --git a/cfg/config.go b/cfg/config.go index 2f29a12..463d04a 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -2,10 +2,11 @@ package cfg import ( "errors" - "github.com/felixangell/strife" "log" "regexp" "strconv" + + "github.com/felixangell/strife" ) type TomlConfig struct { diff --git a/cfg/config_any.go b/cfg/config_any.go index 009fb47..54718ce 100644 --- a/cfg/config_any.go +++ b/cfg/config_any.go @@ -62,6 +62,12 @@ draw = true flash = true [commands] +[commands.undo] +shortcut = "ctrl+z" + +[commands.redo] +shortcut = "ctrl+y" + [commands.save] shortcut = "ctrl+s" diff --git a/cfg/config_linux.go b/cfg/config_linux.go index bf0d315..a364e75 100644 --- a/cfg/config_linux.go +++ b/cfg/config_linux.go @@ -62,6 +62,12 @@ draw = true flash = true [commands] +[commands.undo] +shortcut = "ctrl+z" + +[commands.redo] +shortcut = "ctrl+y" + [commands.exit] shortcut = "ctrl+q" diff --git a/cfg/config_mac.go b/cfg/config_mac.go index dac0020..f8f076d 100644 --- a/cfg/config_mac.go +++ b/cfg/config_mac.go @@ -62,6 +62,12 @@ draw = true flash = true [commands] +[commands.undo] +shortcut = "super+z" + +[commands.redo] +shortcut = "super+y" + [commands.exit] shortcut = "super+q" diff --git a/gui/action.go b/gui/action.go index e0ba03d..36191d5 100644 --- a/gui/action.go +++ b/gui/action.go @@ -126,6 +126,9 @@ var actions = map[string]BufferAction{ "page_down": NewBufferAction("page_down", pageDown), "page_up": NewBufferAction("page_up", pageUp), + "undo": NewBufferAction("undo", Undo), + "redo": NewBufferAction("redo", Redo), + "focus_left": NewBufferAction("focus_left", focusLeft), "focus_right": NewBufferAction("focus_right", focusRight), diff --git a/gui/shortcuts.go b/gui/shortcuts.go index 40d8408..d1f3075 100644 --- a/gui/shortcuts.go +++ b/gui/shortcuts.go @@ -37,6 +37,24 @@ func Paste(v *View, commands []string) bool { return false } +func Undo(v *View, commands []string) bool { + b := v.getCurrentBuff() + if b == nil { + return false + } + b.table.Undo() + return false +} + +func Redo(v *View, commands []string) bool { + b := v.getCurrentBuff() + if b == nil { + return false + } + b.table.Redo() + return false +} + func genFileName(dir, prefix, suffix string) string { randBytes := make([]byte, 16) rand.Read(randBytes)