Fix for repeating in some instances, e.g. pidgin.
This commit is contained in:
1 parent
4d29f2bb23
commit
b232c1eebb
20 files changed
+921
-7
No files matched your search
@@ -32,6 +32,7 @@ type Activity struct {
|
||||
// may be waiting for application settings after ordinary input has aged out.
|
||||
TitleInterruptionSequence uint64
|
||||
PlainCharacterArrow bool
|
||||
PlainEnter bool
|
||||
Selecting bool
|
||||
Intent Intent
|
||||
Sequence uint64
|
||||
@@ -55,6 +56,7 @@ type IntentTracker struct {
|
||||
intent Intent
|
||||
clipboard ClipboardAction
|
||||
plainCharacterArrow bool
|
||||
plainEnter bool
|
||||
selecting bool
|
||||
at time.Time
|
||||
}
|
||||
@@ -78,6 +80,7 @@ func (tracker *IntentTracker) Observe(event Event) {
|
||||
tracker.clipboard = NoClipboardAction
|
||||
tracker.selecting = false
|
||||
tracker.plainCharacterArrow = false
|
||||
tracker.plainEnter = false
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -127,6 +130,9 @@ func (tracker *IntentTracker) Observe(event Event) {
|
||||
tracker.plainCharacterArrow = (name == "Left" || name == "Right") && !ctrl && !shift && !alt &&
|
||||
!tracker.held["Super_L"] && !tracker.held["Super_R"] &&
|
||||
!tracker.held["ISO_Level3_Shift"] && !tracker.held["ISO_Level5_Shift"]
|
||||
tracker.plainEnter = (name == "Return" || name == "Enter") && !ctrl && !shift && !alt &&
|
||||
!tracker.held["Super_L"] && !tracker.held["Super_R"] &&
|
||||
!tracker.held["ISO_Level3_Shift"] && !tracker.held["ISO_Level5_Shift"]
|
||||
tracker.selecting = shift && (intent == CharacterIntent || intent == WordIntent || intent == LineIntent)
|
||||
tracker.intent, tracker.at = intent, time.Now()
|
||||
}
|
||||
@@ -141,6 +147,7 @@ func (tracker *IntentTracker) Reset() {
|
||||
tracker.intent, tracker.at = OtherIntent, time.Time{}
|
||||
tracker.clipboard, tracker.selecting = NoClipboardAction, false
|
||||
tracker.plainCharacterArrow = false
|
||||
tracker.plainEnter = false
|
||||
}
|
||||
|
||||
func (tracker *IntentTracker) RecentInput() Activity {
|
||||
@@ -149,6 +156,6 @@ func (tracker *IntentTracker) RecentInput() Activity {
|
||||
if time.Since(tracker.at) > time.Second {
|
||||
return Activity{InputSequence: tracker.sequence, TitleInterruptionSequence: tracker.titleInterruptionSequence}
|
||||
}
|
||||
return Activity{PlainCharacterArrow: tracker.plainCharacterArrow, InputSequence: tracker.sequence, Intent: tracker.intent, Sequence: tracker.sequence, Clipboard: tracker.clipboard, Selecting: tracker.selecting,
|
||||
return Activity{PlainCharacterArrow: tracker.plainCharacterArrow, PlainEnter: tracker.plainEnter, InputSequence: tracker.sequence, Intent: tracker.intent, Sequence: tracker.sequence, Clipboard: tracker.clipboard, Selecting: tracker.selecting,
|
||||
TitleInterruptionSequence: tracker.titleInterruptionSequence}
|
||||
}
|
||||
@@ -70,6 +70,47 @@ func TestIntentTracksClipboardChords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlainEnterActivityLifetime(t *testing.T) {
|
||||
for _, key := range []string{"Return", "KP_Enter"} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
tracker := &IntentTracker{}
|
||||
tracker.Observe(NewKeyEvent(0, true, key))
|
||||
tracker.Observe(NewKeyEvent(0, false, key))
|
||||
if activity := tracker.RecentInput(); !activity.PlainEnter || activity.Sequence == 0 || activity.Intent != OtherIntent {
|
||||
t.Fatalf("Enter release lost activity: %+v", activity)
|
||||
}
|
||||
tracker.Observe(NewKeyEvent(0, true, "a"))
|
||||
if tracker.RecentInput().PlainEnter {
|
||||
t.Fatal("Enter survived the next key")
|
||||
}
|
||||
tracker.Observe(NewKeyEvent(0, true, key))
|
||||
tracker.at = time.Now().Add(-2 * time.Second)
|
||||
if tracker.RecentInput().PlainEnter {
|
||||
t.Fatal("expired Enter remained active")
|
||||
}
|
||||
tracker.Observe(NewKeyEvent(0, true, key))
|
||||
tracker.Reset()
|
||||
if tracker.RecentInput().PlainEnter {
|
||||
t.Fatal("reset retained Enter")
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, modifier := range []string{"Shift_L", "Control_L", "Alt_L", "Super_L", "ISO_Level3_Shift"} {
|
||||
t.Run(modifier, func(t *testing.T) {
|
||||
tracker := &IntentTracker{}
|
||||
tracker.Observe(NewKeyEvent(0, true, "Return"))
|
||||
tracker.Observe(NewKeyEvent(0, true, modifier))
|
||||
if tracker.RecentInput().PlainEnter {
|
||||
t.Fatal("modifier press retained plain Enter")
|
||||
}
|
||||
tracker.Observe(NewKeyEvent(0, true, "Return"))
|
||||
if tracker.RecentInput().PlainEnter {
|
||||
t.Fatal("modified Enter classified as plain Enter")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectionIntentEndsWithPlainNavigation(t *testing.T) {
|
||||
tracker := &IntentTracker{}
|
||||
tracker.Observe(NewKeyEvent(0, true, "Shift_L"))
|
||||
|
||||
Reference in new issue
Block a user