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

add StartSelect Collumn and Row in entry #5403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mykytaserdiuk
Copy link

@mykytaserdiuk mykytaserdiuk commented Jan 12, 2025

Description:

Fixes #5402

Checklist:

  • Lint and formatter run with no errors.
  • Tests all pass.

Need i for it test?

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This naming is misleading - it reads like the verb "Start" rather than a noun / getter.

Also given that there are cursor fields for position should this not match?

I'm not certain of the use-case which is important to get the naming right. The issue you referenced just pointed out the lack it did not actually describe what is trying to be achieved.

@mykytaserdiuk
Copy link
Author

@andydotxyz People who want to get the starting point of the text selection will not be able to get it. I think it would be better if they had a method that would give them this opportunity.
Maybe "Start" is really not a good naming. I make a new name

@andydotxyz
Copy link
Member

Is it possible to expand on the use-case? "Needing to access the variable" doesn't tell us much about why - and because Fyne naming tries to be focused on outcomes then it may be important.

Also there may even be an easier way to do the thing you're trying to achieve!

@mykytaserdiuk
Copy link
Author

@andydotxyz okey. in one of the project I added and refactored the ability in the "text editor" to change the "parameters" of the text by pressing a button. And I found the fact that I can't "out of the box" take the "beginning of the selection", and I had to implement it through available paths. But it was very difficult and unpleasant, after which I decided to make the selectRow and selectColumn fields private

Do I understand correctly that the problem is not only in the implementation, but also in the lack of understanding of the need?

@mykytaserdiuk
Copy link
Author

“start of selection” is what I need to insert in front of the text a text tag specific for display (local text engine for the project, like Markdown)

@andydotxyz
Copy link
Member

Yea trying to understand the need is key ("use-case").
If your need was to get selected text then Entry.SelectedText() would have helped no? Or is there a display element that I'm not understanding as well?

@mykytaserdiuk
Copy link
Author

mykytaserdiuk commented Jan 13, 2025

image

@andydotxyz here is a regular entry window. And in it I selected text. There is a point where I started to select it and finished. The position where I finished selecting can be found out using

"entry.SelectRow" "entry.SelectColumn"
But where I started to see - no

In my case, it will be "row:0 column:1", "row:3 column:3" respectively
But we can’t find out the second one’s data without machinations, mathematics or getting inside pkg.

image

@andydotxyz
Copy link
Member

Yes thanks I understand exactly what you are describing as start of selection - but I'm still it grasping what you're looking to do - text manipulations and selection handling are complex for sure.

In 2.6 we have "InsertAtCursor" and if you send it "textToInsert" + Entry.SelectedText() then it will inset the string at the beginning of the selection.

Is that what you're trying to do?

@mykytaserdiuk
Copy link
Author

@andydotxyz no, using the method you indicated, we can't insert text BEFORE starting to select text

Or is there something I don't understand anymore?

@mykytaserdiuk
Copy link
Author

mykytaserdiuk commented Jan 14, 2025

Maybe have sense create just method for it (insert text before "start pos")?

@andydotxyz
Copy link
Member

@andydotxyz no, using the method you indicated, we can't insert text BEFORE starting to select text

Let's pin this down to more concrete chat. How does what you want to do differ from:

func Test_InsertBefore(t *testing.T) {
	test.NewTempApp(t)

	initial := widget.NewEntry()
	initial.SetText("abcdef")

	right := &fyne.KeyEvent{
		Name: fyne.KeyRight,
	}
	initial.TypedKey(right)
	initial.TypedKey(right)

	initial.KeyDown(&fyne.KeyEvent{
		Name: desktop.KeyShiftLeft,
	})
	initial.TypedKey(right)
	initial.TypedKey(right)
	initial.KeyUp(&fyne.KeyEvent{
		Name: desktop.KeyShiftLeft,
	})

	if initial.SelectedText() != "cd" {
		t.Fail()
	}

	initial.InsertAtCursor("12cd")
	if initial.Text != "ab12cdef" {
		t.Fail()
	}
}

@mykytaserdiuk
Copy link
Author

mykytaserdiuk commented Jan 14, 2025

@andydotxyz yes, the logic is very close, but in this case, we inserted the text at the cursor location, although we started selecting in a different place (we started selecting from the end, but inserted it almost at the beginning of the text)

+it's a replace of the text, if I'm right understand

@andydotxyz
Copy link
Member

@andydotxyz yes, the logic is very close, but in this case, we inserted the text at the cursor location, although we started selecting in a different place (we started selecting from the end, but inserted it almost at the beginning of the text)

+it's a replace of the text, if I'm right understand

Sorry I don't understand this message. The unit test I pasted replaces the selected text with alternative text which is the selection plus some other text - so it could be added at the beginning or the end.

Does that help?

@mykytaserdiuk
Copy link
Author

There is no way, so to speak, to insert text at the same time and the end, and in the beginning of the text (without the help of external means). When we have seen the text, we can find the point where we stopped selecting, but not where we started

CursorRow - the place where we stopped highlighting, but where we started selected, we have no way of knowing this place
Sorry if i write something strange

@andydotxyz
Copy link
Member

There is no way, so to speak, to insert text at the same time and the end, and in the beginning of the text (without the help of external means). When we have seen the text, we can find the point where we stopped selecting, but not where we started

CursorRow - the place where we stopped highlighting, but where we started selected, we have no way of knowing this place Sorry if i write something strange

Forgive me, but doesn't this code very that scenario?

func Test_InsertBefore(t *testing.T) {
	test.NewTempApp(t)

	initial := widget.NewEntry()
	initial.SetText("123456")

	right := &fyne.KeyEvent{
		Name: fyne.KeyRight,
	}
	initial.TypedKey(right)
	initial.TypedKey(right)

	initial.KeyDown(&fyne.KeyEvent{
		Name: desktop.KeyShiftLeft,
	})
	initial.TypedKey(right)
	initial.TypedKey(right)
	initial.KeyUp(&fyne.KeyEvent{
		Name: desktop.KeyShiftLeft,
	})

	if initial.SelectedText() != "34" {
		t.Fail()
	}

	initial.InsertAtCursor("start34stop")
	if initial.Text != "12start34stop56" {
		t.Fail()
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There is no way to get the beginning of the selected text in entry
2 participants