build: $ ./scripts/bump_gocui.sh

This commit is contained in:
Ryooooooga 2022-09-23 20:01:44 +09:00
parent c8066c54b5
commit 1c82924307
No known key found for this signature in database
GPG key ID: 07CF200DFCC20C25
15 changed files with 231 additions and 40 deletions

View file

@ -49,10 +49,16 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.TextArea.ToggleOverwrite()
case key == KeyCtrlU:
v.TextArea.DeleteToStartOfLine()
case key == KeyCtrlK:
v.TextArea.DeleteToEndOfLine()
case key == KeyCtrlA || key == KeyHome:
v.TextArea.GoToStartOfLine()
case key == KeyCtrlE || key == KeyEnd:
v.TextArea.GoToEndOfLine()
case key == KeyCtrlW:
v.TextArea.BackSpaceWord()
case key == KeyCtrlY:
v.TextArea.Yank()
// TODO: see if we need all three of these conditions: maybe the final one is sufficient
case ch != 0 && mod == 0 && unicode.IsPrint(ch):

View file

@ -1,11 +1,21 @@
package gocui
import "github.com/mattn/go-runewidth"
import (
"strings"
"github.com/mattn/go-runewidth"
)
const (
WHITESPACES = " \t"
WORD_SEPARATORS = "*?_+-.[]~=/&;!#$%^(){}<>"
)
type TextArea struct {
content []rune
cursor int
overwrite bool
clipboard string
}
func (self *TextArea) TypeRune(r rune) {
@ -92,10 +102,25 @@ func (self *TextArea) DeleteToStartOfLine() {
// otherwise, you delete everything up to the start of the current line, without
// deleting the newline character
newlineIndex := self.closestNewlineOnLeft()
self.clipboard = string(self.content[newlineIndex+1 : self.cursor])
self.content = append(self.content[:newlineIndex+1], self.content[self.cursor:]...)
self.cursor = newlineIndex + 1
}
func (self *TextArea) DeleteToEndOfLine() {
if self.atEnd() {
return
}
if self.atLineEnd() {
self.content = append(self.content[:self.cursor], self.content[self.cursor+1:]...)
return
}
lineEndIndex := self.closestNewlineOnRight()
self.clipboard = string(self.content[self.cursor:lineEndIndex])
self.content = append(self.content[:self.cursor], self.content[lineEndIndex:]...)
}
func (self *TextArea) GoToStartOfLine() {
if self.atLineStart() {
return
@ -142,6 +167,43 @@ func (self *TextArea) atLineStart() bool {
(len(self.content) > self.cursor-1 && self.content[self.cursor-1] == '\n')
}
func (self *TextArea) atLineEnd() bool {
return self.atEnd() ||
(len(self.content) > self.cursor && self.content[self.cursor] == '\n')
}
func (self *TextArea) BackSpaceWord() {
if self.cursor == 0 {
return
}
if self.atLineStart() {
self.BackSpaceChar()
return
}
right := self.cursor
for !self.atLineStart() && strings.ContainsRune(WHITESPACES, self.content[self.cursor-1]) {
self.cursor--
}
separators := false
for !self.atLineStart() && strings.ContainsRune(WORD_SEPARATORS, self.content[self.cursor-1]) {
self.cursor--
separators = true
}
if !separators {
for !self.atLineStart() && !strings.ContainsRune(WHITESPACES+WORD_SEPARATORS, self.content[self.cursor-1]) {
self.cursor--
}
}
self.clipboard = string(self.content[self.cursor:right])
self.content = append(self.content[:self.cursor], self.content[right:]...)
}
func (self *TextArea) Yank() {
self.TypeString(self.clipboard)
}
func (self *TextArea) GetCursorXY() (int, int) {
cursorX := 0
cursorY := 0