本文整理汇总了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 "";
}
}
示例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,
}
}
}
示例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
}
})
示例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,
})
}
}