How to use the @lumino/algorithm.ArrayExt.upperBound 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 / mainmenu / src / mainmenu.ts View on Github external
addMenu(menu: Menu, options: IMainMenu.IAddOptions = {}): void {
    if (ArrayExt.firstIndexOf(this.menus, menu) > -1) {
      return;
    }

    let rank = 'rank' in options ? options.rank : 100;
    let rankItem = { menu, rank };
    let index = ArrayExt.upperBound(this._items, rankItem, Private.itemCmp);

    // Upon disposal, remove the menu and its rank reference.
    menu.disposed.connect(this._onMenuDisposed, this);

    ArrayExt.insert(this._items, index, rankItem);
    /**
     * Create a new menu.
     */
    this.insertMenu(index, menu);
  }
github jupyterlab / lumino / packages / datagrid / src / sectionlist.ts View on Github external
// Compute the first affected index.
    let i1 = Math.min(index, destination);

    // Look up the first affected modified section.
    let k1 = ArrayExt.lowerBound(this._sections, i1, Private.indexCmp);

    // Bail early if there are no affected modified sections.
    if (k1 === this._sections.length) {
      return;
    }

    // Compute the last affected index.
    let i2 = Math.max(index + count - 1, destination + count - 1);

    // Look up the last affected modified section.
    let k2 = ArrayExt.upperBound(this._sections, i2, Private.indexCmp) - 1;

    // Bail early if there are no affected modified sections.
    if (k2 < k1) {
      return;
    }

    // Compute the pivot index.
    let pivot = destination < index ? index : index + count;

    // Compute the count for each side of the pivot.
    let count1 = pivot - i1;
    let count2 = i2 - pivot + 1;

    // Compute the span for each side of the pivot.
    let span1 = count1 * this._defaultSize;
    let span2 = count2 * this._defaultSize;
github jupyterlab / jupyterlab / packages / mainmenu / src / labmenu.ts View on Github external
addGroup(items: Menu.IItemOptions[], rank?: number): IDisposable {
    const rankGroup = {
      size: items.length,
      rank: rank === undefined ? 100 : rank
    };

    // Insert the plugin group into the list of groups.
    const groupIndex = ArrayExt.upperBound(
      this._groups,
      rankGroup,
      Private.itemCmp
    );

    // Determine the index of the menu at which to insert the group.
    let insertIndex = 0;
    for (let i = 0; i < groupIndex; ++i) {
      if (this._groups[i].size > 0) {
        insertIndex += this._groups[i].size;
        // Increase the insert index by two extra in order
        // to include the leading and trailing separators.
        insertIndex += this._includeSeparators ? 2 : 0;
      }
    }
github jupyterlab / jupyterlab / packages / codemirror / src / mode.ts View on Github external
export function addSpecLoader(loader: ISpecLoader, rank: number) {
    let item = { loader, rank };
    let index = ArrayExt.upperBound(specLoaders, item, Private.itemCmp);
    ArrayExt.insert(specLoaders, index, item);
  }
github jupyterlab / jupyterlab / packages / application / src / shell.ts View on Github external
private _findInsertIndex(item: Private.IRankItem): number {
      return ArrayExt.upperBound(this._items, item, Private.itemCmp);
    }
github jupyterlab / jupyterlab / packages / application / src / shell.ts View on Github external
addWidget(widget: Widget, rank: number): void {
      widget.parent = null;
      const item = { widget, rank };
      const index = ArrayExt.upperBound(this._items, item, Private.itemCmp);
      ArrayExt.insert(this._items, index, item);
      this._panel.insertWidget(index, widget);
    }