Skip to content

Commit

Permalink
Fix pointer and cursor misalignment
Browse files Browse the repository at this point in the history
Applying the updated maths for finding characters.
Fixes #1937
  • Loading branch information
andydotxyz committed Feb 21, 2021
1 parent d939382 commit 7f76a8f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions widget/entry.go
Expand Up @@ -724,9 +724,10 @@ func (e *Entry) copyToClipboard(clipboard fyne.Clipboard) {

func (e *Entry) cursorColAt(text []rune, pos fyne.Position) int {
for i := 0; i < len(text); i++ {
str := string(text[0 : i+1])
wid := fyne.MeasureText(str, theme.TextSize(), e.textStyle()).Width + theme.Padding()
if wid > pos.X+theme.Padding() {
str := string(text[0 : i])
wid := fyne.MeasureText(str, theme.TextSize(), e.textStyle()).Width
charWid := fyne.MeasureText(string(text[i]), theme.TextSize(), e.textStyle()).Width
if pos.X < theme.Padding()*2 + wid + (charWid/2) {
return i
}
}
Expand Down

0 comments on commit 7f76a8f

Please sign in to comment.