浏览代码

wip completer

Steven Silvester 8 年之前
父节点
当前提交
eb8c7e13bc
共有 2 个文件被更改,包括 150 次插入144 次删除
  1. 1 0
      src/completer/handler.ts
  2. 149 144
      src/completer/model.ts

+ 1 - 0
src/completer/handler.ts

@@ -196,6 +196,7 @@ class CellCompleterHandler implements IDisposable {
   private _pending = 0;
 }
 
+
 /**
  * A namespace for cell completer handler statics.
  */

+ 149 - 144
src/completer/model.ts

@@ -22,151 +22,15 @@ import {
 } from '../notebook/cells/editor';
 
 
-/**
- * A filtered completion menu matching result.
- */
-interface ICompletionMatch {
-  /**
-   * The raw text of a completion match.
-   */
-  raw: string;
-
-  /**
-   * A score which indicates the strength of the match.
-   *
-   * A lower score is better. Zero is the best possible score.
-   */
-  score: number;
-
-  /**
-   * The highlighted text of a completion match.
-   */
-  text: string;
-}
-
-
-/**
- * An object describing a completion option injection into text.
- */
-export
-interface ICompletionPatch {
-  /**
-   * The patch text.
-   */
-  text: string;
-
-  /**
-   * The position in the text where cursor should be after patch application.
-   */
-  position: number;
-}
-
-
-/**
- * A completer menu item.
- */
-export
-interface ICompleterItem {
-  /**
-   * The highlighted, marked up text of a visible completer item.
-   */
-  text: string;
-
-  /**
-   * The raw text of a visible completer item.
-   */
-  raw: string;
-}
-
-
-/**
- * A cursor span.
- */
-export
-interface ICursorSpan extends JSONObject {
-  /**
-   * The start position of the cursor.
-   */
-  start: number;
-
-  /**
-   * The end position of the cursor.
-   */
-  end: number;
-}
-
-
-/**
- * The data model backing a code completer widget.
- */
-export
-interface ICompleterModel extends IDisposable {
-  /**
-   * A signal emitted when state of the completer menu changes.
-   */
-  stateChanged: ISignal<ICompleterModel, void>;
-
-  /**
-   * The current text change details.
-   */
-  current: ITextChange;
-
-  /**
-   * The cursor details that the API has used to return matching options.
-   */
-  cursor: ICursorSpan;
-
-  /**
-   * A flag that is true when the model value was modified by a subset match.
-   */
-  subsetMatch: boolean;
-
-  /**
-   * The list of visible items in the completer menu.
-   */
-  items: ICompleterItem[];
-
-  /**
-   * The unfiltered list of all available options in a completer menu.
-   */
-  options: string[];
-
-  /**
-   * The original completer request details.
-   */
-  original: ICompletionRequest;
-
-  /**
-   * The query against which items are filtered.
-   */
-  query: string;
-
-  /**
-   * Handle a text change.
-   */
-  handleTextChange(change: ITextChange): void;
-
-  /**
-   * Create a resolved patch between the original state and a patch string.
-   */
-  createPatch(patch: string): ICompletionPatch;
-
-  /**
-   * Reset the state of the model.
-   */
-  reset(): void;
-}
-
-
 /**
  * An implementation of a completer model.
  */
 export
-class CompleterModel implements ICompleterModel {
+class CompleterModel implements CompleterModel.IModel {
   /**
    * A signal emitted when state of the completer menu changes.
    */
-  stateChanged: ISignal<ICompleterModel, void>;
+  readonly stateChanged: ISignal<this, void>;
 
   /**
    * The list of visible items in the completer menu.
@@ -174,7 +38,7 @@ class CompleterModel implements ICompleterModel {
    * #### Notes
    * This is a read-only property.
    */
-  get items(): ICompleterItem[] {
+  get items(): CompleterModel.IItem[] {
     return this._filter();
   }
 
@@ -266,10 +130,10 @@ class CompleterModel implements ICompleterModel {
   /**
    * The cursor details that the API has used to return matching options.
    */
-  get cursor(): ICursorSpan {
+  get cursor(): CompleterModel.ICursorSpan {
     return this._cursor;
   }
-  set cursor(newValue: ICursorSpan) {
+  set cursor(newValue: CompleterModel.ICursorSpan) {
     // Original request must always be set before a cursor change. If it isn't
     // the model fails silently.
     if (!this.original) {
@@ -348,7 +212,7 @@ class CompleterModel implements ICompleterModel {
    *
    * @returns A patched text change or null if original value did not exist.
    */
-  createPatch(patch: string): ICompletionPatch {
+  createPatch(patch: string): CompleterModel.IPatch {
     let original = this._original;
     let cursor = this._cursor;
 
@@ -377,7 +241,7 @@ class CompleterModel implements ICompleterModel {
   /**
    * Apply the query to the complete options list to return the matching subset.
    */
-  private _filter(): ICompleterItem[] {
+  private _filter(): CompleterModel.IItem[] {
     let options = this._options || [];
     let query = this._query;
     if (!query) {
@@ -411,7 +275,7 @@ class CompleterModel implements ICompleterModel {
   }
 
   private _current: ITextChange = null;
-  private _cursor: ICursorSpan = null;
+  private _cursor: CompleterModel.ICursorSpan = null;
   private _isDisposed = false;
   private _options: string[] = null;
   private _original: ICompletionRequest = null;
@@ -420,6 +284,147 @@ class CompleterModel implements ICompleterModel {
 }
 
 
+/**
+ * The namespace for the `CompleterModel` class statics.
+ */
+export
+namespace CompleterModel {
+  /**
+   * A filtered completion menu matching result.
+   */
+  interface IMatch {
+    /**
+     * The raw text of a completion match.
+     */
+    raw: string;
+
+    /**
+     * A score which indicates the strength of the match.
+     *
+     * A lower score is better. Zero is the best possible score.
+     */
+    score: number;
+
+    /**
+     * The highlighted text of a completion match.
+     */
+    text: string;
+  }
+
+
+  /**
+   * An object describing a completion option injection into text.
+   */
+  export
+  interface IPatch {
+    /**
+     * The patch text.
+     */
+    text: string;
+
+    /**
+     * The position in the text where cursor should be after patch application.
+     */
+    position: number;
+  }
+
+
+  /**
+   * A completer menu item.
+   */
+  export
+  interface IItem {
+    /**
+     * The highlighted, marked up text of a visible completer item.
+     */
+    text: string;
+
+    /**
+     * The raw text of a visible completer item.
+     */
+    raw: string;
+  }
+
+
+  /**
+   * A cursor span.
+   */
+  export
+  interface ICursorSpan extends JSONObject {
+    /**
+     * The start position of the cursor.
+     */
+    start: number;
+
+    /**
+     * The end position of the cursor.
+     */
+    end: number;
+  }
+
+
+  /**
+   * The data model backing a code completer widget.
+   */
+  export
+  interface IModel extends IDisposable {
+    /**
+     * A signal emitted when state of the completer menu changes.
+     */
+    readonly stateChanged: ISignal<IModel, void>;
+
+    /**
+     * The current text change details.
+     */
+    current: ITextChange;
+
+    /**
+     * The cursor details that the API has used to return matching options.
+     */
+    cursor: ICursorSpan;
+
+    /**
+     * A flag that is true when the model value was modified by a subset match.
+     */
+    subsetMatch: boolean;
+
+    /**
+     * The list of visible items in the completer menu.
+     */
+    items: IItem[];
+
+    /**
+     * The unfiltered list of all available options in a completer menu.
+     */
+    options: string[];
+
+    /**
+     * The original completer request details.
+     */
+    original: ICompletionRequest;
+
+    /**
+     * The query against which items are filtered.
+     */
+    query: string;
+
+    /**
+     * Handle a text change.
+     */
+    handleTextChange(change: ITextChange): void;
+
+    /**
+     * Create a resolved patch between the original state and a patch string.
+     */
+    createPatch(patch: string): IPatch;
+
+    /**
+     * Reset the state of the model.
+     */
+    reset(): void;
+  }
+}
+
 // Define the signals for the `CompleterModel` class.
 defineSignal(CompleterModel.prototype, 'stateChanged');