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

Commit

Permalink
KeyBindingUtil: add usesMacOSHeuristics method (#869)
Browse files Browse the repository at this point in the history
Summary:
**Summary**

Add a public method, `usesMacOSHeuristics`, to the `KeyBindingUtil` module. This makes it possible to determine how draft-js will interpret certain keyboard events and thus alter the UI accordingly, e.g.;

<img width="499" alt="screenshot 2016-12-13 at 17 58 33" src="https://cloud.githubusercontent.com/assets/6705160/21150013/dee64566-c15d-11e6-9639-75a39d21d079.png">

I currently achieve this by doing (🙈);

```js
const COMMAND_MODIFIER_CHAR = (navigator && navigator.userAgent.indexOf('Mac') >= 0)
    ? '\u2318' // Mac command key character
    : 'Ctrl'
```
Pull Request resolved: #869

Differential Revision: D9734962

fbshipit-source-id: ed3f3d0a87df51c708fd666fe85bc6acba1ecfee
  • Loading branch information
williamboman authored and facebook-github-bot committed Sep 8, 2018
1 parent c6ff39d commit 98e7730
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/APIReference-KeyBindingUtil.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ isOptionKeyCommand: function(
): boolean
```

### usesMacOSHeuristics

```
usesMacOSHeuristics: function(): boolean
```

Check whether heuristics that only apply to macOS are used internally, for
example when determining the key combination used as command modifier.

### hasCommandModifier

```
Expand Down
4 changes: 4 additions & 0 deletions src/component/utils/KeyBindingUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const KeyBindingUtil = {
return isOSX && e.altKey;
},

usesMacOSHeuristics: function(): boolean {
return isOSX;
},

hasCommandModifier: function(e: SyntheticKeyboardEvent<>): boolean {
return isOSX
? !!e.metaKey && !e.altKey
Expand Down

0 comments on commit 98e7730

Please sign in to comment.