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


TypeScript TextEditor.getBuffer方法代码示例

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


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

示例1: insertResult

  function insertResult(i: number, editor: TextEditor, lines: string[]) {
    const lineCount = editor.getLineCount();
    let start = 0;
    // find <!- code_chunk_output -->
    for (let j = i + 1; j < i + 6 && j < lineCount; j++) {
      if (lines[j].startsWith("<!-- code_chunk_output -->")) {
        start = j;
        break;
      }
    }

    if (start) {
      // found
      // TODO: modify exited output
      let end = start + 1;
      while (end < lineCount) {
        if (lines[end].startsWith("<!-- /code_chunk_output -->")) {
          break;
        }
        end += 1;
      }

      // if output not changed, then no need to modify editor buffer
      let r = "";
      for (let i2 = start + 2; i2 < end - 1; i2++) {
        r += lines[i2] + "\n";
      }
      if (r === result + "\n") {
        return "";
      } // no need to modify output
      editor
        .getBuffer()
        .setTextInRange([[start + 2, 0], [end - 1, 0]], result + "\n");
      /*
      editor.edit((edit)=> {
        edit.replace(new vscode.Range(
          new vscode.Position(start + 2, 0),
          new vscode.Position(end-1, 0)
        ), result+'\n')
      })
      */
      return "";
    } else {
      editor
        .getBuffer()
        .insert(
          [i + 1, 0],
          `<!-- code_chunk_output -->\n\n${result}\n\n<!-- /code_chunk_output -->\n`,
        );
      return "";
    }
  }
开发者ID:bitst0rm-dev,项目名称:markdown-preview-enhanced,代码行数:52,代码来源:extension.ts

示例2: getSymbolInRange

export function getSymbolInRange(editor: TextEditor, crange: Range) {
  const buffer = editor.getBuffer()
  if (crange.isEmpty()) {
    return getSymbolAtPoint(editor, crange.start)
  } else {
    return {
      symbol: buffer.getTextInRange(crange),
      range: crange,
    }
  }
}
开发者ID:mvoidex,项目名称:atom-haskell-hsdev,代码行数:11,代码来源:util.ts

示例3: beforeEach

 beforeEach(async function() {
   await atom.packages.activatePackage(grammar)
   editor = (await atom.workspace.open(
     `${__dirname}${sep}fixtures${sep}${fixture}`,
   )) as TextEditor
   expect(editor).to.exist
   editor.getBuffer().setPreferredLineEnding(opts.crlf)
   if (opts.addGrammar) {
     expect(
       atom.commands.dispatch(
         atom.views.getView(editor),
         'markdown-table-formatter:enable-for-current-scope',
       ),
     ).to.be.ok
   }
 })
开发者ID:fcrespo82,项目名称:atom-markdown-table-formatter,代码行数:16,代码来源:editor.spec.ts

示例4: prettifyFile

export async function prettifyFile(editor: TextEditor) {
  const [firstCursor, ...cursors] = editor
    .getCursors()
    .map((cursor) => cursor.getBufferPosition())
  const format = editor.getGrammar().scopeName
  const prettify = format === 'source.cabal' ? cabalFormat : filterFormat
  const workDir = (await getRootDir(editor.getBuffer())).getPath()
  try {
    const { stdout, stderr } = await prettify(
      editor.getText(),
      workDir,
      editor.getRootScopeDescriptor(),
    )
    editor.setText(stdout)
    const lastCursor = editor.getLastCursor()
    if (lastCursor) {
      lastCursor.setBufferPosition(firstCursor, { autoscroll: false })
    }
    cursors.forEach((cursor) => {
      editor.addCursorAtBufferPosition(cursor, { autoscroll: false })
    })
    if (stderr.length > 0) {
      atom.notifications.addWarning(
        'Prettifier reported the following problems:',
        {
          detail: stderr,
          dismissable: true,
        },
      )
    }
  } catch (e) {
    const err: Error = e.error || e
    let stderr: string = e.stderr ? e.stderr.trim() : ''
    if (err.message.includes(stderr)) {
      stderr = ''
    }
    atom.notifications.addError('Failed to prettify', {
      detail: `${stderr ? `${stderr}\n\n` : ''}${err.message}`,
      stack: err.stack,
      dismissable: true,
    })
  }
}
开发者ID:atom-haskell,项目名称:ide-haskell,代码行数:43,代码来源:index.ts


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