本文整理汇总了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 "";
}
}
示例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
}
示例3: deserializeEditorState
export function deserializeEditorState(
editor: TextEditor,
{bufferRanges, scrollTop}: ReturnType<typeof serializeEditorState>,
) {
const editorElement = atom.views.getView(editor)
editor.setSelectedBufferRanges(bufferRanges)
editorElement.setScrollTop(scrollTop)
}
示例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])
}
示例5: serializeEditorState
export function serializeEditorState(editor: TextEditor) {
const editorElement = atom.views.getView(editor)
const scrollTop = editorElement.getScrollTop()
return {
bufferRanges: editor.getSelectedBufferRanges(),
scrollTop,
}
}
示例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,
}
}
}
示例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)
}
示例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)
}
示例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)
}
}
}
示例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()
}