Просмотр исходного кода

More work on variable dropdown

Torkel Ödegaard 10 лет назад
Родитель
Сommit
a433e0e79c

+ 20 - 7
public/app/directives/variableValueSelect.js

@@ -115,7 +115,10 @@ function (angular, app, _) {
               scope.moveHighlight(-1);
             }
             if (evt.keyCode === 13) {
-              scope.optionSelected(scope.search.options[scope.highlightIndex], {});
+              scope.optionSelected(scope.search.options[scope.highlightIndex], {}, true, false);
+            }
+            if (evt.keyCode === 32) {
+              scope.optionSelected(scope.search.options[scope.highlightIndex], {}, false, false);
             }
           };
 
@@ -123,24 +126,34 @@ function (angular, app, _) {
             scope.highlightIndex = (scope.highlightIndex + direction) % scope.search.options.length;
           };
 
-          scope.optionSelected = function(option, event) {
+          scope.optionSelected = function(option, event, commitChange, excludeOthers) {
+            if (!option) { return; }
+
             option.selected = !option.selected;
 
-            var hideAfter = false;
+            commitChange = commitChange || false;
+            excludeOthers = excludeOthers || false;
+
             var setAllExceptCurrentTo = function(newValue) {
               _.each(scope.options, function(other) {
                 if (option !== other) { other.selected = newValue; }
               });
             };
 
-            if (option.text === 'All') {
+            // commit action (enter key), should not deselect it
+            if (commitChange) {
+              option.selected = true;
+            }
+
+            if (option.text === 'All' || excludeOthers) {
               setAllExceptCurrentTo(false);
+              commitChange = true;
             }
             else if (!variable.multi) {
               setAllExceptCurrentTo(false);
-              hideAfter = true;
+              commitChange = true;
             } else if (event.ctrlKey || event.metaKey || event.shiftKey) {
-              hideAfter = true;
+              commitChange = true;
               setAllExceptCurrentTo(false);
             }
 
@@ -168,7 +181,7 @@ function (angular, app, _) {
               variable.current.value = selected[0].value;
             }
 
-            if (hideAfter) {
+            if (commitChange) {
               scope.switchToLink();
             }
           };

+ 1 - 0
public/app/features/templating/editorCtrl.js

@@ -82,6 +82,7 @@ function (angular, _) {
     };
 
     $scope.update = function() {
+      $scope.current.tags = [];
       if ($scope.isValid()) {
         $scope.runQuery().then(function() {
           $scope.reset();