mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ace: minor refactor
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
* Params:
|
* Params:
|
||||||
* content: Editor content.
|
* content: Editor content.
|
||||||
* onChange: Function called on content change (invoked on editor blur, ctrl+enter, not on every change).
|
* onChange: Function called on content change (invoked on editor blur, ctrl+enter, not on every change).
|
||||||
|
* getCompleter: Function returned external completer. Completer is an object implemented getCompletions() method,
|
||||||
|
* see Prometheus Data Source implementation for details.
|
||||||
*
|
*
|
||||||
* Some Ace editor options available via data-* attributes:
|
* Some Ace editor options available via data-* attributes:
|
||||||
* data-lang-mode - Language mode (text, sql, javascript, etc.). Default is 'text'.
|
* data-lang-mode - Language mode (text, sql, javascript, etc.). Default is 'text'.
|
||||||
@@ -17,6 +19,8 @@
|
|||||||
* data-max-lines - Max editor height in lines. Editor grows automatically from 1 to maxLines.
|
* data-max-lines - Max editor height in lines. Editor grows automatically from 1 to maxLines.
|
||||||
* data-show-gutter - Show gutter (contains line numbers and additional info).
|
* data-show-gutter - Show gutter (contains line numbers and additional info).
|
||||||
* data-tab-size - Tab size, default is 2.
|
* data-tab-size - Tab size, default is 2.
|
||||||
|
* data-behaviours-enabled - Specifies whether to use behaviors or not. "Behaviors" in this case is the auto-pairing of
|
||||||
|
* special characters, like quotation marks, parenthesis, or brackets.
|
||||||
*
|
*
|
||||||
* Keybindings:
|
* Keybindings:
|
||||||
* Ctrl-Enter (Command-Enter): run onChange() function
|
* Ctrl-Enter (Command-Enter): run onChange() function
|
||||||
@@ -32,6 +36,7 @@ const DEFAULT_THEME = "grafana-dark";
|
|||||||
const DEFAULT_MODE = "text";
|
const DEFAULT_MODE = "text";
|
||||||
const DEFAULT_MAX_LINES = 10;
|
const DEFAULT_MAX_LINES = 10;
|
||||||
const DEFAULT_TAB_SIZE = 2;
|
const DEFAULT_TAB_SIZE = 2;
|
||||||
|
const DEFAULT_BEHAVIOURS = true;
|
||||||
|
|
||||||
const GRAFANA_MODULES = ['mode-prometheus', 'snippets-prometheus', 'theme-grafana-dark'];
|
const GRAFANA_MODULES = ['mode-prometheus', 'snippets-prometheus', 'theme-grafana-dark'];
|
||||||
const GRAFANA_MODULE_BASE = "public/app/core/components/code_editor/";
|
const GRAFANA_MODULE_BASE = "public/app/core/components/code_editor/";
|
||||||
@@ -67,6 +72,7 @@ function link(scope, elem, attrs) {
|
|||||||
let showGutter = attrs.showGutter !== undefined;
|
let showGutter = attrs.showGutter !== undefined;
|
||||||
let theme = attrs.theme || DEFAULT_THEME;
|
let theme = attrs.theme || DEFAULT_THEME;
|
||||||
let tabSize = attrs.tabSize || DEFAULT_TAB_SIZE;
|
let tabSize = attrs.tabSize || DEFAULT_TAB_SIZE;
|
||||||
|
let behavioursEnabled = attrs.behavioursEnabled ? attrs.behavioursEnabled === 'true' : DEFAULT_BEHAVIOURS;
|
||||||
|
|
||||||
// Initialize editor
|
// Initialize editor
|
||||||
let aceElem = elem.get(0);
|
let aceElem = elem.get(0);
|
||||||
@@ -77,6 +83,7 @@ function link(scope, elem, attrs) {
|
|||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
showGutter: showGutter,
|
showGutter: showGutter,
|
||||||
tabSize: tabSize,
|
tabSize: tabSize,
|
||||||
|
behavioursEnabled: behavioursEnabled,
|
||||||
highlightActiveLine: false,
|
highlightActiveLine: false,
|
||||||
showPrintMargin: false,
|
showPrintMargin: false,
|
||||||
autoScrollEditorIntoView: true // this is needed if editor is inside scrollable page
|
autoScrollEditorIntoView: true // this is needed if editor is inside scrollable page
|
||||||
@@ -147,8 +154,6 @@ function link(scope, elem, attrs) {
|
|||||||
codeEditor.completers.push(scope.getCompleter());
|
codeEditor.completers.push(scope.getCompleter());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
codeEditor.setBehavioursEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setThemeMode(theme) {
|
function setThemeMode(theme) {
|
||||||
|
|||||||
Reference in New Issue
Block a user