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


TypeScript TextEditor.getText方法代码示例

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


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

示例1: editorFormat

 function editorFormat(input: string) {
   editor.setText(input)
   if (opts.selectBeforeTest) {
     editor.setSelectedBufferRange(editor.getBuffer().getRange())
   }
   atom.commands.dispatch(
     atom.views.getView(editor),
     'markdown-table-formatter:format',
   )
   return editor.getText()
 }
开发者ID:fcrespo82,项目名称:atom-markdown-table-formatter,代码行数:11,代码来源:editor.spec.ts

示例2: 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

示例3: async

  lint: async (textEditor: TextEditor): Promise<LintResult> => {
    const filePath = textEditor.getPath();

    if (!filePath) {
      // The current TextEditor has no path associated with it.
      return null;
    }

    const input = textEditor.getText();

    const command = atom.config.get("linter-swiftlint.swiftlintExecutablePath");
    if (!fs.existsSync(command)) {
      return null;
    }

    const parameters = ["lint", "--use-stdin"];
    let config = path.normalize(
      atom.config.get("linter-swiftlint.configurationPath")
    );

    if (filePath && !path.isAbsolute(config)) {
      config =
        atom.project
          .getDirectories()
          .filter(directory => directory.contains(filePath))
          .map(directory => directory.getFile(config).getPath())
          .find(() => true) || config; // take first item if exists
    }

    if (config && fs.existsSync(config)) {
      parameters.push("--config", config);
    }

    const additionalOptions = atom.config.get(
      "linter-swiftlint.additionalOptions"
    );
    if (additionalOptions) {
      parameters.push(additionalOptions);
    }

    const options = {
      ignoreExitCode: true,
      stdin: input,
      throwOnStderr: false
    };

    const output = await helpers.exec(command, parameters, options);

    const messages: Message[] = [];
    let match = regex.exec(output);
    while (match !== null) {
      const line = Math.max(Number.parseInt(match[1], 10) - 1, 0);
      const col = Math.max(Number.parseInt(match[2], 10) - 1, 0);
      let position: Range;
      try {
        position = helpers.generateRange(textEditor, line, col);
      } catch(e) {
        // If the position wasn't valid, just return the start of the file
        // NOTE: Ideally this would handle the error and give the user an easy
        // way to report it for eventual fixing.
        position = new Range([0, 0], [0, Number.POSITIVE_INFINITY]);
      }

      const type = match[3].toLowerCase();
      const severity =
        type === 'error' || type === 'warning' || type === 'info' ?
        type : 'error';

      messages.push({
        severity,
        excerpt: match[4],
        location: {
          file: filePath,
          position,
        }
      });

      // Pull in the next result (if any)
      match = regex.exec(output);
    }

    return messages;
  }
开发者ID:AtomLinter,项目名称:linter-swiftlint,代码行数:83,代码来源:linter-provider.ts


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