"strconv"
"strings"
"time"
+ "unicode/utf8"
"github.com/yuin/gopher-lua"
"github.com/zyedidia/clipboard"
// If the user is using spaces instead of tabs and they are deleting
// whitespace at the start of the line, we should delete as if it's a
// tab (tabSize number of spaces)
- lineStart := v.Buf.Line(v.Cursor.Y)[:v.Cursor.X]
+ lineStart := sliceEnd(v.Buf.LineBytes(v.Cursor.Y), v.Cursor.X)
tabSize := int(v.Buf.Settings["tabsize"].(float64))
- if v.Buf.Settings["tabstospaces"].(bool) && IsSpaces(lineStart) && len(lineStart) != 0 && len(lineStart)%tabSize == 0 {
+ if v.Buf.Settings["tabstospaces"].(bool) && IsSpaces(lineStart) && utf8.RuneCount(lineStart) != 0 && utf8.RuneCount(lineStart)%tabSize == 0 {
loc := v.Cursor.Loc
v.Buf.Remove(loc.Move(-tabSize, v.Buf), loc)
} else {
indentrunes := []rune(buf.Settings["indentchar"].(string))
// if empty indentchar settings, use space
if indentrunes == nil || len(indentrunes) == 0 {
- indentrunes = []rune(" ")
+ indentrunes = []rune{' '}
}
indentchar := indentrunes[0]
continue
}
}
- if !IsSpaces(removed) {
+ if !IsSpaces([]byte(removed)) {
messenger.Message("Removed ", removed)
} else {
messenger.Error("The requested plugins do not exist")
if n >= 1000 && loaded >= 0 {
totalLinesNum := int(float64(size) * (float64(n) / float64(loaded)))
newSlice := make([]Line, len(la.lines), totalLinesNum+10000)
- // The copy function is predeclared and works for any slice type.
copy(newSlice, la.lines)
la.lines = newSlice
loaded = -1
// NewlineBelow adds a newline below the given line number
func (la *LineArray) NewlineBelow(y int) {
- la.lines = append(la.lines, Line{[]byte(" "), nil, nil, false})
+ la.lines = append(la.lines, Line{[]byte{' '}, nil, nil, false})
copy(la.lines[y+2:], la.lines[y+1:])
- la.lines[y+1] = Line{[]byte(""), la.lines[y].state, nil, false}
+ la.lines[y+1] = Line{[]byte{}, la.lines[y].state, nil, false}
}
// inserts a byte array at a given location
return runes
}
+func sliceStart(slc []byte, index int) []byte {
+ len := len(slc)
+ i := 0
+ totalSize := 0
+ for totalSize < len {
+ if i >= index {
+ return slc[totalSize:]
+ }
+
+ _, size := utf8.DecodeRune(slc[totalSize:])
+ totalSize += size
+ i++
+ }
+
+ return slc[totalSize:]
+}
+
+func sliceEnd(slc []byte, index int) []byte {
+ len := len(slc)
+ i := 0
+ totalSize := 0
+ for totalSize < len {
+ if i >= index {
+ return slc[:totalSize]
+ }
+
+ _, size := utf8.DecodeRune(slc[totalSize:])
+ totalSize += size
+ i++
+ }
+
+ return slc[:totalSize]
+}
+
// NumOccurrences counts the number of occurrences of a byte in a string
func NumOccurrences(s string, c byte) int {
var n int
}
// IsSpaces checks if a given string is only spaces
-func IsSpaces(str string) bool {
+func IsSpaces(str []byte) bool {
for _, c := range str {
if c != ' ' {
return false