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