-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve editor refresh for kernel API /api/block/moveBlock
#14559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
我这里分屏后测试,两个页签都会自动刷新内容的。 |
补充个录屏: issue.webm暂时关了,欢迎随时跟帖,谢谢。 |
两个以上同时移动更容易出问题,如下图所示 总之,这个api不稳定,每次仅移动一个块时,时好时坏,同时移动多个块时,第一次移动到新文档一般都有问题。 我测试的版本有 v3.1.24,v3.1.27,v3.1.10 ,都有这个问题,记得其他版本也有问题。 附测试代码 let to = '20250410123049-anh992z';
await fetchSyncPost('/api/block/moveBlock', {
"id": '20250316200508-wkewsu8',
"previousID": to,
"parentID": '',
});
await fetchSyncPost('/api/block/moveBlock', {
"id": '20250316201817-bmmtfuh',
"previousID": to,
"parentID": '',
});
async function fetchSyncPost(url, data, method = 'POST') {
return await (await fetch(url, {method: method, body: JSON.stringify(data||{})})).json();
} |
另外,这个api还有一个小问题,就是当只用parentID且previousID填空字符串时,会报错:previousID can not be the ID of a document 必须删除previousID或填undefined才行 |
请使用 3.1.27 测试 |
3.1.27 也是一样的问题。 |
暂时用这种方案,移动后,先检查目标文档所有块是否已显示,有未显示的再刷新 function reloadProtyle(ids = [], node = null) {
node = node || document;
if(ids.length > 0) {
// 检查id的元素是否存在
let hasNotExistEl = false;
for(const id of ids){
const el = node.querySelector(`[data-node-id="${id}"]`);
if(!el) {
hasNotExistEl = true;
break;
}
}
if(hasNotExistEl) (siyuan?.mobile||getProtyle()?.model)?.editor?.reload();
} else {
(siyuan?.mobile||getProtyle()?.model)?.editor?.reload();
}
} |
#14559 (comment) 我这里可以重现了 @Vanessa219 #14559 (comment) |
/api/block/moveBlock
收到,感谢D大! |
我和 V 分析了下,这个前端无法实时刷新(因为跨编辑器 move 比较复杂),但可以实现内核推送编辑器刷新,将就就用这个方案吧。 |
OK!感谢D大和V姐!辛苦了! |
/api/block/moveBlock调用后,在新文档中无法实时显示块,需要F5刷新才行,怎么改进?
In what scenarios do you need this feature?
假设有A,B两个文档,A,B文档同时打开,A文档的块通过api
/api/block/moveBlock
移动到B文档后,如果第一次移动到B时,B文档无法实时显示移动过来的块,需要按F5刷新才行,有没有办法不通过刷新也能实时显示?目前通过 protyle.reload() 刷新实现,但这种刷新,如果移动过来的块在文档的下方,页面会闪动以下,体验不好。
Describe the optimal solution
期望移动过来的块能实时显示。
Describe the candidate solution
No response
Other information
No response
The text was updated successfully, but these errors were encountered: