Pārlūkot izejas kodu

[editor] Support changing file paths from the context popover in the AceEditor component

Johan Ahlen 5 gadi atpakaļ
vecāks
revīzija
9cb9a2fe97

+ 15 - 1
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/AceEditor.vue

@@ -26,7 +26,7 @@
 <script lang="ts">
   import { CURSOR_POSITION_CHANGED_EVENT } from 'ko/bindings/ace/aceLocationHandler';
   import { INSERT_AT_CURSOR_EVENT } from 'ko/bindings/ace/ko.aceEditor';
-  import { IdentifierChainEntry } from 'parse/types';
+  import { IdentifierChainEntry, ParsedLocation } from 'parse/types';
   import huePubSub from 'utils/huePubSub';
   import AceAutocomplete from './autocomplete/AceAutocomplete.vue';
   import $ from 'jquery';
@@ -312,6 +312,20 @@
       this.subTracker.subscribe('assist.set.manual.visibility', resizeAce);
       this.subTracker.subscribe('split.panel.resized', resizeAce);
 
+      this.subTracker.subscribe(
+        'ace.replace',
+        (data: { text: string; location: ParsedLocation }): void => {
+          const Range = ace.require('ace/range').Range;
+          const range = new Range(
+            data.location.first_line - 1,
+            data.location.first_column - 1,
+            data.location.last_line - 1,
+            data.location.last_column - 1
+          );
+          editor.getSession().getDocument().replace(range, data.text);
+        }
+      );
+
       if (this.initialCursorPosition) {
         editor.moveCursorToPosition(this.initialCursorPosition);
         editor.renderer.scrollCursorIntoView();

+ 2 - 0
desktop/core/src/desktop/js/ext/ace.d.ts

@@ -117,6 +117,7 @@ declare namespace Ace {
   export interface Document {
     createAnchor(position: Position): Anchor;
     createAnchor(x: number, y: number): Anchor;
+    replace(range: Range, text: string): void;
   }
 
   export interface Anchor extends Position {
@@ -140,6 +141,7 @@ declare namespace Ace {
     addGutterDecoration(line: number, clazz: string): void;
     addMarker(range: Range, clazz: string): number;
     doc: Document;
+    getDocument(): Document;
     getLine(row: number): number;
     getTextRange(range: SimpleRange): string;
     getTokenAt(row: number, column: number): HueToken | null;