Skip to content

Commit

Permalink
Don't exit EuiCodeEditor when the ESCAPE key is being used to dismis…
Browse files Browse the repository at this point in the history
…s the autocompletion menu. (#363)

* Add autocompletion to EuiCodeEditor example.
* Don't exit EuiCodeEditor when the ESCAPE key is being used to dismiss the autocompletion menu.
  • Loading branch information
cjcenizal authored Feb 2, 2018
1 parent 033227e commit 240c2d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src-docs/src/views/code_editor/code_editor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { Component } from 'react';

import 'brace/mode/less';
import 'brace/theme/github';
import 'brace/mode/javascript';
import 'brace/snippets/javascript';
import 'brace/ext/language_tools';

import {
EuiCodeEditor,
Expand All @@ -19,12 +21,17 @@ export default class extends Component {
render() {
return (
<EuiCodeEditor
mode="less"
mode="javascript"
theme="github"
width="100%"
value={this.state.value}
onChange={this.onChange}
setOptions={{ fontSize: '14px' }}
setOptions={{
fontSize: '14px',
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
}}
onBlur={() => { console.log('blur'); }}
/>
);
Expand Down
12 changes: 8 additions & 4 deletions src/components/code_editor/code_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ export class EuiCodeEditor extends Component {

onKeydownAce = (ev) => {
if (ev.keyCode === keyCodes.ESCAPE) {
ev.preventDefault();
ev.stopPropagation();
this.stopEditing();
this.editorHint.focus();
// If the autocompletion context menu is open then we want to let ESCAPE close it but
// **not** exit out of editing mode.
if (!this.aceEditor.editor.completer) {
ev.preventDefault();
ev.stopPropagation();
this.stopEditing();
this.editorHint.focus();
}
}
}

Expand Down

0 comments on commit 240c2d6

Please sign in to comment.