Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.TextArea.BackSpaceWord()
case key == KeyBackspace || key == KeyBackspace2 || key == KeyCtrlH:
v.TextArea.BackSpaceChar()
case key == KeyDelete && (mod&ModAlt) != 0:
v.TextArea.DeleteWord()
case key == KeyCtrlD || key == KeyDelete:
v.TextArea.DeleteChar()
case key == KeyArrowDown:
Expand All @@ -40,10 +42,14 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.TextArea.MoveLeftWord()
case key == KeyArrowLeft || key == KeyCtrlB:
v.TextArea.MoveCursorLeft()
case key == KeyCtrlArrowLeft:
v.TextArea.MoveLeftWord()
case (key == KeyArrowRight || ch == 'f') && (mod&ModAlt) != 0:
v.TextArea.MoveRightWord()
case key == KeyArrowRight || key == KeyCtrlF:
v.TextArea.MoveCursorRight()
case key == KeyCtrlArrowRight:
v.TextArea.MoveRightWord()
case key == KeyEnter:
v.TextArea.TypeCharacter("\n")
case key == KeySpace:
Expand All @@ -60,6 +66,10 @@ func SimpleEditor(v *View, key Key, ch rune, mod Modifier) bool {
v.TextArea.GoToEndOfLine()
case key == KeyCtrlW:
v.TextArea.BackSpaceWord()
case key == KeyCtrlBackspace:
v.TextArea.BackSpaceWord()
case key == KeyCtrlDelete:
v.TextArea.DeleteWord()
case key == KeyCtrlY:
v.TextArea.Yank()
case ch != 0:
Expand Down
6 changes: 6 additions & 0 deletions keybinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ const (
KeyShiftArrowDown = Key(tcell.KeyF63)
KeyArrowLeft = Key(tcell.KeyLeft)
KeyArrowRight = Key(tcell.KeyRight)
KeyCtrlArrowLeft = Key(tcell.KeyF52)
KeyCtrlArrowRight = Key(tcell.KeyF53)
KeyCtrlArrowUp = Key(tcell.KeyF54)
KeyCtrlArrowDown = Key(tcell.KeyF55)
KeyCtrlBackspace = Key(tcell.KeyF56)
KeyCtrlDelete = Key(tcell.KeyF57)
)

// Keys combinations.
Expand Down
24 changes: 24 additions & 0 deletions tcell_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,30 @@ func (g *Gui) pollEvent() GocuiEvent {
mod = 0
ch = rune(0)
k = tcell.KeyF63
} else if mod == tcell.ModCtrl && k == tcell.KeyLeft {
mod = 0
ch = rune(0)
k = tcell.KeyF52
} else if mod == tcell.ModCtrl && k == tcell.KeyRight {
mod = 0
ch = rune(0)
k = tcell.KeyF53
} else if mod == tcell.ModCtrl && k == tcell.KeyUp {
mod = 0
ch = rune(0)
k = tcell.KeyF54
} else if mod == tcell.ModCtrl && k == tcell.KeyDown {
mod = 0
ch = rune(0)
k = tcell.KeyF55
} else if mod == tcell.ModCtrl && k == tcell.KeyBackspace {
mod = 0
ch = rune(0)
k = tcell.KeyF56
} else if mod == tcell.ModCtrl && k == tcell.KeyDelete {
mod = 0
ch = rune(0)
k = tcell.KeyF57
} else if mod == tcell.ModCtrl || mod == tcell.ModShift {
// remove Ctrl or Shift if specified
// - shift - will be translated to the final code of rune
Expand Down
25 changes: 21 additions & 4 deletions text_area.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,15 @@ func (self *TextArea) MoveLeftWord() {
}

func (self *TextArea) MoveRightWord() {
self.cursor = self.newCursorForMoveRightWord()
}

func (self *TextArea) newCursorForMoveRightWord() int {
if self.atEnd() {
return
return self.cursor
}
if self.atLineEnd() {
self.cursor++
return
return self.cursor + 1
}

cellCursor := self.contentCursorToCellCursor(self.cursor)
Expand All @@ -364,7 +367,7 @@ func (self *TextArea) MoveRightWord() {
}
}

self.cursor = self.cellCursorToContentCursor(cellCursor)
return self.cellCursorToContentCursor(cellCursor)
}

func (self *TextArea) MoveCursorUp() {
Expand Down Expand Up @@ -559,6 +562,20 @@ func (self *TextArea) BackSpaceWord() {
self.updateCells()
}

func (self *TextArea) DeleteWord() {
newCursor := self.newCursorForMoveRightWord()
if newCursor == self.cursor {
return
}

clipboard := self.content[self.cursor:newCursor]
if clipboard != "\n" {
self.clipboard = clipboard
}
self.content = self.content[:self.cursor] + self.content[newCursor:]
self.updateCells()
}

func (self *TextArea) Yank() {
self.TypeString(self.clipboard)
}
Expand Down