浏览代码

Replace uses of scrollIfNeeded with phosphor function

Steven Silvester 8 年之前
父节点
当前提交
4f8d12863a
共有 3 个文件被更改,包括 16 次插入57 次删除
  1. 5 19
      src/console/widget.ts
  2. 5 19
      src/filebrowser/listing.ts
  3. 6 19
      src/notebook/completion/widget.ts

+ 5 - 19
src/console/widget.ts

@@ -17,6 +17,10 @@ import {
   Message
 } from 'phosphor/lib/core/messaging';
 
+import {
+  scrollIntoViewIfNeeded
+} from 'phosphor/lib/dom/query';
+
 import {
   PanelLayout
 } from 'phosphor/lib/ui/panel';
@@ -323,7 +327,7 @@ class ConsoleWidget extends Widget {
    */
   protected onUpdateRequest(msg: Message): void {
     let prompt = this.prompt;
-    Private.scrollIfNeeded(this.parent.node, prompt.node);
+    scrollIntoViewIfNeeded(this.parent.node, prompt.node);
   }
 
   /**
@@ -454,24 +458,6 @@ namespace ConsoleWidget {
  * A namespace for console widget private data.
  */
 namespace Private {
-  /**
-   * Scroll an element into view if needed.
-   *
-   * @param area - The scroll area element.
-   *
-   * @param elem - The element of interest.
-   */
-  export
-  function scrollIfNeeded(area: HTMLElement, elem: HTMLElement): void {
-    let ar = area.getBoundingClientRect();
-    let er = elem.getBoundingClientRect();
-    if (er.top < ar.top - 10) {
-      area.scrollTop -= ar.top - er.top + 10;
-    } else if (er.bottom > ar.bottom + 10) {
-      area.scrollTop += er.bottom - ar.bottom + 10;
-    }
-  }
-
   /**
    * Jump to the bottom of a node.
    *

+ 5 - 19
src/filebrowser/listing.ts

@@ -21,6 +21,10 @@ import {
   Drag, IDragEvent
 } from 'phosphor/lib/dom/dragdrop';
 
+import {
+  scrollIntoViewIfNeeded
+} from 'phosphor/lib/dom/query';
+
 import {
   Widget
 } from 'phosphor/lib/ui/widget';
@@ -1207,7 +1211,7 @@ class DirListing extends Widget {
     }
     let name = items[index].name;
     this._selection[name] = true;
-    Private.scrollIfNeeded(this.contentNode, this._items[index]);
+    scrollIntoViewIfNeeded(this.contentNode, this._items[index]);
     this._isCut = false;
   }
 
@@ -1637,22 +1641,4 @@ namespace Private {
     }
     return output;
   }
-
-  /**
-   * Scroll an element into view if needed.
-   *
-   * @param area - The scroll area element.
-   *
-   * @param elem - The element of interest.
-   */
-  export
-  function scrollIfNeeded(area: HTMLElement, elem: HTMLElement): void {
-    let ar = area.getBoundingClientRect();
-    let er = elem.getBoundingClientRect();
-    if (er.top < ar.top) {
-      area.scrollTop -= ar.top - er.top;
-    } else if (er.bottom > ar.bottom) {
-      area.scrollTop += er.bottom - ar.bottom;
-    }
-  }
 }

+ 6 - 19
src/notebook/completion/widget.ts

@@ -9,6 +9,10 @@ import {
   defineSignal, ISignal
 } from 'phosphor/lib/core/signaling';
 
+import {
+  scrollIntoViewIfNeeded
+} from 'phosphor/lib/dom/query';
+
 import {
   Widget
 } from 'phosphor/lib/ui/widget';
@@ -17,6 +21,7 @@ import {
   ICompletionModel, ICompletionItem
 } from './model';
 
+
 /**
  * The class name added to completion menu widgets.
  */
@@ -278,7 +283,7 @@ class CompletionWidget extends Widget {
     }
     active = items[this._activeIndex] as HTMLElement;
     active.classList.add(ACTIVE_CLASS);
-    Private.scrollIfNeeded(this.node, active);
+    scrollIntoViewIfNeeded(this.node, active);
   }
 
   /**
@@ -568,22 +573,4 @@ namespace Private {
       event.shiftKey ||
       event.metaKey;
   }
-
-  /**
-   * Scroll an element into view if needed.
-   *
-   * @param area - The scroll area element.
-   *
-   * @param elem - The element of interest.
-   */
-  export
-  function scrollIfNeeded(area: HTMLElement, elem: HTMLElement): void {
-    let ar = area.getBoundingClientRect();
-    let er = elem.getBoundingClientRect();
-    if (er.top < ar.top - 10) {
-      area.scrollTop -= ar.top - er.top + 10;
-    } else if (er.bottom > ar.bottom + 10) {
-      area.scrollTop += er.bottom - ar.bottom + 10;
-    }
-  }
 }