question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add reserved custom commands for `enter` to override default handling

See original GitHub issue

Do 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thesunnycommented, May 9, 2019

I feel like this bridge can be crossed later and it’s adding to the issues so I’m going to close for now.

1reaction
ianstormtaylorcommented, Apr 26, 2019

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to customize Voice Control commands on your iPhone ...
Create a custom command · Go to Settings and select Accessibility. · Select Voice Control, then Customize Commands. · Select Create New Command, ......
Read more >
Custom Commands - Cypress Documentation
Cypress comes with its own API for creating custom commands and overwriting existing commands. The built in Cypress commands use the very same...
Read more >
Override command or entrypoint | Northflank Application docs
You can override the default command from the CMD override page in your job or service by selecting custom command as the Docker...
Read more >
Custom Commands in Cypress - Tools QA
What are custom commands in Cypress and the recommended best practices? How to add Custom commands documentation in Cypress Intellisense?
Read more >
Symfony Console - Overwrite default options
The defaults are defined in Console\Application::getDefaultInputDefinition so I suppose you could make your own Application class and override.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found