"runtime"
"strings"
"time"
- "unicode/utf8"
shellquote "github.com/kballard/go-shellquote"
"github.com/zyedidia/clipboard"
if tabstospaces && tabmovement {
tabsize := int(h.Buf.Settings["tabsize"].(float64))
line := h.Buf.LineBytes(h.Cursor.Y)
- if h.Cursor.X+tabsize < utf8.RuneCount(line) && util.IsSpaces(line[h.Cursor.X:h.Cursor.X+tabsize]) && util.IsBytesWhitespace(line[0:h.Cursor.X]) {
+ if h.Cursor.X+tabsize < util.CharacterCount(line) && util.IsSpaces(line[h.Cursor.X:h.Cursor.X+tabsize]) && util.IsBytesWhitespace(line[0:h.Cursor.X]) {
for i := 0; i < tabsize; i++ {
h.Cursor.Right()
}
// Remove the whitespaces if keepautoindent setting is off
if util.IsSpacesOrTabs(h.Buf.LineBytes(h.Cursor.Y-1)) && !h.Buf.Settings["keepautoindent"].(bool) {
line := h.Buf.LineBytes(h.Cursor.Y - 1)
- h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: utf8.RuneCount(line), Y: h.Cursor.Y - 1})
+ h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: util.CharacterCount(line), Y: h.Cursor.Y - 1})
}
}
h.Cursor.LastVisualX = h.Cursor.GetVisualX()
// tab (tabSize number of spaces)
lineStart := util.SliceStart(h.Buf.LineBytes(h.Cursor.Y), h.Cursor.X)
tabSize := int(h.Buf.Settings["tabsize"].(float64))
- if h.Buf.Settings["tabstospaces"].(bool) && util.IsSpaces(lineStart) && len(lineStart) != 0 && utf8.RuneCount(lineStart)%tabSize == 0 {
+ if h.Buf.Settings["tabstospaces"].(bool) && util.IsSpaces(lineStart) && len(lineStart) != 0 && util.CharacterCount(lineStart)%tabSize == 0 {
loc := h.Cursor.Loc
h.Buf.Remove(loc.Move(-tabSize, h.Buf), loc)
} else {
tripleClick bool
// Last search stores the last successful search for FindNext and FindPrev
- lastSearch string
+ lastSearch string
lastSearchRegex bool
// Should the current multiple cursor selection search based on word or
// based on selection (false for selection, true for word)
"regexp"
"strconv"
"strings"
- "unicode/utf8"
shellquote "github.com/kballard/go-shellquote"
"github.com/zyedidia/micro/v2/internal/buffer"
return
}
line = util.Clamp(line-1, 0, h.Buf.LinesNum()-1)
- col = util.Clamp(col-1, 0, utf8.RuneCount(h.Buf.LineBytes(line)))
+ col = util.Clamp(col-1, 0, util.CharacterCount(h.Buf.LineBytes(line)))
h.Cursor.GotoLoc(buffer.Loc{col, line})
} else {
line, err := strconv.Atoi(args[0])
nreplaced++
} else if !canceled && !yes {
searchLoc = locs[0]
- searchLoc.X += utf8.RuneCount(replace)
+ searchLoc.X += util.CharacterCount(replace)
} else if canceled {
h.Cursor.ResetSelection()
h.Buf.RelocateCursors()
"os"
"sort"
"strings"
- "unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
start := c.Loc
end := c.Loc
if prevSuggestion < len(b.Suggestions) && prevSuggestion >= 0 {
- start = end.Move(-utf8.RuneCountInString(b.Completions[prevSuggestion]), b)
+ start = end.Move(-util.CharacterCountInString(b.Completions[prevSuggestion]), b)
} else {
// end = start.Move(1, b)
}
args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
input := args[len(args)-1]
- return input, c.X - utf8.RuneCount(input)
+ return input, c.X - util.CharacterCount(input)
}
// GetArg gets the most recent word (separated by ' ' only)
if i == len(args)-1 {
break
}
- argstart += utf8.RuneCount(a) + 1
+ argstart += util.CharacterCount(a) + 1
}
return input, argstart
return []string{}, []string{}
}
- inputLen := utf8.RuneCount(input)
+ inputLen := util.CharacterCount(input)
suggestionsSet := make(map[string]struct{})
l := b.LineBytes(i)
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
for _, w := range words {
- if bytes.HasPrefix(w, input) && utf8.RuneCount(w) > inputLen {
+ if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
strw := string(w)
if _, ok := suggestionsSet[strw]; !ok {
suggestionsSet[strw] = struct{}{}
l := b.LineBytes(i)
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
for _, w := range words {
- if bytes.HasPrefix(w, input) && utf8.RuneCount(w) > inputLen {
+ if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
strw := string(w)
if _, ok := suggestionsSet[strw]; !ok {
suggestionsSet[strw] = struct{}{}
"strings"
"sync"
"time"
- "unicode/utf8"
luar "layeh.com/gopher-luar"
if end == len(b.lines) {
b.Insert(
Loc{
- utf8.RuneCount(b.lines[end-1].data),
+ util.CharacterCount(b.lines[end-1].data),
end - 1,
},
"\n"+l,
"math/rand"
"strings"
"testing"
- "unicode/utf8"
"github.com/stretchr/testify/assert"
lua "github.com/yuin/gopher-lua"
- ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/config"
+ ulua "github.com/zyedidia/micro/v2/internal/lua"
+ "github.com/zyedidia/micro/v2/internal/util"
)
type operation struct {
operations := make([]operation, nCursors)
for i := range operations {
startLine := (i * regionSize) + rand.Intn(regionSize-5)
- startColumn := rand.Intn(utf8.RuneCountInString(b.Line(startLine)) + 1)
+ startColumn := rand.Intn(util.CharacterCountInString(b.Line(startLine)) + 1)
endLine := startLine + 1 + rand.Intn(5)
- endColumn := rand.Intn(utf8.RuneCountInString(b.Line(endLine)) + 1)
+ endColumn := rand.Intn(util.CharacterCountInString(b.Line(endLine)) + 1)
operations[i] = operation{
start: Loc{startColumn, startLine},
package buffer
import (
- "unicode/utf8"
-
"github.com/zyedidia/clipboard"
"github.com/zyedidia/micro/v2/internal/util"
)
// InBounds returns whether the given location is a valid character position in the given buffer
func InBounds(pos Loc, buf *Buffer) bool {
- if pos.Y < 0 || pos.Y >= len(buf.lines) || pos.X < 0 || pos.X > utf8.RuneCount(buf.LineBytes(pos.Y)) {
+ if pos.Y < 0 || pos.Y >= len(buf.lines) || pos.X < 0 || pos.X > util.CharacterCount(buf.LineBytes(pos.Y)) {
return false
}
bytes := c.buf.LineBytes(c.Y)
tabsize := int(c.buf.Settings["tabsize"].(float64))
- if c.X > utf8.RuneCount(bytes) {
- c.X = utf8.RuneCount(bytes) - 1
+ if c.X > util.CharacterCount(bytes) {
+ c.X = util.CharacterCount(bytes) - 1
}
return util.StringWidth(bytes, c.X, tabsize)
func (c *Cursor) StartOfText() {
c.Start()
for util.IsWhitespace(c.RuneUnder(c.X)) {
- if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+ if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
break
}
c.Right()
func (c *Cursor) IsStartOfText() bool {
x := 0
for util.IsWhitespace(c.RuneUnder(x)) {
- if x == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+ if x == util.CharacterCount(c.buf.LineBytes(c.Y)) {
break
}
x++
// End moves the cursor to the end of the line it is on
func (c *Cursor) End() {
- c.X = utf8.RuneCount(c.buf.LineBytes(c.Y))
+ c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
c.LastVisualX = c.GetVisualX()
}
bytes := c.buf.LineBytes(proposedY)
c.X = c.GetCharPosInLine(bytes, c.LastVisualX)
- if c.X > utf8.RuneCount(bytes) || (amount < 0 && proposedY == c.Y) {
- c.X = utf8.RuneCount(bytes)
+ if c.X > util.CharacterCount(bytes) || (amount < 0 && proposedY == c.Y) {
+ c.X = util.CharacterCount(bytes)
}
c.Y = proposedY
if c.Loc == c.buf.End() {
return
}
- if c.X < utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+ if c.X < util.CharacterCount(c.buf.LineBytes(c.Y)) {
c.X++
} else {
c.Down()
if c.X < 0 {
c.X = 0
- } else if c.X > utf8.RuneCount(c.buf.LineBytes(c.Y)) {
- c.X = utf8.RuneCount(c.buf.LineBytes(c.Y))
+ } else if c.X > util.CharacterCount(c.buf.LineBytes(c.Y)) {
+ c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
}
}
c.SetSelectionStart(Loc{backward, c.Y})
c.OrigSelection[0] = c.CurSelection[0]
- lineLen := utf8.RuneCount(c.buf.LineBytes(c.Y)) - 1
+ lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
forward++
}
if c.Loc.GreaterThan(c.OrigSelection[1]) {
forward := c.X
- lineLen := utf8.RuneCount(c.buf.LineBytes(c.Y)) - 1
+ lineLen := util.CharacterCount(c.buf.LineBytes(c.Y)) - 1
for forward < lineLen && util.IsWordChar(c.RuneUnder(forward+1)) {
forward++
}
// WordRight moves the cursor one word to the right
func (c *Cursor) WordRight() {
for util.IsWhitespace(c.RuneUnder(c.X)) {
- if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+ if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
c.Right()
return
}
}
c.Right()
for util.IsWordChar(c.RuneUnder(c.X)) {
- if c.X == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
+ if c.X == util.CharacterCount(c.buf.LineBytes(c.Y)) {
return
}
c.Right()
// RuneUnder returns the rune under the given x position
func (c *Cursor) RuneUnder(x int) rune {
line := c.buf.LineBytes(c.Y)
- if len(line) == 0 || x >= utf8.RuneCount(line) {
+ if len(line) == 0 || x >= util.CharacterCount(line) {
return '\n'
} else if x < 0 {
x = 0
import (
"bytes"
"time"
- "unicode/utf8"
dmp "github.com/sergi/go-diff/diffmatchpatch"
"github.com/zyedidia/micro/v2/internal/config"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
+ "github.com/zyedidia/micro/v2/internal/util"
luar "layeh.com/gopher-luar"
)
var textX int
if t.EventType == TextEventInsert {
linecount := eh.buf.LinesNum() - oldl
- textcount := utf8.RuneCount(text)
+ textcount := util.CharacterCount(text)
lastnl = bytes.LastIndex(text, []byte{'\n'})
if lastnl >= 0 {
- endX = utf8.RuneCount(text[lastnl+1:])
+ endX = util.CharacterCount(text[lastnl+1:])
textX = endX
} else {
endX = start.X + textcount
t.Deltas[i].Text = buf.remove(d.Start, d.End)
buf.insert(d.Start, d.Text)
t.Deltas[i].Start = d.Start
- t.Deltas[i].End = Loc{d.Start.X + utf8.RuneCount(d.Text), d.Start.Y}
+ t.Deltas[i].End = Loc{d.Start.X + util.CharacterCount(d.Text), d.Start.Y}
}
for i, j := 0, len(t.Deltas)-1; i < j; i, j = i+1, j-1 {
t.Deltas[i], t.Deltas[j] = t.Deltas[j], t.Deltas[i]
loc := eh.buf.Start()
for _, d := range diff {
if d.Type == dmp.DiffDelete {
- eh.Remove(loc, loc.MoveLA(utf8.RuneCountInString(d.Text), eh.buf.LineArray))
+ eh.Remove(loc, loc.MoveLA(util.CharacterCountInString(d.Text), eh.buf.LineArray))
} else {
if d.Type == dmp.DiffInsert {
eh.Insert(loc, d.Text)
}
- loc = loc.MoveLA(utf8.RuneCountInString(d.Text), eh.buf.LineArray)
+ loc = loc.MoveLA(util.CharacterCountInString(d.Text), eh.buf.LineArray)
}
}
}
"bytes"
"io"
"sync"
- "unicode/utf8"
- "github.com/zyedidia/micro/v2/pkg/highlight"
"github.com/zyedidia/micro/v2/internal/util"
+ "github.com/zyedidia/micro/v2/pkg/highlight"
)
// Finds the byte index of the nth rune in a byte slice
// End returns the location of the last character in the buffer
func (la *LineArray) End() Loc {
numlines := len(la.lines)
- return Loc{utf8.RuneCount(la.lines[numlines-1].data), numlines - 1}
+ return Loc{util.CharacterCount(la.lines[numlines-1].data), numlines - 1}
}
// LineBytes returns line n as an array of bytes
package buffer
import (
- "unicode/utf8"
-
"github.com/zyedidia/micro/v2/internal/util"
)
loc := 0
for i := a.Y + 1; i < b.Y; i++ {
// + 1 for the newline
- loc += utf8.RuneCount(buf.LineBytes(i)) + 1
+ loc += util.CharacterCount(buf.LineBytes(i)) + 1
}
- loc += utf8.RuneCount(buf.LineBytes(a.Y)) - a.X + b.X + 1
+ loc += util.CharacterCount(buf.LineBytes(a.Y)) - a.X + b.X + 1
return loc
}
return Loc{l.X + 1, l.Y}
}
var res Loc
- if l.X < utf8.RuneCount(buf.LineBytes(l.Y)) {
+ if l.X < util.CharacterCount(buf.LineBytes(l.Y)) {
res = Loc{l.X + 1, l.Y}
} else {
res = Loc{0, l.Y + 1}
if l.X > 0 {
res = Loc{l.X - 1, l.Y}
} else {
- res = Loc{utf8.RuneCount(buf.LineBytes(l.Y - 1)), l.Y - 1}
+ res = Loc{util.CharacterCount(buf.LineBytes(l.Y - 1)), l.Y - 1}
}
return res
}
"path/filepath"
"runtime"
"unicode"
- "unicode/utf8"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
b.UpdateRules()
if b.Settings["rmtrailingws"].(bool) {
for i, l := range b.lines {
- leftover := utf8.RuneCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
+ leftover := util.CharacterCount(bytes.TrimRightFunc(l.data, unicode.IsSpace))
- linelen := utf8.RuneCount(l.data)
+ linelen := util.CharacterCount(l.data)
b.Remove(Loc{leftover, i}, Loc{linelen, i})
}
import (
"regexp"
- "unicode/utf8"
"github.com/zyedidia/micro/v2/internal/util"
)
charpos := 0
if i == start.Y && start.Y == end.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
start.X = util.Clamp(start.X, 0, nchars)
end.X = util.Clamp(end.X, 0, nchars)
l = util.SliceStart(l, end.X)
l = util.SliceEnd(l, start.X)
charpos = start.X
} else if i == start.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
start.X = util.Clamp(start.X, 0, nchars)
l = util.SliceEnd(l, start.X)
charpos = start.X
} else if i == end.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
end.X = util.Clamp(end.X, 0, nchars)
l = util.SliceStart(l, end.X)
}
charpos := 0
if i == start.Y && start.Y == end.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
start.X = util.Clamp(start.X, 0, nchars)
end.X = util.Clamp(end.X, 0, nchars)
l = util.SliceStart(l, end.X)
l = util.SliceEnd(l, start.X)
charpos = start.X
} else if i == start.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
start.X = util.Clamp(start.X, 0, nchars)
l = util.SliceEnd(l, start.X)
charpos = start.X
} else if i == end.Y {
- nchars := utf8.RuneCount(l)
+ nchars := util.CharacterCount(l)
end.X = util.Clamp(end.X, 0, nchars)
l = util.SliceStart(l, end.X)
}
result = search.Expand(result, replace, in, submatches)
}
found++
- netrunes += utf8.RuneCount(in) - utf8.RuneCount(result)
+ netrunes += util.CharacterCount(in) - util.CharacterCount(result)
return result
})
from := Loc{charpos, i}
- to := Loc{charpos + utf8.RuneCount(l), i}
+ to := Loc{charpos + util.CharacterCount(l), i}
deltas = append(deltas, Delta{newText, from, to})
}
package display
import (
- "unicode/utf8"
-
runewidth "github.com/mattn/go-runewidth"
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
func (i *InfoWindow) LocFromVisual(vloc buffer.Loc) buffer.Loc {
c := i.Buffer.GetActiveCursor()
l := i.Buffer.LineBytes(0)
- n := utf8.RuneCountInString(i.Msg)
+ n := util.CharacterCountInString(i.Msg)
return buffer.Loc{c.GetCharPosInLine(l, vloc.X-n), 0}
}
activeC := b.GetActiveCursor()
blocX := 0
- vlocX := utf8.RuneCountInString(i.Msg)
+ vlocX := util.CharacterCountInString(i.Msg)
tabsize := 4
line, nColsBeforeStart, bslice := util.SliceVisualEnd(line, blocX, tabsize)
s := i.totalSize()
for j, n := range i.Suggestions {
- c := utf8.RuneCountInString(n)
+ c := util.CharacterCountInString(n)
if j == i.CurSuggestion {
if x+c >= i.hscroll+i.Width {
i.hscroll = util.Clamp(x+c+1-i.Width, 0, s-i.Width)
"regexp"
"strconv"
"strings"
- "unicode/utf8"
luar "layeh.com/gopher-luar"
statusLineStyle = style
}
- leftLen := util.StringWidth(leftText, utf8.RuneCount(leftText), 1)
- rightLen := util.StringWidth(rightText, utf8.RuneCount(rightText), 1)
+ leftLen := util.StringWidth(leftText, util.CharacterCount(leftText), 1)
+ rightLen := util.StringWidth(rightText, util.CharacterCount(rightText), 1)
winX := s.win.X
for x := 0; x < s.win.Width; x++ {
package display
import (
- "unicode/utf8"
-
runewidth "github.com/mattn/go-runewidth"
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
for i, n := range w.Names {
x++
- s := utf8.RuneCountInString(n)
+ s := util.CharacterCountInString(n)
if vloc.Y == w.Y && vloc.X < x+s {
return i
}
s := w.TotalSize()
for i, n := range w.Names {
- c := utf8.RuneCountInString(n)
+ c := util.CharacterCountInString(n)
if i == a {
if x+c >= w.hscroll+w.Width {
w.hscroll = util.Clamp(x+c+1-w.Width, 0, s-w.Width)
package display
import (
- "unicode/utf8"
-
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/screen"
}
text := []byte(w.Name())
- textLen := utf8.RuneCount(text)
+ textLen := util.CharacterCount(text)
for x := 0; x < w.Width; x++ {
if x < textLen {
r, combc, size := util.DecodeCharacter(text)
},
}
-
// DecodeCharacter returns the next character from an array of bytes
// A character is a rune along with any accompanying combining runes
func DecodeCharacter(b []byte) (rune, []rune, int) {
b = b[s:]
c, s = utf8.DecodeRune(b)
}
-
+
return r, combc, size
}