add DeleteWord
This commit is contained in:
parent
9a8da1fa51
commit
b7c5314a2a
|
@ -1,8 +1,6 @@
|
|||
package prompt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
@ -132,7 +130,6 @@ func (d *Document) FindStartOfPreviousWordWithSpace() int {
|
|||
func (d *Document) FindEndOfCurrentWordWithSpace() int {
|
||||
// Reverse the text before the cursor, in order to do an efficient backwards search.
|
||||
x := d.TextAfterCursor()
|
||||
ioutil.WriteFile("/tmp/fff", []byte(fmt.Sprintf("[%s]", x)), 0644)
|
||||
l := len(x)
|
||||
appear := false
|
||||
for i := 0; i < l; i++ {
|
||||
|
|
|
@ -17,6 +17,11 @@ func DeleteChar(buf *Buffer) {
|
|||
buf.Delete(1)
|
||||
}
|
||||
|
||||
// DeleteWord Delete word before the cursor
|
||||
func DeleteWord(buf *Buffer) {
|
||||
buf.DeleteBeforeCursor(len([]rune(buf.Document().TextBeforeCursor())) - buf.Document().FindStartOfPreviousWordWithSpace())
|
||||
}
|
||||
|
||||
// DeleteBeforeChar Go to Backspace
|
||||
func DeleteBeforeChar(buf *Buffer) {
|
||||
buf.DeleteBeforeCursor(1)
|
||||
|
@ -34,7 +39,6 @@ func GoLeftChar(buf *Buffer) {
|
|||
|
||||
// GoRightWord Forward one word
|
||||
func GoRightWord(buf *Buffer) {
|
||||
// fmt.Printf("%#v\n", buf.Document().FindEndOfCurrentWordWithSpace())
|
||||
buf.CursorRight(buf.Document().FindEndOfCurrentWordWithSpace())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue