当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Clipboard.getInstance方法代码示例

本文整理汇总了TypeScript中@jupyterlab/apputils.Clipboard.getInstance方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Clipboard.getInstance方法的具体用法?TypeScript Clipboard.getInstance怎么用?TypeScript Clipboard.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@jupyterlab/apputils.Clipboard的用法示例。


在下文中一共展示了Clipboard.getInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: paste

  function paste(widget: Notebook): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let clipboard = Clipboard.getInstance();
    if (!clipboard.hasData(JUPYTER_CELL_MIME)) {
      return;
    }
    let state = Private.getState(widget);
    let values = clipboard.getData(JUPYTER_CELL_MIME) as nbformat.IBaseCell[];
    let model = widget.model;
    let newCells: ICellModel[] = [];
    widget.mode = 'command';

    each(values, cell => {
      switch (cell.cell_type) {
      case 'code':
        newCells.push(model.contentFactory.createCodeCell({ cell }));
        break;
      case 'markdown':
        newCells.push(model.contentFactory.createMarkdownCell({ cell }));
        break;
      default:
        newCells.push(model.contentFactory.createRawCell({ cell }));
        break;
      }
    });
    let index = widget.activeCellIndex;

    let cells = widget.model.cells;
    cells.beginCompoundOperation();
    each(newCells, cell => {
      cells.insert(++index, cell);
    });
    cells.endCompoundOperation();

    widget.activeCellIndex += newCells.length;
    widget.deselectAll();
    Private.handleState(widget, state);
  }
开发者ID:eskirk,项目名称:jupyterlab,代码行数:40,代码来源:actions.ts

示例2: copyOrCut

 function copyOrCut(widget: Notebook, cut: boolean): void {
   if (!widget.model || !widget.activeCell) {
     return;
   }
   let state = getState(widget);
   widget.mode = 'command';
   let clipboard = Clipboard.getInstance();
   clipboard.clear();
   let data: nbformat.IBaseCell[] = [];
   each(widget.widgets, child => {
     if (widget.isSelectedOrActive(child)) {
       data.push(child.model.toJSON());
     }
   });
   clipboard.setData(JUPYTER_CELL_MIME, data);
   if (cut) {
     deleteCells(widget);
   } else {
     widget.deselectAll();
   }
   handleState(widget, state);
 }
开发者ID:7125messi,项目名称:jupyterlab,代码行数:22,代码来源:actions.ts

示例3: defaultRenderMime

  export const defaultEditorConfig = { ...StaticNotebook.defaultEditorConfig };

  export const editorFactory = editorServices.factoryService.newInlineEditor.bind(
    editorServices.factoryService
  );

  export const mimeTypeService = editorServices.mimeTypeService;

  /**
   * Get a copy of the default rendermime instance.
   */
  export function defaultRenderMime(): RenderMimeRegistry {
    return localRendermime();
  }

  export const clipboard = Clipboard.getInstance();

  /**
   * Create a base cell content factory.
   */
  export function createBaseCellFactory(): Cell.IContentFactory {
    return new Cell.ContentFactory({ editorFactory });
  }

  /**
   * Create a new code cell content factory.
   */
  export function createCodeCellFactory(): Cell.IContentFactory {
    return new Cell.ContentFactory({ editorFactory });
  }
开发者ID:AlbertHilb,项目名称:jupyterlab,代码行数:30,代码来源:notebook-utils.ts

示例4: paste

  function paste(widget: Notebook, mode: 'below' | 'above' | 'replace' = 'below'): void {
    if (!widget.model || !widget.activeCell) {
      return;
    }
    let clipboard = Clipboard.getInstance();
    if (!clipboard.hasData(JUPYTER_CELL_MIME)) {
      return;
    }
    let state = Private.getState(widget);
    let values = clipboard.getData(JUPYTER_CELL_MIME) as nbformat.IBaseCell[];
    let model = widget.model;
    let newCells: ICellModel[] = [];
    widget.mode = 'command';

    each(values, cell => {
      switch (cell.cell_type) {
      case 'code':
        newCells.push(model.contentFactory.createCodeCell({ cell }));
        break;
      case 'markdown':
        newCells.push(model.contentFactory.createMarkdownCell({ cell }));
        break;
      default:
        newCells.push(model.contentFactory.createRawCell({ cell }));
        break;
      }
    });

    let cells = widget.model.cells;
    let index: number;
    cells.beginCompoundOperation();

    // Set the starting index of the paste
    // operation depending upon the mode.
    switch (mode) {
      case 'below':
        index = widget.activeCellIndex;
        break;
      case 'above':
        index = widget.activeCellIndex - 1;
        break;
      case 'replace':
        // Find the cells to delete.
        const toDelete: number[] = [];
        each(widget.widgets, (child, i) => {
          let deletable = child.model.metadata.get('deletable');
          if (widget.isSelectedOrActive(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.
          each(toDelete.reverse(), i => {
            cells.remove(i);
          });
        }
        index = toDelete[0];
        break;
      default:
        break;
    }

    each(newCells, cell => {
      cells.insert(++index, cell);
    });
    cells.endCompoundOperation();

    widget.activeCellIndex += newCells.length;
    widget.deselectAll();
    Private.handleState(widget, state);
  }
开发者ID:7125messi,项目名称:jupyterlab,代码行数:72,代码来源:actions.ts


注:本文中的@jupyterlab/apputils.Clipboard.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。