added ctrl+V clipboard paste; fixed delete_line semantics

This commit is contained in:
Felix Angell 2018-04-21 17:42:18 +01:00
parent 05f1e4fcd3
commit 44199a632f
8 changed files with 52 additions and 16 deletions

View File

@ -38,17 +38,33 @@ broken change, please:
* try removing the ~/.phi-config folder manually and letting the editor re-load it
# building
You'll need Go with the GOPATH, GOBIN, etc. setup, as well as SDL2, SDL2\_image, and SDL2\_ttf. Here's
an example for Ubuntu:
## requirements
You will need the go compiler installed with the GOPATH/GOBIN/etc setup. In addition
you will need the following libraries:
* sdl2
* sdl2_image
* sdl2_ttf
If you're on Linux, you will need:
* xsel
* xclip
Either works. This is for copying/pasting.
### linux
Here's an example for Ubuntu:
```bash
$ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev
$ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev xclip
$ go get github.com/felixangell/phi-editor
$ cd $GOPATH/src/github.com/felixangell/phi-editor
$ go build
$ ./phi-editor
```
### macOS
If you're on macOS, you can do something like this, using homebrew:
```bash
@ -59,6 +75,7 @@ $ go build
$ ./phi-editor
```
### windows
If you're on windows, you have my condolences.
## configuration

View File

@ -46,6 +46,9 @@ flash = true
[commands.save]
shortcut = "ctrl+s"
[commands.paste]
shortcut = "ctrl+v"
[commands.close_buffer]
shortcut = "ctrl+w"

View File

@ -46,6 +46,9 @@ flash = true
[commands.save]
shortcut = "ctrl+s"
[commands.paste]
shortcut = "ctrl+v"
[commands.close_buffer]
shortcut = "ctrl+w"

View File

@ -46,6 +46,9 @@ flash = true
[commands.save]
shortcut = "super+s"
[commands.paste]
shortcut = "super+v"
[commands.close_buffer]
shortcut = "super+w"

View File

@ -6,4 +6,5 @@ var actions = map[string]BufferAction{
"save": Save,
"delete_line": DeleteLine,
"close_buffer": CloseBuffer,
"paste": Paste,
}

View File

@ -201,6 +201,7 @@ func (b *Buffer) processTextInput(r rune) bool {
actionName, actionExists := cfg.Shortcuts.Controls[string(unicode.ToLower(r))]
if actionExists {
if proc, ok := actions[actionName]; ok {
log.Println("Executing action '" + actionName + "'")
return proc(b)
}
} else {
@ -368,11 +369,17 @@ func (b *Buffer) moveRight() {
func (b *Buffer) moveToEndOfLine() {
lineLen := b.contents[b.curs.y].Len()
if b.curs.x > lineLen {
distToMove := b.curs.x - lineLen
for i := 0; i < distToMove; i++ {
b.moveLeft()
}
} else if b.curs.x < lineLen {
distToMove := lineLen - b.curs.x
for i := 0; i < distToMove; i++ {
b.moveRight()
}
}
}

View File

@ -3,33 +3,21 @@ package gui
import rope "github.com/felixangell/go-rope"
func DeleteLine(b *Buffer) bool {
var prevLineLen = 0
if len(b.contents) > 1 {
prevLineLen = b.contents[b.curs.y].Len()
b.contents = remove(b.contents, b.curs.y)
} else {
// we are on the first line
// and there is nothing else to delete
// so we just clear the line
b.contents[b.curs.y] = new(rope.Rope)
b.moveToEndOfLine()
return true
}
if b.curs.y >= len(b.contents) {
if b.curs.y > 0 {
b.moveUp()
}
return false
}
currLineLen := b.contents[b.curs.y].Len()
if b.curs.x > currLineLen {
amountToMove := prevLineLen - currLineLen
for i := 0; i < amountToMove; i++ {
b.moveLeft()
}
}
b.moveToEndOfLine()
return true
}

View File

@ -4,8 +4,22 @@ import (
"bytes"
"io/ioutil"
"log"
"github.com/atotto/clipboard"
)
func Paste(b *Buffer) bool {
str, err := clipboard.ReadAll()
if err == nil {
b.contents[b.curs.y] = b.contents[b.curs.y].Insert(b.curs.x, str)
b.moveToEndOfLine()
return true
}
log.Println("Failed to paste from clipboard: ", err.Error())
return false
}
// NOTE: all shortcuts return a bool
// this is whether or not they have
// modified the buffer