Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:outline/markdown-editor into remo…
Browse files Browse the repository at this point in the history
…ve-forced-title
  • Loading branch information
tommoor committed Jul 13, 2018
2 parents f770941 + 5421cba commit 7bf8a08
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ This callback is triggered when the user explicitly requests to save using a key

#### `onCancel`

This callback is triggered when the escape key is hit within the editor. You may use it to cancel editing.
This callback is triggered when the `Cmd+Escape` is hit within the editor. You may use it to cancel editing.

#### `onChange`

Expand Down
2 changes: 2 additions & 0 deletions src/components/Toolbar/LinkSearchResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const ListItem = styled.a`
height: 28px;
padding: 6px 8px 6px 0;
color: ${props => props.theme.white};
font-family: ${props => props.theme.fontFamily};
font-size: 15px;
text-decoration: none;
overflow: hidden;
white-space: nowrap;
Expand Down
25 changes: 20 additions & 5 deletions src/components/Toolbar/LinkToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ export default class LinkToolbar extends React.Component<Props, State> {
this.save(url);
};

cancel = () => {
this.save(this.originalValue);
};

onKeyDown = (ev: SyntheticKeyboardEvent<*>) => {
switch (ev.which) {
case 13: // enter
switch (ev.key) {
case "Enter":
ev.preventDefault();
if (!(ev.target instanceof HTMLInputElement)) return;
return this.save(ev.target.value);
case 27: // escape
return this.save(this.originalValue);
case 40: // down
case "Escape":
ev.preventDefault();
ev.stopPropagation();
return this.cancel();
case "ArrowDown":
ev.preventDefault();
if (this.firstDocument) {
const element = findDOMNode(this.firstDocument);
Expand All @@ -138,6 +144,14 @@ export default class LinkToolbar extends React.Component<Props, State> {
this.setState({ results: [] });
};

onResultKeyDown = (ev: SyntheticKeyboardEvent<*>) => {
if (ev.key === "Escape") {
ev.preventDefault();
ev.stopPropagation();
this.cancel();
}
};
removeLink = () => {
this.save("");
};
Expand Down Expand Up @@ -202,6 +216,7 @@ export default class LinkToolbar extends React.Component<Props, State> {
title={result.title}
key={result.url}
onClick={ev => this.selectSearchResult(ev, result.url)}
onKeyDown={this.onResultKeyDown}
/>
))}
</ArrowKeyNavigation>
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {
if (isModKey(ev)) this.onSaveAndExit(ev);
return;
case "Escape":
this.onCancel(ev);
if (isModKey(ev)) this.onCancel(ev);
return;
default:
}
Expand Down

0 comments on commit 7bf8a08

Please sign in to comment.