本文整理匯總了TypeScript中atom.TextEditor.getCursors方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextEditor.getCursors方法的具體用法?TypeScript TextEditor.getCursors怎麽用?TypeScript TextEditor.getCursors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類atom.TextEditor
的用法示例。
在下文中一共展示了TextEditor.getCursors方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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,
})
}
}