Skip to content

Commit

Permalink
Support deleting a word with ctrl + backspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jul 22, 2023
1 parent 940dcdc commit a3b5349
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,27 @@ func (e *Entry) registerShortcut() {
e.selecting = false
moveWord(se)
}
removeWord := func(se fyne.Shortcut) {
row := e.textProvider().row(e.CursorRow)
start, end := getTextWhitespaceRegion(row, e.CursorColumn, true)
if start == -1 || end == -1 {
return
}

e.propertyLock.Lock()
pos := e.cursorTextPos()
e.textProvider().deleteFromTo(start, pos)
e.CursorRow, e.CursorColumn = e.rowColFromTextPos(pos - 1)
e.propertyLock.Unlock()

e.updateTextAndRefresh(e.textProvider().String())
}

e.shortcut.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: fyne.KeyModifierShortcutDefault}, unselectMoveWord)
e.shortcut.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: fyne.KeyModifierShortcutDefault | fyne.KeyModifierShift}, selectMoveWord)
e.shortcut.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: fyne.KeyModifierShortcutDefault}, unselectMoveWord)
e.shortcut.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: fyne.KeyModifierShortcutDefault | fyne.KeyModifierShift}, selectMoveWord)
e.shortcut.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyBackspace, Modifier: fyne.KeyModifierShortcutDefault}, removeWord)
}

func (e *Entry) requestFocus() {
Expand Down

0 comments on commit a3b5349

Please sign in to comment.