Explorar o código

HUE-7732 Support CTRL + S when inside a variable input

jdesjean %!s(int64=7) %!d(string=hai) anos
pai
achega
d5b32ce

+ 10 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -2015,6 +2015,16 @@ var EditorViewModel = (function() {
         self.execute();
       }
     };
+
+    self.onKeydownInVariable = function (context, e) {
+      if ((e.ctrlKey || e.metaKey) && e.which === 13) { // Ctrl-enter
+        self.ace().commands.commands['execute'].exec();
+      } else if ((e.ctrlKey || e.metaKey) && e.which === 83) { // Ctrl-s
+        self.ace().commands.commands['save'].exec();
+        e.preventDefault(); // Prevent browser page save dialog
+      }
+      return true;
+    };
   };
 
   var Session = function(vm, session) {

+ 3 - 3
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1199,13 +1199,13 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
         <div class="input-prepend margin-top-10">
           <span class="muted add-on" data-bind="text: name"></span>
           <!-- ko if: meta.type() == 'text' -->
-          <input class="input-medium" type="text" data-bind="value: value, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keydown': function (context, e){ if ((e.ctrlKey || e.metaKey) && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }">
+          <input class="input-medium" type="text" data-bind="value: value, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, event: { 'keydown': $parent.onKeydownInVariable }">
           <!-- /ko -->
           <!-- ko if: meta.type() == 'select' && !('options' in document.createElement('datalist')) -->
-          <select data-bind="options: meta.options(), optionsText: 'text', optionsValue:'value', value: value, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, event: { 'keydown': function (context, e){ if ((e.ctrlKey || e.metaKey) && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }"/>
+          <select data-bind="options: meta.options(), optionsText: 'text', optionsValue:'value', value: value, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, event: { 'keydown': $parent.onKeydownInVariable }"/>
           <!-- /ko -->
           <!-- ko if: meta.type() == 'select' && 'options' in document.createElement('datalist') -->
-          <input list="input-medium" type="text" data-bind="datalist: { options: meta.options(), optionsText: 'text', optionsValue: 'value', value: value }, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, event: { 'keydown': function (context, e){ if ((e.ctrlKey || e.metaKey) && e.which === 13) { $parent.ace().commands.commands['execute'].exec(); } return true; } }" />
+          <input list="input-medium" type="text" data-bind="datalist: { options: meta.options(), optionsText: 'text', optionsValue: 'value', value: value }, valueUpdate: 'afterkeydown', autogrowInput: { minWidth: 150, maxWidth: 270, comfortZone: 15 }, attr: { placeholder: meta.placeholder() || '${ _ko('Variable value') }' }, event: { 'keydown': $parent.onKeydownInVariable }" />
           <!-- /ko -->
         </div>
       </li>