Add reserved custom commands for `enter` to override default handling
See original GitHub issueDo you want to request a feature or report a bug?
Add reserved custom command for enter
to normalize behavior between desktop and mobile
What’s the current behavior?
Currently there is no way to intercept enter
behavior in Android because enter
is usually implemented by looking at keydown
and checking for the enter
key then overriding it. In Android, we cannot intercept and prevent default on the enter
key.
Note that by default Slate calls splitBlock
(I believe) when handling an enter
.
What’s the expected behavior?
In Android, there is no interruptible keydown
event that we can cancel and replace behavior with but we still want a way to do special handling of enter
. For example, in a table or a list, we want to handle it differently.
The way we can do it is to reserve a special command like enter
. By default, we can have hitting enter
do a splitBlock
like it currently does; however, if an enter
command is available (because the developer added it), we use that instead. Something like this pseudo code.
if (commandExists('enter') {
editor.enter()
} else {
editor.splitBlock()
}
Note that this approach means that we can’t easily build plugins with enter
handling in it because we can only have one enter
command. Another approach I suggested was creating a special event like onEnter
that would go through the normal event handling chain; however, there was some push back on that and the thought that perhaps we should use commands instead.
I don’t feel like this solution I have here is a better solution than creating a custom event but I agree that that approach is heavy. If anyone has any better ideas, I’d be grateful to hear them.
Either way, with an enter
command, we can get Android working even though it may require a very big custom enter
command with branching. This is better than having no solution to the problem.
If a solution cannot be found that is acceptable at this time, I will probably make a custom command like enterOnAndroid
that would only be called in Android so that at last we can have the ability to make Android work until we can come to a consensus on a cross-platform method.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I feel like this bridge can be crossed later and it’s adding to the issues so I’m going to close for now.
Interesting points. For (1) I’m not sure there’s a good solution, but that’s kind of inherent to middleware/composition. For (2) I think you could use
splitBlockAtRange
for that potentially?For other thoughts, check out https://github.com/ianstormtaylor/slate/issues/2342. It would be great if you add your thoughts there too for the future!