Fix some issues with unicode handling

There were unicode issues with prompts, search, and syntax highlighting,
which are now fixed.
This commit is contained in:
Zachary Yedidia 2016-08-18 08:14:33 -07:00
parent e4b6a931de
commit 8d230d2038
4 changed files with 7 additions and 5 deletions

View file

@ -472,6 +472,7 @@ func Match(v *View) SyntaxMatches {
for _, value := range indicies {
start := runePos(value[0], line)
end := runePos(value[1], line)
// messenger.Message(start, " ", end)
for i := start; i < end; i++ {
matches[lineN][i] = rule.style
}

View file

@ -249,7 +249,7 @@ func (m *Messenger) HandleEvent(event tcell.Event, history []string) {
}
case tcell.KeyBackspace2, tcell.KeyBackspace:
if m.cursorx > 0 {
m.response = string([]rune(m.response)[:m.cursorx-1]) + string(m.response[m.cursorx:])
m.response = string([]rune(m.response)[:m.cursorx-1]) + string([]rune(m.response)[m.cursorx:])
m.cursorx--
}
case tcell.KeyRune:

View file

@ -84,10 +84,10 @@ func Search(searchStr string, v *View, down bool) {
var charPos int
text := v.Buf.String()
if down {
str = text[searchStart:]
str = string([]rune(text)[searchStart:])
charPos = searchStart
} else {
str = text[:searchStart]
str = string([]rune(text)[:searchStart])
}
r, err := regexp.Compile(searchStr)
if settings["ignorecase"].(bool) {
@ -127,7 +127,6 @@ func Search(searchStr string, v *View, down bool) {
v.Cursor.CurSelection[0] = FromCharPos(charPos+runePos(match[0], str), v.Buf)
v.Cursor.CurSelection[1] = FromCharPos(charPos+runePos(match[1], str), v.Buf)
v.Cursor.Loc = FromCharPos(charPos+match[1]-1, v.Buf)
if v.Relocate() {
v.matches = Match(v)
}

View file

@ -624,7 +624,8 @@ func (v *View) DisplayView() {
}
// Now we actually draw the line
for colN, ch := range line {
colN := 0
for _, ch := range line {
lineStyle := defStyle
if settings["syntax"].(bool) {
@ -709,6 +710,7 @@ func (v *View) DisplayView() {
}
charNum = charNum.Move(1, v.Buf)
screenX++
colN++
}
// Here we are at a newline