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