mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
Add util.Find{FirstEOL LastSOL}; use it
This commit is contained in:
parent
8460fa8b4c
commit
6b7e1296c1
|
@ -2,9 +2,10 @@ package edit
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/xiaq/elvish/util"
|
||||
)
|
||||
|
||||
// Line editor builtins.
|
||||
|
@ -85,21 +86,14 @@ func startCommand(ed *Editor, k Key) *leReturn {
|
|||
}
|
||||
|
||||
func killLineLeft(ed *Editor, k Key) *leReturn {
|
||||
// Find last start of line
|
||||
sol := strings.LastIndex(ed.line[:ed.dot], "\n") + 1
|
||||
sol := util.FindLastSOL(ed.line[:ed.dot])
|
||||
ed.line = ed.line[:sol] + ed.line[ed.dot:]
|
||||
ed.dot = sol
|
||||
return nil
|
||||
}
|
||||
|
||||
func killLineRight(ed *Editor, k Key) *leReturn {
|
||||
// Find next end of line
|
||||
eol := strings.IndexRune(ed.line[ed.dot:], '\n')
|
||||
if eol == -1 {
|
||||
eol = len(ed.line)
|
||||
} else {
|
||||
eol += ed.dot
|
||||
}
|
||||
eol := util.FindFirstEOL(ed.line[ed.dot:]) + ed.dot
|
||||
ed.line = ed.line[:ed.dot] + ed.line[eol:]
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,3 +24,15 @@ func FindContext(text string, pos int) (lineno, colno int, line string) {
|
|||
line = strings.SplitN(text[p-colno:], "\n", 2)[0]
|
||||
return
|
||||
}
|
||||
|
||||
func FindFirstEOL(s string) int {
|
||||
eol := strings.IndexRune(s, '\n')
|
||||
if eol == -1 {
|
||||
eol = len(s)
|
||||
}
|
||||
return eol
|
||||
}
|
||||
|
||||
func FindLastSOL(s string) int {
|
||||
return strings.LastIndex(s, "\n") + 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user