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


TypeScript atom.TextEditor類代碼示例

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


在下文中一共展示了TextEditor類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getSymbolAtPoint

export function getSymbolAtPoint(
  editor: TextEditor, point: Point,
) {
  const [scope] = editor.scopeDescriptorForBufferPosition(point).getScopesArray().slice(-1)
  if (scope) {
    const range = editor.bufferRangeForScopeAtPosition(scope, point)
    if (range && !range.isEmpty()) {
      const symbol = editor.getTextInBufferRange(range)
      return { scope, range, symbol }
    }
  }
  return undefined
}
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:13,代碼來源:util.ts

示例3: deserializeEditorState

export function deserializeEditorState(
  editor: TextEditor,
  {bufferRanges, scrollTop}: ReturnType<typeof serializeEditorState>,
) {
  const editorElement = atom.views.getView(editor)
  editor.setSelectedBufferRanges(bufferRanges)
  editorElement.setScrollTop(scrollTop)
}
開發者ID:TypeStrong,項目名稱:atom-typescript,代碼行數:8,代碼來源:utils.ts

示例4: constructor

 constructor(public props: Props) {
   this.model = atom.workspace.buildTextEditor({
     mini: true,
     softWrapped: true,
     lineNumberGutterVisible: false,
   })
   this.element = atom.views.getView(this.model)
   this.model.setText(props.initialText)
   if (props.selectAll) {
     this.model.selectAll()
   } else {
     this.model.getLastCursor().moveToEndOfScreenLine()
   }
   this.setReadOnly()
   this.setGrammar()
   this.model.scrollToBufferPosition([0, 0])
 }
開發者ID:TypeStrong,項目名稱:atom-typescript,代碼行數:17,代碼來源:miniEditor.ts

示例5: serializeEditorState

export function serializeEditorState(editor: TextEditor) {
  const editorElement = atom.views.getView(editor)
  const scrollTop = editorElement.getScrollTop()

  return {
    bufferRanges: editor.getSelectedBufferRanges(),
    scrollTop,
  }
}
開發者ID:TypeStrong,項目名稱:atom-typescript,代碼行數:9,代碼來源:utils.ts

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

示例7: bufferPositionFromMouseEvent

export function bufferPositionFromMouseEvent(
  editor: TextEditor,
  event: MouseEvent,
) {
  const sp: Point = (atom.views.getView(
    editor,
  ) as any).component.screenPositionForMouseEvent(event)
  if (isNaN(sp.row) || isNaN(sp.column)) {
    return undefined
  }
  return editor.bufferPositionForScreenPosition(sp)
}
開發者ID:atom-haskell,項目名稱:ide-haskell,代碼行數:12,代碼來源:index.ts

示例8: bufferPositionFromMouseEvent

export function bufferPositionFromMouseEvent(
  editor: TextEditor,
  event: {clientX: number; clientY: number},
) {
  const sp = atom.views
    .getView(editor)
    .getComponent()
    .screenPositionForMouseEvent(event)
  if (isNaN(sp.row) || isNaN(sp.column)) {
    return
  }
  return editor.bufferPositionForScreenPosition(sp)
}
開發者ID:TypeStrong,項目名稱:atom-typescript,代碼行數:13,代碼來源:util.ts

示例9: constructor

 constructor(private editor: TextEditor, groups: IMarkerGroup[]) {
   // tslint:disable-next-line:no-null-keyword
   this.table = Object.create(null)
   for (const i of eventRangeTypeVals) {
     this.table[i] = new Map()
   }
   this.layers = new Set()
   for (const i of groups) {
     const layer = this.editor.addMarkerLayer()
     this.layers.add(layer)
     for (const { type, source } of i) {
       ;(this.table[type] as TTableCell).set(source, layer)
     }
   }
 }
開發者ID:atom-haskell,項目名稱:ide-haskell,代碼行數:15,代碼來源:event-table.ts

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


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