Skip to content

Commit

Permalink
Example of how to add a custom mode
Browse files Browse the repository at this point in the history
  • Loading branch information
securingsincity committed May 28, 2017
1 parent f041342 commit c5fa55e
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,39 @@ Add the following line

`import 'brace/ext/searchbox';`

before introducing the component and it will add the search box.
before introducing the component and it will add the search box.

## How do I add a custom mode?

1. Create my custom mode class (pure ES6 code)
2. Initialize the component with an existing mode name (such as "sql")
3. Use the `componentDidMount` function and call `session.setMode` with an instance of my custom mode.

My custom mode is:
```javascript
export default class CustomSqlMode extends ace.acequire('ace/mode/text').Mode {
constructor(){
super();
// Your code goes here
}
}
```

And my react-ace code looks like:
```javascript
render() {
return <div>
<AceEditor
ref="aceEditor"
mode="sql" // Default value since this props must be set.
theme="chrome" // Default value since this props must be set.
/>
</div>;
}

componentDidMount() {
const customMode = new CustomSqlMode();
this.refs.aceEditor.editor.getSession().setMode(customMode);
}
```

0 comments on commit c5fa55e

Please sign in to comment.