From ce0de35a6c00942ba0ab23489f674d136270d54b Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 8 Sep 2017 01:04:32 +0900 Subject: [PATCH 1/3] set give focus in code editor --- public/app/core/components/code_editor/code_editor.ts | 3 +++ .../plugins/datasource/prometheus/partials/query.editor.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 151ebffab5d..826d62eaade 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -110,6 +110,9 @@ function link(scope, elem, attrs) { elem.addClass("gf-code-editor"); let textarea = elem.find("textarea"); textarea.addClass('gf-form-input'); + if (attrs.giveFocus) { + textarea.attr('give-focus', attrs.giveFocus); + } // Event handlers editorSession.on('change', (e) => { diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 5140c9e7bbd..9b2aa533743 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -2,7 +2,7 @@
+ get-completer="ctrl.getCompleter()" data-mode="prometheus" give-focus="ctrl.target.refId == 'A'">
From d971eddc7a316fb109705bd9bdf0ad869f9498b9 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 8 Sep 2017 11:49:10 +0900 Subject: [PATCH 2/3] copy from give-focus --- public/app/core/components/code_editor/code_editor.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index 826d62eaade..ec10b7a477b 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -111,7 +111,14 @@ function link(scope, elem, attrs) { let textarea = elem.find("textarea"); textarea.addClass('gf-form-input'); if (attrs.giveFocus) { - textarea.attr('give-focus', attrs.giveFocus); + setTimeout(function () { + textarea.focus(); + var domEl = textarea[0]; + if (domEl.setSelectionRange) { + var pos = textarea.val().length * 2; + domEl.setSelectionRange(pos, pos); + } + }, 200); } // Event handlers From 7c566a6539720e46626bb61df57662b60cd433da Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 8 Sep 2017 12:33:36 +0900 Subject: [PATCH 3/3] fix to focus first query --- public/app/core/components/code_editor/code_editor.ts | 3 ++- .../plugins/datasource/prometheus/partials/query.editor.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/app/core/components/code_editor/code_editor.ts b/public/app/core/components/code_editor/code_editor.ts index ec10b7a477b..0ceb21d0335 100644 --- a/public/app/core/components/code_editor/code_editor.ts +++ b/public/app/core/components/code_editor/code_editor.ts @@ -110,7 +110,7 @@ function link(scope, elem, attrs) { elem.addClass("gf-code-editor"); let textarea = elem.find("textarea"); textarea.addClass('gf-form-input'); - if (attrs.giveFocus) { + if (scope.focus) { setTimeout(function () { textarea.focus(); var domEl = textarea[0]; @@ -209,6 +209,7 @@ export function codeEditorDirective() { template: editorTemplate, scope: { content: "=", + focus: "=", onChange: "&", getCompleter: "&" }, diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 9b2aa533743..d35f9f9c14c 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -2,7 +2,7 @@
+ get-completer="ctrl.getCompleter()" data-mode="prometheus" focus="ctrl.target.refId == 'A'">