From ad61b790fdef156179b843e439be28613369ded7 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 10 Nov 2024 20:45:40 +0100 Subject: WIP: xA: entry modifiers --- xA/xA.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/xA/xA.go b/xA/xA.go index 417a24a..f61102e 100644 --- a/xA/xA.go +++ b/xA/xA.go @@ -979,23 +979,31 @@ func inputSubmit(text string) bool { type customEntry struct { widget.Entry + + // selectKeyDown is a hack to exactly invert widget.Entry's behaviour, + // which groups both Shift keys together. selectKeyDown bool + + down map[fyne.KeyName]bool } func newCustomEntry() *customEntry { e := &customEntry{} e.MultiLine = true e.Wrapping = fyne.TextWrap(fyne.TextTruncateClip) + e.down = make(map[fyne.KeyName]bool) e.ExtendBaseWidget(e) return e } func (e *customEntry) FocusLost() { + e.down = make(map[fyne.KeyName]bool) e.selectKeyDown = false e.Entry.FocusLost() } func (e *customEntry) KeyDown(key *fyne.KeyEvent) { + e.down[key.Name] = true if key.Name == desktop.KeyShiftLeft || key.Name == desktop.KeyShiftRight { e.selectKeyDown = true } @@ -1003,6 +1011,7 @@ func (e *customEntry) KeyDown(key *fyne.KeyEvent) { } func (e *customEntry) KeyUp(key *fyne.KeyEvent) { + delete(e.down, key.Name) if key.Name == desktop.KeyShiftLeft || key.Name == desktop.KeyShiftRight { e.selectKeyDown = false } @@ -1014,6 +1023,19 @@ func (e *customEntry) TypedKey(key *fyne.KeyEvent) { return } + /* + modified := false + for _, name := range []fyne.KeyName{ + desktop.KeyAltLeft, desktop.KeyAltRight, + desktop.KeyControlLeft, desktop.KeyControlRight, + desktop.KeySuperLeft, desktop.KeySuperRight, + } { + if e.down[name] { + modified = true + } + } + */ + // Invert the Shift key behaviour here. // Notice that this will never work on mobile. shift := &fyne.KeyEvent{Name: desktop.KeyShiftLeft} @@ -1027,7 +1049,8 @@ func (e *customEntry) TypedKey(key *fyne.KeyEvent) { e.OnSubmitted(e.Text) } case fyne.KeyTab: - // TODO(p) + // TODO(p): Just do e.Append() if state matches. + log.Println("completion") default: e.Entry.TypedKey(key) } -- cgit v1.2.3-70-g09d2