Fix cursor positioning and add utf8 import
This commit is contained in:
parent
0b727ff3b2
commit
6939550527
|
|
@ -3,6 +3,7 @@ package editor
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"pad/internal/browser"
|
"pad/internal/browser"
|
||||||
"pad/internal/ui"
|
"pad/internal/ui"
|
||||||
|
|
@ -485,13 +486,10 @@ func SetCursorFromPoint(x, y float64) {
|
||||||
|
|
||||||
// 3. Check if tap is to the right of the last character on this line
|
// 3. Check if tap is to the right of the last character on this line
|
||||||
if rightmostIdx != -1 && x > rightmostX {
|
if rightmostIdx != -1 && x > rightmostX {
|
||||||
// If rightmostIdx is the last glyph of the entire document
|
// Position after the last character on this line
|
||||||
if rightmostIdx == len(layout.X)-1 {
|
start := layout.ByteOffsets[rightmostIdx]
|
||||||
TheState.Editor.CursorPosition = len(TheState.Editor.Buffer)
|
_, size := utf8.DecodeRuneInString(TheState.Editor.Buffer[start:])
|
||||||
} else {
|
TheState.Editor.CursorPosition = start + size
|
||||||
// Position after the last character on this line
|
|
||||||
TheState.Editor.CursorPosition = layout.ByteOffsets[rightmostIdx+1]
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user