Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default function App() {
return KeyCommand.addListener(KEY_COMMAND, () => handleSearchCommandPress('[CMD + F] pressed'));
}, []);

React.useEffect(() => {
const KEY_COMMAND = {input: KeyCommand.constants.keyInputEscape, modifierFlags: KeyCommand.constants.keyModifierShift};
return KeyCommand.addListener(KEY_COMMAND, () => handleSearchCommandPress('[Shift + Esc] pressed'));
}, []);

React.useEffect(() => {
const KEY_COMMAND = {input: KeyCommand.constants.keyInputEscape};
return KeyCommand.addListener(KEY_COMMAND, () => handleSearchCommandPress('[Esc] pressed'));
Expand Down Expand Up @@ -78,9 +83,10 @@ export default function App() {
<Text style={styles.title}>1. [CMD + F]</Text>
<Text style={styles.title}>2. [G]</Text>
<Text style={styles.title}>3. [Esc]</Text>
<Text style={styles.title}>4. [CMD + SHIFT + K]</Text>
<Text style={styles.title}>5. [ENTER]</Text>
<Text style={styles.title}>6. [DOWN / UP ARROW]</Text>
<Text style={styles.title}>4. [Shift + Esc]</Text>
<Text style={styles.title}>5. [CMD + SHIFT + K]</Text>
<Text style={styles.title}>6. [ENTER]</Text>
<Text style={styles.title}>7. [DOWN / UP ARROW]</Text>
</View>

<ScrollView style={styles.scroll}>
Expand Down
2 changes: 1 addition & 1 deletion src/KeyCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function getRegisteredCommandIndex(json) {
// This does a strict check first to see if there is a match
// https://github.com/Expensify/App/issues/18480
const strictIndex = _.findIndex(commands, item => (
(item.input === json.input && matchesModifierFlags(item))
((item.input === json.input || (matchesEscape(item))) && matchesModifierFlags(item))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This technically happens to every non single letter input, but I only added it for escape for now. Let me know if I should handle them all.

Copy link
Member

@s77rt s77rt Jun 3, 2025

Choose a reason for hiding this comment

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

I'm not sure I understand the logic here. Why are item.input and json.input not equal? (and what are their values)

Copy link
Member

Choose a reason for hiding this comment

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

I'm still trying to understand the bug. Here is what I think is going: After you press ESC, we look for an exact (strict) match and we fail and fallback for loose match and we end up with the listener for SHIFT + ESC (because it's somehow first in the list). Does that sound about right? If so I think we should add a condition to handle exact ESC key combination i.e.:

    const strictIndex = _.findIndex(commands, item => (
        (item.input === json.input && matchesModifierFlags(item))
        || (matchesEnter(item) && matchesModifierFlags(item))
        || (matchesEscape(item) && matchesModifierFlags(item))
    ));

Copy link
Member

Choose a reason for hiding this comment

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

Ahh it's exactly the same logic your are making XD

Can you just rewrite that way as I think it's a little more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, I'm trying to keep it short. Updated.

|| (matchesEnter(item) && matchesModifierFlags(item))
));

Expand Down