aboutsummaryrefslogtreecommitdiff
path: root/xA/xA.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-11-10 18:24:14 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-11-10 18:24:14 +0100
commit066b99e4cac9c51fa9bd46e62e8e593c1c80d3e5 (patch)
tree1a2712c64733b9bf227266203a050922d3967127 /xA/xA.go
parent813c5b09fe57021809a4f550d766e43b809e433e (diff)
downloadxK-066b99e4cac9c51fa9bd46e62e8e593c1c80d3e5.tar.gz
xK-066b99e4cac9c51fa9bd46e62e8e593c1c80d3e5.tar.xz
xK-066b99e4cac9c51fa9bd46e62e8e593c1c80d3e5.zip
WIP: xA: desired Return handling
Diffstat (limited to 'xA/xA.go')
-rw-r--r--xA/xA.go65
1 files changed, 62 insertions, 3 deletions
diff --git a/xA/xA.go b/xA/xA.go
index c1038e5..f1de18f 100644
--- a/xA/xA.go
+++ b/xA/xA.go
@@ -24,6 +24,7 @@ import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
+ "fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
@@ -219,7 +220,7 @@ var (
wRichScroll *container.Scroll
wPrompt *widget.Label
wStatus *widget.Label
- wEntry *widget.Entry
+ wEntry *customEntry
)
// -----------------------------------------------------------------------------
@@ -974,6 +975,64 @@ func inputSubmit(text string) bool {
// --- General UI --------------------------------------------------------------
+type customEntry struct {
+ widget.Entry
+ selectKeyDown bool
+}
+
+func newCustomEntry() *customEntry {
+ e := &customEntry{}
+ e.MultiLine = true
+ e.Wrapping = fyne.TextWrap(fyne.TextTruncateClip)
+ e.ExtendBaseWidget(e)
+ return e
+}
+
+func (e *customEntry) FocusLost() {
+ e.selectKeyDown = false
+ e.Entry.FocusLost()
+}
+
+func (e *customEntry) KeyDown(key *fyne.KeyEvent) {
+ if key.Name == desktop.KeyShiftLeft || key.Name == desktop.KeyShiftRight {
+ e.selectKeyDown = true
+ }
+ e.Entry.KeyDown(key)
+}
+
+func (e *customEntry) KeyUp(key *fyne.KeyEvent) {
+ if key.Name == desktop.KeyShiftLeft || key.Name == desktop.KeyShiftRight {
+ e.selectKeyDown = false
+ }
+ e.Entry.KeyUp(key)
+}
+
+func (e *customEntry) TypedKey(key *fyne.KeyEvent) {
+ if e.Disabled() {
+ return
+ }
+
+ // Invert the Shift key behaviour here.
+ // Notice that this will never work on mobile.
+ shift := &fyne.KeyEvent{Name: desktop.KeyShiftLeft}
+ switch key.Name {
+ case fyne.KeyReturn, fyne.KeyEnter:
+ if e.selectKeyDown {
+ e.Entry.KeyUp(shift)
+ e.Entry.TypedKey(key)
+ e.Entry.KeyDown(shift)
+ } else if e.OnSubmitted != nil {
+ e.OnSubmitted(e.Text)
+ }
+ case fyne.KeyTab:
+ // TODO(p)
+ default:
+ e.Entry.TypedKey(key)
+ }
+}
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
func main() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(),
@@ -1042,12 +1101,12 @@ func main() {
"", fyne.TextAlignLeading, fyne.TextStyle{Bold: true})
wStatus = widget.NewLabelWithStyle(
"", fyne.TextAlignTrailing, fyne.TextStyle{})
- wEntry = widget.NewMultiLineEntry()
+
+ wEntry = newCustomEntry()
// TODO(p): Rather respond to all keypresses/similar activity.
wEntry.OnChanged = func(text string) {
relaySend(RelayCommandData{Variant: &RelayCommandDataActive{}}, nil)
}
- // TODO(p): Make this submit on Enter rather than Shift+Enter.
wEntry.OnSubmitted = func(text string) {
inputSubmit(text)
}