浏览代码

Merge pull request #13530 from grafana/davkal/13485-cursor-suggestions

Explore: reset typeahead on cursor move
Torkel Ödegaard 7 年之前
父节点
当前提交
1da352822a
共有 1 个文件被更改,包括 9 次插入3 次删除
  1. 9 3
      public/app/features/explore/QueryField.tsx

+ 9 - 3
public/app/features/explore/QueryField.tsx

@@ -179,15 +179,21 @@ class QueryField extends React.PureComponent<TypeaheadFieldProps, TypeaheadField
   }
 
   onChange = ({ value }) => {
-    const changed = value.document !== this.state.value.document;
+    const textChanged = value.document !== this.state.value.document;
+
+    // Control editor loop, then pass text change up to parent
     this.setState({ value }, () => {
-      if (changed) {
+      if (textChanged) {
         this.handleChangeValue();
       }
     });
 
-    if (changed) {
+    // Show suggest menu on text input
+    if (textChanged && value.selection.isCollapsed) {
+      // Need one paint to allow DOM-based typeahead rules to work
       window.requestAnimationFrame(this.handleTypeahead);
+    } else {
+      this.resetTypeahead();
     }
   };