有没有办法从字符串更改文件中的整个代码? 我的意思是有一种方法可以阅读文档中的所有内容,但我也可以替换整个文本吗?
阅读文档中代码的方式:
SourceCodeString = e.getData(LangDataKeys.EDITOR).getDocument().getText();
所以我基本上试图做与此相反的事情。
查看相关文档 安全地替换文档中的选定文本:
// Replace the selection with a fixed string.
// Must do this document change in a write action context.
WriteCommandAction.runWriteCommandAction(project, () ->
document.replaceString(start, end, "editor_basics")
);