Added support for Alt+Backspace

This commit is contained in:
Aetnaeus 2020-12-22 16:54:05 -05:00
parent 4610eed249
commit 3a3ac85f52

View File

@ -100,6 +100,32 @@ func (t *typer) start(s string, onStart func()) (int, int, bool) {
t.Scr.Show() t.Scr.Show()
} }
deleteWord := func() {
t.highlight(text, idx, t.backgroundStyle, t.backgroundStyle)
if idx == 0 {
return
}
idx--
for idx > 0 && (text[idx].c == ' ' || text[idx].c == '\n') {
text[idx].style = t.backgroundStyle
idx--
}
for idx > 0 && text[idx].c != ' ' && text[idx].c != '\n' {
text[idx].style = t.backgroundStyle
idx--
}
if text[idx].c == ' ' || text[idx].c == '\n' {
idx++
}
t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle)
}
for { for {
t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle) t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle)
redraw() redraw()
@ -128,49 +154,32 @@ func (t *typer) start(s string, onStart func()) (int, int, bool) {
return -1, -1, false return -1, -1, false
case tcell.KeyCtrlL: case tcell.KeyCtrlL:
t.Scr.Sync() t.Scr.Sync()
case tcell.KeyCtrlH: //Control+backspace case tcell.KeyCtrlH:
t.highlight(text, idx, t.backgroundStyle, t.backgroundStyle) deleteWord()
if idx == 0 {
break
}
idx--
for idx > 0 && (text[idx].c == ' ' || text[idx].c == '\n') {
text[idx].style = t.backgroundStyle
idx--
}
for idx > 0 && text[idx].c != ' ' && text[idx].c != '\n' {
text[idx].style = t.backgroundStyle
idx--
}
if text[idx].c == ' ' || text[idx].c == '\n' {
idx++
}
t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle)
case tcell.KeyBackspace2: case tcell.KeyBackspace2:
t.highlight(text, idx, t.backgroundStyle, t.backgroundStyle) if ev.Modifiers() == tcell.ModAlt {
deleteWord()
} else {
t.highlight(text, idx, t.backgroundStyle, t.backgroundStyle)
if idx == 0 { if idx == 0 {
break break
} }
if idx < len(text) { if idx < len(text) {
text[idx].style = t.backgroundStyle text[idx].style = t.backgroundStyle
} }
idx--
for idx > 0 && text[idx].c == '\n' {
text[idx].style = t.backgroundStyle
idx-- idx--
}
t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle) for idx > 0 && text[idx].c == '\n' {
text[idx].style = t.backgroundStyle
idx--
}
t.highlight(text, idx, t.currentWordStyle, t.nextWordStyle)
}
case tcell.KeyRune: case tcell.KeyRune:
if idx < len(text) { if idx < len(text) {
switch { switch {