当前位置: 首页>>代码示例>>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;未经允许,请勿转载。