hedy icon indicating copy to clipboard operation
hedy copied to clipboard

🪲 Highlight pressed keyword when expected key is a number key

Open brianpeiris opened this issue 3 months ago • 1 comments

Fixes #5757

The highlighting grammar for Level 13 explicitly allowed for Numbers when using the pressed keyword, as part of the EqualityCheck rule. Subsequent grammars (Level 14-18) omitted Numbers since the rule was split out into a dedicated PressedCheck rule. This PR reintroduces Numbers in the pressed grammar rule to fix the highlighting when expecting a number key press.

How to test

Follow these steps to verify this PR works as intended:

  • Visit http://localhost:8080/hedy/14#debugging
  • Paste in the following code:
if 1 is pressed
    print 'one'
else
    print 'waiting for second key'
    if x is pressed
        print 'x'
    else
        print '?'
  • See that pressed is highlighted orange in both if conditions
  • Visit http://localhost:8080/hedy/17#debugging
  • Paste in the following code:
stop = False
key = 'x'
while stop == False:
    if 1 is pressed:
        print 'one'
    elif a is pressed:
        print 'a'
    elif key is pressed:
        print 'x'
        stop = True
    else:
        print '?'
  • See that pressed is highlighted orange in all the if and elif conditions

Checklist

  • [x] Contains one of the PR categories in the name
  • [x] Describes changes in the format above
  • [x] Links to an existing issue or discussion
  • [x] Has a "How to test" section

brianpeiris avatar Sep 05 '25 10:09 brianpeiris

Thanks for the fix @brianpeiris!

We are about to make some large changes to the grammar (see https://github.com/hedyorg/hedy/pull/6329) which will then also impact the highlighter, so we need to keep this PR for a little while until @jpelay is ready with the highlighter.

@jpelay Can you take this into account when updating the highlighter?

Felienne avatar Sep 05 '25 11:09 Felienne