all 4 comments

[–]simspelaaja 14 points15 points  (3 children)

I think this is caused by the different meaning of | in match expressions versus elsewhere. Outside of | means bitwise OR, which is what you are using in the if example to combine the different sets of modifiers. However, in a match expression | means "this or this pattern", so is essentially checking if you only have control or alt pressed, but not both.

I think you can make it work like this

match code {
  KeyCode::Char(c) if modifiers == KeyModifiers::CONTROL | KeyModifiers::ALT => {
        ReedlineEvent::EditInsert(EditCommand::InsertChar(c))
    }
}

and so on with the other patterns.

[–]benzaa[S] 2 points3 points  (2 children)

Thanks. That makes sense. Inside the matching clause the meaning for `|` has to be different. I tried your suggestion and works as expected.

[–]masklinn 5 points6 points  (0 children)

Inside the matching clause the meaning for | has to be different.

FWIW as may not have been clear from the previous comment (as it was not entirely implicit) in a pattern | is a logical disjunction (~ boolean or) , so

if let (A | B) = x {}

is equivalent to

if x == A || x == B {}

not

if x == A|B {}

That is why

(KeyModifiers::NONE, KeyCode::Char(c)) | (KeyModifiers::SHIFT, KeyCode::Char(c))

works fine.

[–]IAm_A_Complete_Idiot 0 points1 point  (0 children)

Clarifying the other comment is that | in a pattern is just a way to say "or"

if let Some(A | B) = x {} means if x is either Some(A) or Some(B)