How to use the @lumino/algorithm.ArrayExt.findFirstIndex function in @lumino/algorithm

To help you get started, we’ve selected a few @lumino/algorithm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / filebrowser / src / crumbs.ts View on Github external
if (!event.mimeData.hasData(CONTENTS_MIME)) {
      return;
    }
    event.dropAction = event.proposedAction;

    let target = event.target as HTMLElement;
    while (target && target.parentElement) {
      if (target.classList.contains(DROP_TARGET_CLASS)) {
        target.classList.remove(DROP_TARGET_CLASS);
        break;
      }
      target = target.parentElement;
    }

    // Get the path based on the target node.
    let index = ArrayExt.findFirstIndex(this._crumbs, node => node === target);
    if (index === -1) {
      return;
    }

    const model = this._model;
    const path = PathExt.resolve(model.path, BREAD_CRUMB_PATHS[index]);
    const manager = model.manager;

    // Move all of the items.
    let promises: Promise[] = [];
    let oldPaths = event.mimeData.getData(CONTENTS_MIME) as string[];
    for (let oldPath of oldPaths) {
      let localOldPath = manager.services.contents.localPath(oldPath);
      let name = PathExt.basename(localOldPath);
      let newPath = PathExt.join(path, name);
      promises.push(renameFile(manager, oldPath, newPath));
github jupyterlab / lumino / packages / widgets / src / commandpalette.ts View on Github external
private _activateNextItem(): void {
    // Bail if there are no search results.
    if (!this._results || this._results.length === 0) {
      return;
    }

    // Find the next enabled item index.
    let ai = this._activeIndex;
    let n = this._results.length;
    let start = ai < n - 1 ? ai + 1 : 0;
    let stop = start === 0 ? n - 1 : start - 1;
    this._activeIndex = ArrayExt.findFirstIndex(
      this._results, Private.canActivate, start, stop
    );

    // Schedule an update of the items.
    this.update();
  }
github jupyterlab / jupyterlab / packages / filebrowser / src / crumbs.ts View on Github external
private _evtClick(event: MouseEvent): void {
    // Do nothing if it's not a left mouse press.
    if (event.button !== 0) {
      return;
    }

    // Find a valid click target.
    let node = event.target as HTMLElement;
    while (node && node !== this.node) {
      if (
        node.classList.contains(BREADCRUMB_ITEM_CLASS) ||
        node.classList.contains(BREADCRUMB_HOME_CLASS)
      ) {
        let index = ArrayExt.findFirstIndex(
          this._crumbs,
          value => value === node
        );
        this._model
          .cd(BREAD_CRUMB_PATHS[index])
          .catch(error => showErrorMessage('Open Error', error));

        // Stop the event propagation.
        event.preventDefault();
        event.stopPropagation();
        return;
      }
      node = node.parentElement as HTMLElement;
    }
  }
github jupyterlab / jupyterlab / tests / test-mainmenu / src / labmenu.spec.ts View on Github external
it('should take a rank as an option', () => {
        menu.addGroup([{ command: 'run1' }, { command: 'run2' }], 2);
        menu.addGroup([{ command: 'run3' }, { command: 'run4' }], 1);

        const idx1 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run1'
        );
        const idx2 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run2'
        );
        const idx3 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run3'
        );
        const idx4 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run4'
        );
        expect(idx3 < idx4).to.equal(true);
        expect(idx4 < idx1).to.equal(true);
        expect(idx1 < idx2).to.equal(true);
      });
github jupyterlab / jupyterlab / tests / test-mainmenu / src / labmenu.spec.ts View on Github external
menu.addGroup([{ command: 'run1' }, { command: 'run2' }], 2);
        menu.addGroup([{ command: 'run3' }, { command: 'run4' }], 1);

        const idx1 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run1'
        );
        const idx2 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run2'
        );
        const idx3 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run3'
        );
        const idx4 = ArrayExt.findFirstIndex(
          menu.menu.items,
          m => m.command === 'run4'
        );
        expect(idx3 < idx4).to.equal(true);
        expect(idx4 < idx1).to.equal(true);
        expect(idx1 < idx2).to.equal(true);
      });
github jupyterlab / jupyterlab / packages / apputils / src / domutils.ts View on Github external
export function hitTestNodes(
    nodes: HTMLElement[] | HTMLCollection,
    x: number,
    y: number
  ): number {
    return ArrayExt.findFirstIndex(nodes, node => {
      return ElementExt.hitTest(node, x, y);
    });
  }
github jupyterlab / jupyterlab / packages / codemirror / src / editor.ts View on Github external
CodeMirror.on(editor, 'keydown', (editor: CodeMirror.Editor, event) => {
      let index = ArrayExt.findFirstIndex(this._keydownHandlers, handler => {
        if (handler(this, event) === true) {
          event.preventDefault();
          return true;
        }
        return false;
      });
      if (index === -1) {
        this.onKeydown(event);
      }
    });
    CodeMirror.on(editor, 'cursorActivity', () => this._onCursorActivity());
github jupyterlab / jupyterlab / packages / observables / src / observablelist.ts View on Github external
removeValue(value: T): number {
    let itemCmp = this._itemCmp;
    let index = ArrayExt.findFirstIndex(this._array, item => {
      return itemCmp(item, value);
    });
    this.remove(index);
    return index;
  }
github jupyterlab / jupyterlab / packages / statusbar / src / statusbar.ts View on Github external
private _findInsertIndex(
    side: Private.IRankItem[],
    newItem: Private.IRankItem
  ): number {
    return ArrayExt.findFirstIndex(side, item => item.rank > newItem.rank);
  }