Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some incorrect cursor movement in a multiline entry with wrapping #2698

Closed
nullst opened this issue Dec 19, 2021 · 1 comment
Closed

Some incorrect cursor movement in a multiline entry with wrapping #2698

nullst opened this issue Dec 19, 2021 · 1 comment
Labels
blocker Items that would block a forthcoming release bug Something isn't working

Comments

@nullst
Copy link
Contributor

nullst commented Dec 19, 2021

Describe the bug:

This is kind of a follow-up to #1737 : more edge cases for cursor positioning for entries with wrapping enabled.

Suppose you have a multiline entry with word wrapping enabled. Some user actions move the cursor into an unexpected position. I've observed two problems, probably with the same underlying issue, thus I'm reporting them jointly:

Erasing the first symbol

Put the cursor after the first symbol on some line in a multiline entry with wrapping. Any line except the very first one would work. Pressing backspace erases the symbol, but then moves the cursor to the start of the next line instead of staying in the same line.

The additional cursor movement happens due to the rowColFromTextPos function in entry.go, specifically in this part:

fyne/widget/entry.go

Lines 910 to 912 in 6c35798

if canWrap && b.begin == pos && col == 0 && pos != 0 && row < (totalRows-1) {
row++
}

This part of logic was created to fix #1737, but I guess it is executed in some undesirable cases too.

Space key in a word-wrapped entry

In a word-wrapping entry, sometimes pressing the space character creates a new (visual) line of text. In some cases at this moment cursor also moves one more row down than expected: instead of being moved to the new visual line, it's being put one line after that.

It's easiest to reproduce by putting the cursor at the beginning of the last word on some line, and then pressing space enough times to move that word to the next visual line. You would see that the cursor is no longer at the beginning of that word but rather in the next line after it. It's also relatively easy to reproduce by typing a space in the middle of a long word in a way that the second part of the word no longer fits visually after the space character. Then the cursor would also jump two lines down instead of only one.

To Reproduce:

Steps to reproduce the behavior:

  1. Compile the example code below and run it.
  2. To see the issue with space character, just press space. The long word would split into two and the cursor would jump two lines down.
  3. To see the issue with erasing one character, press backspace several time until you erase the first symbol. You will see the cursor move one line down. Alternatively, just put the cursor so that pressing backspace would erase the first symbol of some line for the same result.

Example code:

package main

import (
	"time"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	app := app.New()
	w := app.NewWindow("Multiline entry demo")

	entry := widget.NewMultiLineEntry()
	entry.Wrapping = fyne.TextWrapWord
	entry.SetText("abc\ns\ndefsfdsfsdffd\nf hh\n")

	w.SetContent(entry)
	w.Resize(fyne.NewSize(float32(120), float32(150)))
	w.Canvas().Focus(entry)

	go func() {
		// NB: the window (hence the entry as well) is tiny when just created,
		// which causes excessive wrapping in the entry. Calling w.Resize() does not
		// resize the entry immediately, so we set cursor position only after a delay.
		// I don't know if this is considered a bug, but it's a bit surprising.
		time.AfterFunc(200*time.Millisecond, func() {
			entry.CursorRow = 2
			entry.CursorColumn = 7
			entry.Refresh()
		})
	}()

	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: Linux
  • Version: PopOS 21.04
  • Go version: go1.17.4 linux/amd64
  • Fyne version: v2.1.2
@nullst nullst added the unverified A bug that has been reported but not verified label Dec 19, 2021
@andydotxyz andydotxyz added blocker Items that would block a forthcoming release bug Something isn't working and removed unverified A bug that has been reported but not verified labels Dec 19, 2021
@andydotxyz andydotxyz added this to the Fixes (v2.1.x) milestone Dec 19, 2021
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Feb 18, 2022
@andydotxyz
Copy link
Member

Resolved on release/v2.1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Items that would block a forthcoming release bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants