當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript iteration.enumerate函數代碼示例

本文整理匯總了TypeScript中phosphor/lib/algorithm/iteration.enumerate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript enumerate函數的具體用法?TypeScript enumerate怎麽用?TypeScript enumerate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了enumerate函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: changeCellType

  function changeCellType(widget: Notebook, value: nbformat.CellType): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let model = widget.model;
    let cells = model.cells;

    cells.beginCompoundOperation();
    each(enumerate(widget.widgets), ([i, child]) => {
      if (!widget.isSelected(child)) {
        return;
      }
      if (child.model.type !== value) {
        let newCell: ICellModel;
        switch (value) {
        case 'code':
          newCell = model.factory.createCodeCell(child.model.toJSON());
          break;
        case 'markdown':
          newCell = model.factory.createMarkdownCell(child.model.toJSON());
          break;
        default:
          newCell = model.factory.createRawCell(child.model.toJSON());
        }
        cells.set(i, newCell);
      }
      if (value === 'markdown') {
        // Fetch the new widget and unrender it.
        child = widget.widgets.at(i);
        (child as MarkdownCellWidget).rendered = false;
      }
    });
    cells.endCompoundOperation();
    widget.deselectAll();
  }
開發者ID:danielballan,項目名稱:jupyterlab,代碼行數:35,代碼來源:actions.ts

示例2: deleteCells

  function deleteCells(widget: Notebook): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let model = widget.model;
    let cells = model.cells;
    let toDelete: ICellModel[] = [];
    let index = -1;
    widget.mode = 'command';

    // Find the cells to delete.
    each(enumerate(widget.widgets), ([i, child]) => {
      if (widget.isSelected(child)) {
        index = i;
        toDelete.push(cells.at(i));
      }
    });

    // Delete the cells as one undo event.
    cells.beginCompoundOperation();
    each(toDelete, cell => {
      cells.remove(cell);
    });
    // The model will add a new code cell if there are no
    // remaining cells.
    model.cells.endCompoundOperation();

    // Select the cell *after* the last selected.
    // Note: The activeCellIndex is clamped to the available cells,
    // so if the last cell is deleted the previous cell will be activated.
    index -= toDelete.length - 1;
    widget.activeCellIndex = index;
  }
開發者ID:danielballan,項目名稱:jupyterlab,代碼行數:33,代碼來源:actions.ts

示例3: mergeCells

  function mergeCells(widget: Notebook): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let toMerge: string[] = [];
    let toDelete: ICellModel[] = [];
    let model = widget.model;
    let cells = model.cells;
    let primary = widget.activeCell;
    let index = widget.activeCellIndex;

    // Get the cells to merge.
    each(enumerate(widget.widgets), ([i, child]) => {
      if (widget.isSelected(child)) {
        toMerge.push(child.model.value.text);
        if (i !== index) {
          toDelete.push(child.model);
        }
      }
    });

    // Check for only a single cell selected.
    if (toMerge.length === 1) {
      // Bail if it is the last cell.
      if (index === cells.length - 1) {
        return;
      }
      // Otherwise merge with the next cell.
      let cellModel = cells.at(index + 1);
      toMerge.push(cellModel.value.text);
      toDelete.push(cellModel);
    }

    widget.deselectAll();

    // Create a new cell for the source to preserve history.
    let newModel = Private.cloneCell(model, primary.model);
    newModel.value.text = toMerge.join('\n\n');
    if (newModel.type === 'code') {
      (newModel as ICodeCellModel).outputs.clear();
    }

    // Make the changes while preserving history.
    cells.beginCompoundOperation();
    cells.set(index, newModel);
    each(toDelete, cell => {
      cells.remove(cell);
    });
    cells.endCompoundOperation();

    // If the original cell is a markdown cell, make sure
    // the new cell is unrendered.
    if (primary instanceof MarkdownCellWidget) {
      let cell = widget.activeCell as MarkdownCellWidget;
      cell.rendered = false;
    }
  }
開發者ID:Carreau,項目名稱:jupyterlab,代碼行數:57,代碼來源:actions.ts

示例4: deleteCells

  function deleteCells(widget: Notebook): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let model = widget.model;
    let cells = model.cells;
    let toDelete: number[] = [];
    widget.mode = 'command';

    // Find the cells to delete.
    each(enumerate(widget.widgets), ([i, child]) => {
      let deletable = child.model.getMetadata('deletable').getValue();
      if (widget.isSelected(child) && deletable !== false) {
        toDelete.push(i);
      }
    });

    // If cells are not deletable, we may not have anything to delete.
    if (toDelete.length > 0) {
      // Delete the cells as one undo event.
      cells.beginCompoundOperation();
      each(toDelete.reverse(), i => {
        cells.removeAt(i);
      });
      // The model will add a new code cell if there are no
      // remaining cells.
      model.cells.endCompoundOperation();

      // Select the *first* interior cell not deleted or the cell
      // *after* the last selected cell.
      // Note: The activeCellIndex is clamped to the available cells,
      // so if the last cell is deleted the previous cell will be activated.
      widget.activeCellIndex = toDelete[0];
    }

    // Deselect any remaining, undeletable cells. Do this even if we don't
    // delete anything so that users are aware *something* happened.
    widget.deselectAll();
  }
開發者ID:Carreau,項目名稱:jupyterlab,代碼行數:39,代碼來源:actions.ts


注:本文中的phosphor/lib/algorithm/iteration.enumerate函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。