怎么更新IEditorTab中的文本内容
YuanWangZai opened this issue · comments
Question
// 打开一个文本文件
molecule.editor.open(transformToEditorTab(node))
updateStatusBarLanguage(node.data.language)
// 当底层文件发生变化的时候,希望已经打开的编辑器Tab中的文本也发生变化
if (molecule.editor.isOpened(tabId)) {
const tab = molecule.editor.getTabById(tabId, 1)
// 更新逻辑
// 期望对 tab 做更新
}
我知道获取editorInstance是可以做到的,但是当前active的编辑器Tab不一定是我要修改的那个,有没有IEditorTab中的方法可以实现这一点
直接调用 molecule.editor.updateTab
可以更新吧
是这样吗,页面内容没有变化
const tab = molecule.editor.getTabById(tabId, 1) as any
tab.data = newData
molecule.editor.updateTab(tab, 1)
貌似 updateTab 没有去更新非当前 tab 的数据是一个 bug。
临时解决方法:在 updateTab 调用后调用 model.setValue
import { editor, Uri } from '@dtinsight/molecule/esm/monaco';
const tab = molecule.editor.getTabById(tabId, 1) as any
tab.data = newData
molecule.editor.updateTab(tab, 1);
// 以上只能更新当前 tab 的内容
const model = editor.getModel(Uri.parse(tab.id)); // 获取 tab 对应的 model
if (model) {
model.setValue('test');
}
好的,谢谢