undo and redo of text, closes #53

This commit is contained in:
Felix Angell 2018-05-16 21:52:17 +01:00
parent ee055fdc67
commit edbe684306
6 changed files with 41 additions and 1 deletions

View File

@ -2,10 +2,11 @@ package cfg
import (
"errors"
"github.com/felixangell/strife"
"log"
"regexp"
"strconv"
"github.com/felixangell/strife"
)
type TomlConfig struct {

View File

@ -62,6 +62,12 @@ draw = true
flash = true
[commands]
[commands.undo]
shortcut = "ctrl+z"
[commands.redo]
shortcut = "ctrl+y"
[commands.save]
shortcut = "ctrl+s"

View File

@ -62,6 +62,12 @@ draw = true
flash = true
[commands]
[commands.undo]
shortcut = "ctrl+z"
[commands.redo]
shortcut = "ctrl+y"
[commands.exit]
shortcut = "ctrl+q"

View File

@ -62,6 +62,12 @@ draw = true
flash = true
[commands]
[commands.undo]
shortcut = "super+z"
[commands.redo]
shortcut = "super+y"
[commands.exit]
shortcut = "super+q"

View File

@ -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),

View File

@ -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)