I want to create a key binding that only fires when the final entry in the scope list is “meta.jsx.js”.
The keybinding listens to the >
key and is used to autocomplete React JSX tags, so when I type <span
and then >
, I get <span>|</span>
. It works really well until I start embedding JSX tags inside dynamically evaluated expressions:
<ul>
{items.map(item => {
if (item.value > 10) {
return <li>{item.value}</li>;
}
return null;
})}
</ul>
In this case, I want the >
key to complete the tag on the internal <li>
, but not on the arrow function’s =>
symbol or the >
inside the if
statement. It seems to me that the best solution is to match the keybinding on the final entry of the scope, which is always meta.jsx.js
at the place that I want to complete the tag. But I don’t know how to create a keybinding that only fires when the last entry in scope matches.
Any thoughts? I am also open to alternative methods of autocompleting tags, because I may be making this more complex than it needs to be.