Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
152c4170
Commit
152c4170
authored
Aug 08, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code-editor: onChange option and usage docs
parent
cd16db4d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
5 deletions
+42
-5
public/app/core/components/code_editor/code_editor.ts
+42
-5
No files found.
public/app/core/components/code_editor/code_editor.ts
View file @
152c4170
...
...
@@ -3,13 +3,22 @@
* https://github.com/ajaxorg/ace
*
* Basic usage:
* <code-editor content="ctrl.target.query" data-mode="sql" data-show-gutter></code-editor>
* <code-editor content="ctrl.target.query" on-change="ctrl.panelCtrl.refresh()"
* data-mode="sql" data-show-gutter>
* </code-editor>
*
* Params:
* content: Editor content.
* onChange: Function called on content change (invoked on editor blur, ctrl+enter, not on every change).
*
* Some Ace editor options available via data-* attributes:
* data-lang-mode - Language mode (text, sql, javascript, etc.). Default is 'text'.
* data-theme - Editor theme (eg 'solarized_dark').
* 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).
*
* Keybindings:
* Ctrl-Enter (Command-Enter): run onChange() function
*/
///<reference path="../../../headers/common.d.ts" />
...
...
@@ -65,15 +74,14 @@ function link(scope, elem, attrs) {
codeEditor
.
renderer
.
setPadding
(
10
);
setThemeMode
(
theme
);
setLangMode
(
langMode
);
codeEditor
.
setValue
(
scope
.
content
);
codeEditor
.
clearSelection
();
setEditorContent
(
scope
.
content
);
// Add classes
elem
.
addClass
(
"gf-code-editor"
);
let
textarea
=
elem
.
find
(
"textarea"
);
textarea
.
addClass
(
'gf-form-input'
);
// Event handlers
editorSession
.
on
(
'change'
,
(
e
)
=>
{
scope
.
$apply
(()
=>
{
let
newValue
=
codeEditor
.
getValue
();
...
...
@@ -81,6 +89,29 @@ function link(scope, elem, attrs) {
});
});
// Sync with outer scope - update editor content if model has been changed from outside of directive.
scope
.
$watch
(
'content'
,
(
newValue
,
oldValue
)
=>
{
let
editorValue
=
codeEditor
.
getValue
();
if
(
newValue
!==
editorValue
&&
newValue
!==
oldValue
)
{
scope
.
$$postDigest
(
function
()
{
setEditorContent
(
newValue
);
});
}
});
codeEditor
.
on
(
'blur'
,
()
=>
{
scope
.
onChange
();
});
// Keybindings
codeEditor
.
commands
.
addCommand
({
name
:
'executeQuery'
,
bindKey
:
{
win
:
'Ctrl-Enter'
,
mac
:
'Command-Enter'
},
exec
:
()
=>
{
scope
.
onChange
();
}
});
function
setLangMode
(
lang
)
{
let
aceModeName
=
`ace/mode/
${
lang
}
`
;
fixModuleUrl
(
"mode"
,
lang
);
...
...
@@ -100,6 +131,11 @@ function link(scope, elem, attrs) {
let
aceThemeName
=
`ace/theme/
${
theme
}
`
;
codeEditor
.
setTheme
(
aceThemeName
);
}
function
setEditorContent
(
value
)
{
codeEditor
.
setValue
(
value
);
codeEditor
.
clearSelection
();
}
}
export
function
codeEditorDirective
()
{
...
...
@@ -107,7 +143,8 @@ export function codeEditorDirective() {
restrict
:
'E'
,
template
:
editorTemplate
,
scope
:
{
content
:
"="
content
:
"="
,
onChange
:
"&"
},
link
:
link
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment