Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Binding left & right arrow keys? #219

Closed
coryasato opened this issue Mar 17, 2016 · 5 comments
Closed

Binding left & right arrow keys? #219

coryasato opened this issue Mar 17, 2016 · 5 comments
Labels

Comments

@coryasato
Copy link

Doesn't fall through to the default behavior when returning false from a custom key handler. Crawled the source code but couldn't find anywhere this is being handled. I guess I could manually reset the selection every time after Im done listening in. Perhaps theres an easier way?

@hellendag
Copy link

What is your use case?

@coryasato
Copy link
Author

I'm trying to listen if the cursor is currently in an inline that has an Entity type of LINK to fire off a popover component to edit the href. This will do a bit more, but for now baby steps. Currently I can achieve this in the onChange event and a little tweak to the 'currentBlockContainsLink' helper.

@hellendag
Copy link

If you don't mind positioning the flyout absolutely, outside the Editor itself, you can declaratively set whether to render it based on the current selection state.

getVisibleSelectionRect may need to be modified for the collapsed cursor, but otherwise, I'm thinking that it could be something like this:

render() {
  return (
    <div>
     <Editor ... />
     <LinkMenu editorState={this.state.editorState} />
    </div>
  );
}

class LinkMenu extends React.Component {
  render() {
    const isWithinLink = ...;
    if (isWithinLink) {
      const targetRect = getVisibleSelectionRect(...);
      return <div style={/* use targetRect to position */}>...</div>;
    }
    return <div />;
  }
}

@coryasato
Copy link
Author

Yup, thats pretty much what I'm doing. :)

We can close this issue if you think that binding to the left / right arrow keys is unnecessary or dangerous. Thanks!

@hellendag
Copy link

I think they could be exposed the same way as the up and down arrow keys, especially if it allows better keyboard navigation for flyouts. For instance, I could imagine a mentions result dropdown that allows two dimensions of navigation.

I haven't seen a need for it yet, so I'm fine with holding off for now. But if anyone should see this issue and want to offer up a PR to solve a need, I'm open to it. :)

facebook-github-bot pushed a commit that referenced this issue Oct 2, 2017
Summary:
Exposes right and left keyboard events, as suggested in [this issue](#219) by hellendag.

This will greatly simplify some of our arrow handling at [Artsy](https://github.com/artsy/positron/blob/master/client/apps/edit/components/content2/sections/text/index.coffee#L121).

The test suite is passing locally.
Closes #1384

Differential Revision: D5954003

fbshipit-source-id: 90c3a7d6bb5070c455f56d60ccd64c5ad136fe59
midas19910709 added a commit to midas19910709/draft-js that referenced this issue Mar 30, 2022
Summary:
Exposes right and left keyboard events, as suggested in [this issue](facebookarchive/draft-js#219) by hellendag.

This will greatly simplify some of our arrow handling at [Artsy](https://github.com/artsy/positron/blob/master/client/apps/edit/components/content2/sections/text/index.coffee#L121).

The test suite is passing locally.
Closes facebookarchive/draft-js#1384

Differential Revision: D5954003

fbshipit-source-id: 90c3a7d6bb5070c455f56d60ccd64c5ad136fe59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants