Domain entry special cases #4891
Replies: 3 comments 11 replies
-
It sounds like a case for Validation. Otherwise an extended Entry where you intercept the TypedRune and paste functionality to do as you desire. |
Beta Was this translation helpful? Give feedback.
-
To extract the characters before and after the cursor position, |
Beta Was this translation helpful? Give feedback.
-
func main() {
a := app.New()
w := a.NewWindow("Hello")
hello := widget.NewLabel("")
ent := widget.NewEntry()
selstart := -1
ent.OnCursorChanged = func() {
pos := ent.CursorColumn
text := ent.SelectedText()
if text == "" {
hello.SetText("No selection")
selstart = -1
return
}
pos2 := 0
if selstart == -1 {
selstart = ent.CursorColumn
}
if ent.CursorColumn >= selstart {
pos = ent.CursorColumn - len(text)
}
pos2 = pos + len(text)
info := fmt.Sprintf("Selection \"%s\", range %d:%d", text, pos, pos2)
hello.SetText(info)
}
w.SetContent(container.NewVBox(
hello,
ent,
))
w.ShowAndRun()
} |
Beta Was this translation helpful? Give feedback.
-
Checklist
Is your feature request related to a problem?
I am creating a domain input field in the fyne graphical environment.
The basic input is easy to filter, but there were problems.
The domain name cannot contain two dots in a row.
There cannot be a hyphen before or after the period.
My questions:
If, while typing, the user moves the cursor in the already typed text. Is it possible to scan the character before the cursor and the character after the cursor?
If the user selects a piece of text, can the character before and after the selection be read?
The goal is to prevent the user from writing or pasting text that invalidates the already entered domain name.
Is it possible to construct a solution with the existing API?
No response
Describe the solution you'd like to see.
I would like to detect when the user clicks on the entry and then request the characters before and after the cursor in the program.
I would like to detect when the user clicks in the entry and selects a text section and then request the characters before and after the selection in the program.
Beta Was this translation helpful? Give feedback.
All reactions