An Ember component wrapping Ace editor.
ember install ember-aceSee the application controller in this addon's dummy application for usage examples of many of these options.
value: the string value of the editorupdate(newValue): an action triggered when the value of the editor changesready(editor): an action triggered when the AceEditoris instantiated
mode: the mode for the editor to operate in, either a string (e.g."ace/mode/javascript") or aModeinstancetheme: the color scheme to be used (e.g."ace/theme/chaos");useSoftTabs: a boolean indicating whether to use spaces for indentationtabSize: the number of spaces a tab representsuseWrapMode: a boolean indicating whether to wrap long lineshighlightActiveLine: a boolean indicating whether the active line should be highlightedshowPrintMargin: a boolean indicating whether a line indicating the print margin should be shownprintMarginColumn: a boolean indicating what column the print margin (if enabled) should appear atshowInvisibles: a boolean indicating whether to show invisible charactersreadOnly: a boolean indicating whether the editor is locked to the usershowLineNumbers: a boolean indicating if line numbers are shown in the left gutter. Default to true.
lines: the number of lines the editor should show (shorthand for setting bothminLinesandmaxLines)minLines: the minimum number of lines the editor should containmaxLines: the maximum number of lines the editor should expand to
enableDefaultAutocompletion: a boolean indicating whether to enable Ace's default completions (which basically just look for similar words within the existing document)enableLiveAutocompletion: whether to automatically trigger completion, or require the user to make an explicit gesture (typicallyCtrl + Space)suggestCompletions: an action to supply your own completion suggestions (see below for details)
overlays: an array of objects describing notices that should be overlaid on the editor, each containing the following keys:type: one oferror,warningorinfo, which will impact the icon that appears on the overlaid rowtext: text for a tooltip that will appear when the user hovers the overlay iconrange: anAce.Rangeinstance denoting the section of text to be markedclass: a string containing any classes that should be added to the element(s) overlaying the marked text (anember-ace-${type}class will automatically be applied)
Note that overlays is actually shorthand for configuring the following two options individually:
markers: an array of text marker objects, each containing the following keys:class: the class name that should be applied to the element(s) overlaying the marked textrange: anAce.Rangeinstance denoting the section of text to be markedinFront: a boolean (defaulttrue) indicating whether the marker should be in front of or behind the text layer
annotations: an array of line annotation objects, each of which contains the following keys:type: one oferror,warningorinforow: the zero-based index of the row the annotation should appear ontext: the text to appear when the annotation is hovered
Build configuration can be specified in an ace key in ember-cli-build.js:
new EmberApp(defaults, {
ace: {
themes: ['ambiance', 'chaos'],
modes: ['javascript'],
workers: ['javascript']
}
});For each of the following types, you may specify an array of names to be included in your Ace build (as above).
modes: syntax highlighting and editor behaviors for different languages (see all)workers: background workers to perform more expensive processing available for some modes (see all, intermingled with modes)themes: color schemes for the editor (see all)exts: editor extensions, like spellcheck and Emmet abbreviations (see all)keybindings: common keybindings from editors like Emacs and Vim (see all)
If you need to customize the worker path you can specify workerPath in the build configuration.
new EmberApp(defaults, {
ace: {
...
workerPath: '/my/custom/worker-path'
}
});Note: completion requires the language tools extension to be included. You'll need to set exts: ['language_tools'] in your configuration in order for autocomplete to work.
To enable custom autocomplete suggestions in your editor, you can implement the suggestCompletions action. The action will receive four arguments:
editor: an Ace Editor instancesession: an Ace EditSession instanceposition: a hash withrowandcolumnindicating where the cursor is in the documentprefix: the leading characters the user entered before triggering completion
The action is expected to return an array (or a promise for one) containing objects with the following keys:
value: the core 'value' this suggestion is considered to hold (note that any suggestions whose value doesn't include the given prefix are filtered out by Ace)score: a numeric value indicating how good a match this suggestion is (optional; higher is better)caption: the text that will appear in the dropdown representing this suggestion (defaults tovalue)meta: supplemental information that will appear on the righthand side in the dropdown for this suggestion (optional)snippet: a string representing what will actually appear in the editor if this suggestion is selected (defaults tovalue)
Each suggestion may also have a rendered tooltip providing arbitrary additional information about that suggestion (e.g. function documentation). To do so, you can use the completion-tooltip contextual component: