Example #1
0
  /**
   * Handle a tab key press.
   */
  protected onTabEvent(event: KeyboardEvent, ch: number, line: number): void {
    const editor = this.editor;
    const doc = editor.getDoc();

    // If there is a text selection, no completion requests should be emitted.
    if (doc.getSelection()) {
      return;
    }

    const currentValue = doc.getValue();
    const currentLine = currentValue.split('\n')[line];

    // A completion request signal should only be emitted if the current
    // character or a preceding character is not whitespace.
    //
    // Otherwise, the default tab action of creating a tab character should be
    // allowed to propagate.
    if (!currentLine.substring(0, ch).match(/\S/)) {
      return;
    }

    event.preventDefault();
    event.stopPropagation();
    event.stopImmediatePropagation();

    const chHeight = editor.defaultTextHeight();
    const chWidth = editor.defaultCharWidth();
    const coords = editor.charCoords({ line, ch }, 'page') as ICoords;
    const position = editor.getDoc().indexFromPos({ line, ch });
    let data = {
      line, ch, chHeight, chWidth, coords, position, currentValue
    };
    this.completionRequested.emit(data as ICompletionRequest);
  }
Example #2
0
 private _collapse() {
   this._collapsed = true;
   if (this._content) {
     this._content.hide();
   }
   this.removeClass(COLLAPSE_CLASS_OPEN);
   this.collapseChanged.emit(void 0);
 }
Example #3
0
 private _uncollapse() {
   this._collapsed = false;
   if (this._content) {
     this._content.show();
   }
   this.addClass(COLLAPSE_CLASS_OPEN);
   this.collapseChanged.emit(void 0);
 }
Example #4
0
 /**
  * Handle the DOM events for the widget.
  *
  * @param event - The DOM event sent to the widget.
  *
  * #### Notes
  * This method implements the DOM `EventListener` interface and is
  * called in response to events on the dock panel's node. It should
  * not be called directly by user code.
  */
 handleEvent(event: Event): void {
   switch (event.type) {
   case 'change':
     this.delimiterChanged.emit(this.selectNode.value);
     break;
   default:
     break;
   }
 }
Example #5
0
 /**
  * Parse the content using the model's delimiter.
  *
  * #### Notes
  * This method will always return parsed content that has at most the display
  * limit worth of rows, currently maxing out at 1000 rows.
  */
 parse(): dsv.DSVParsedArray<dsv.DSVRowString> {
   let output = dsv.dsvFormat(this._delimiter).parse(this._content);
   let available = output.length;
   let maximum = DISPLAY_LIMIT;
   if (available > maximum) {
     // Mutate the array instead of slicing in order to conserve memory.
     output.splice(maximum);
     this.maxExceeded.emit({ available, maximum });
   }
   return output;
 }
Example #6
0
 /**
  * Remove the item from the list at the specified index.
  *
  * @param index - The index of the item to remove. This must be
  *   an integer in the range `[0, internal.length)`.
  *
  * @returns The item removed from the list.
  *
  * #### Notes
  * This may be reimplemented by subclasses to customize the behavior.
  */
 protected removeItem(index: number): T {
   let item = this.internal.removeAt(index);
   this.changed.emit({
     type: 'remove',
     newIndex: -1,
     newValue: void 0,
     oldIndex: index,
     oldValue: item,
   });
   return item;
 }
Example #7
0
 /**
  * Add an item to the list at the specified index.
  *
  * @param index - The index at which to add the item. This must be
  *   an integer in the range `[0, internal.length]`.
  *
  * @param item - The item to add at the specified index.
  *
  * @returns The index at which the item was added.
  *
  * #### Notes
  * This may be reimplemented by subclasses to customize the behavior.
  */
 protected addItem(index: number, item: T): number {
   this.internal.insert(index, item);
   this.changed.emit({
     type: 'add',
     newIndex: index,
     newValue: item,
     oldIndex: -1,
     oldValue: void 0,
   });
   return index;
 }
Example #8
0
 /**
  * Set the item at a specific index in the list.
  *
  * @param index - The index of interest. This must be an integer in
  *   the range `[0, internal.length)`.
  *
  * @param item - The item to set at the index.
  *
  * @returns The item which previously occupied the specified index.
  *
  * #### Notes
  * This may be reimplemented by subclasses to customize the behavior.
  */
 protected setItem(index: number, item: T): T {
   let old = this.internal.at(index);
   this.internal.set(index, item);
   this.changed.emit({
     type: 'set',
     newIndex: index,
     newValue: item,
     oldIndex: index,
     oldValue: old,
   });
   return old;
 }
 let firstPass = () => {
   let now = (new Date()).getTime();
   let delta = now - start;
   if (delta > timeout) {
     expect(called).to.be(true);
     expect(emission).to.be(firstEmission);
     done();
     return;
   }
   signal.emit(secondEmission);
   // Restart the clock.
   start = (new Date()).getTime();
   setTimeout(secondPass, timeout - 100);
 };
 it('should be emitted after the signal has fired and a timeout', (done) => {
   let called = false;
   let monitor = new ActivityMonitor({ signal, timeout: 100 });
   monitor.activityStopped.connect((sender, args) => {
     expect(sender).to.be(monitor);
     expect(args.sender).to.be(testObj);
     expect(args.args).to.be(10);
     called = true;
   });
   signal.emit(10);
   expect(called).to.be(false);
   setTimeout(() => {
     expect(called).to.be(true);
     done();
   }, 100);
 });