浏览代码

[editor] Emit active statement changed event from the AceEditor component

Johan Ahlen 4 年之前
父节点
当前提交
fbde7fb931

+ 11 - 1
desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceEditor.vue

@@ -39,7 +39,7 @@
   import { attachPredictTypeahead } from './acePredict';
   import AceAutocomplete from './autocomplete/AceAutocomplete.vue';
   import AceGutterHandler from './AceGutterHandler';
-  import AceLocationHandler from './AceLocationHandler';
+  import AceLocationHandler, { ACTIVE_STATEMENT_CHANGED_EVENT } from './AceLocationHandler';
   import { formatSql } from 'apps/editor/api';
   import Executor from 'apps/editor/execution/executor';
   import SubscriptionTracker from 'components/utils/SubscriptionTracker';
@@ -103,6 +103,7 @@
       }
     },
     emits: [
+      'active-statement-changed',
       'value-changed',
       'create-new-doc',
       'save-doc',
@@ -151,6 +152,15 @@
       });
       this.subTracker.addDisposable(this.aceLocationHandler);
 
+      this.subTracker.subscribe(
+        ACTIVE_STATEMENT_CHANGED_EVENT,
+        (details: ActiveStatementChangedEventDetails) => {
+          if (this.id === details.id) {
+            this.$emit('active-statement-changed', details);
+          }
+        }
+      );
+
       const aceGutterHandler = new AceGutterHandler({
         editor: editor,
         editorId: this.id,

+ 2 - 11
desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceLocationHandler.ts

@@ -17,6 +17,7 @@
 import { Ace } from 'ext/ace';
 import ace from 'ext/aceHelper';
 
+import { ActiveStatementChangedEventDetails } from './types';
 import Executor from 'apps/editor/execution/executor';
 import DataCatalogEntry, { TableSourceMeta } from 'catalog/DataCatalogEntry';
 import SubscriptionTracker, { Disposable } from 'components/utils/SubscriptionTracker';
@@ -44,16 +45,6 @@ import {
 } from 'sql/sqlWorkerHandler';
 import { getFromLocalStorage } from 'utils/storageUtils';
 
-export interface ActiveStatementChangedEvent {
-  id: string;
-  editorChangeTime: number;
-  activeStatementIndex: number;
-  totalStatementCount: number;
-  precedingStatements: ParsedSqlStatement[];
-  activeStatement: ParsedSqlStatement;
-  selectedStatements: ParsedSqlStatement[];
-  followingStatements: ParsedSqlStatement[];
-}
 export const REFRESH_STATEMENT_LOCATIONS_EVENT = 'editor.refresh.statement.locations';
 export const ACTIVE_STATEMENT_CHANGED_EVENT = 'editor.active.statement.changed';
 export const CURSOR_POSITION_CHANGED_EVENT = 'editor.cursor.position.changed';
@@ -702,7 +693,7 @@ export default class AceLocationHandler implements Disposable {
       selectedStatements.push(this.activeStatement);
     }
 
-    huePubSub.publish(ACTIVE_STATEMENT_CHANGED_EVENT, <ActiveStatementChangedEvent>{
+    huePubSub.publish(ACTIVE_STATEMENT_CHANGED_EVENT, <ActiveStatementChangedEventDetails>{
       id: this.editorId,
       editorChangeTime: this.lastKnownStatements.editorChangeTime,
       activeStatementIndex: statementIndex,

+ 12 - 0
desktop/core/src/desktop/js/apps/editor/components/aceEditor/types.ts

@@ -0,0 +1,12 @@
+import { StatementDetails } from '../../../../parse/types';
+
+export interface ActiveStatementChangedEvent extends Event {
+  detail: ActiveStatementChangedEventDetails;
+}
+
+export interface ActiveStatementChangedEventDetails extends StatementDetails {
+  id: string;
+  editorChangeTime: number;
+  activeStatementIndex: number;
+  totalStatementCount: number;
+}