Browse Source

[codeeditor] Added revealPosition/Selection methods

akosyakov 8 năm trước cách đây
mục cha
commit
e5f7882e85
2 tập tin đã thay đổi với 36 bổ sung7 xóa
  1. 18 3
      src/codeeditor/editor.ts
  2. 18 4
      src/codemirror/editor.ts

+ 18 - 3
src/codeeditor/editor.ts

@@ -149,6 +149,9 @@ namespace CodeEditor {
 
     /**
      * A mime type of the model.
+     * 
+     * #### Notes
+     * It is never `null`, the default mime type is `text/plain`.
      */
     mimeType: string;
 
@@ -274,9 +277,14 @@ namespace CodeEditor {
     setSize(size: IDimension | null): void;
 
     /**
-     * Scroll the given cursor position into view.
+     * Reveals the given position in the editor.
+     */
+    revealPosition(position: IPosition): void;
+
+    /**
+     * Reveals the given selection in the editor.
      */
-    scrollIntoView(pos: IPosition, margin?: number): void;
+    revealSelection(selection: ITextSelection): void;
 
     /**
      * Get the window coordinates given a cursor position.
@@ -557,7 +565,14 @@ class TextAreaEditor extends Widget implements CodeEditor.IEditor {
   /**
    * Scroll the given cursor position into view.
    */
-  scrollIntoView(pos: CodeEditor.IPosition, margin?: number): void {
+  revealPosition(pos: CodeEditor.IPosition): void {
+    // set node scroll position here.
+  }
+
+  /**
+   * Scroll the given cursor position into view.
+   */
+  revealSelection(selection: CodeEditor.ITextSelection): void {
     // set node scroll position here.
   }
 

+ 18 - 4
src/codemirror/editor.ts

@@ -126,17 +126,31 @@ class CodeMirrorEditor implements CodeEditor.IEditor {
   }
 
   /**
-   * Scroll the given cursor position into view.
+   * Reveal the given position in the editor.
    */
-  scrollIntoView(pos: CodeEditor.IPosition, margin?: number): void {
-    // set node scroll position here.
+  revealPosition(position: CodeEditor.IPosition): void {
+    this._editor.scrollIntoView({
+      line: position.line,
+      ch: position.column
+    });
+  }
+
+  /**
+   * Reveal the given selection in the editor.
+   */
+  revealSelection(selection: CodeEditor.ITextSelection): void {
+    const start = this.model.getPositionAt(selection.start);
+    const from = { line: start.line, ch: start.column };
+    const end = this.model.getPositionAt(selection.end);
+    const to = { line: end.line, ch: end.column };
+    this._editor.scrollIntoView({ from, to }, undefined);
   }
 
   /**
    * Get the window coordinates given a cursor position.
    */
   getCoords(position: CodeEditor.IPosition): CodeEditor.ICoords {
-    // more css measurements required
+    // FIXME: more css measurements required
     return void 0;
   }