本文整理汇总了TypeScript中atom.TextEditor.setText方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextEditor.setText方法的具体用法?TypeScript TextEditor.setText怎么用?TypeScript TextEditor.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atom.TextEditor
的用法示例。
在下文中一共展示了TextEditor.setText方法的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()
}
示例2: 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])
}
示例3: 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,
})
}
}