Auto-dedent lines but indent following lines

I am deveoping a simple mode for a grammar in which all lines starting with the word bank should have indent level 0, and all following lines should have indent level 1. Example:

initial lines
with no indentation
bank foo
  this gets indented
  this as well
bank this not
  this yes

…so I set indent: true on the token rule for bank, which indents all following lines. But when we get to the next line starting with bank, that line itself is still indented (from the previous bank), so I would like it to automatically get dedented. However, setting dedent: true only works when I don’t use indent: true.

I tried to fix this using electricInput. However, the way electricInput is implemented, even if the regex matches, the event only fires if smart-indent on that line changes the indentation (which it doesn’t). How do I get the correct behavior?

The mode’s indentation method gets called with the line that should be intented as argument. You can see if that starts with bank and reset the indentation when it does – this is how things like else and closing braces are handled in many languages.