mirror of
https://github.com/heyman/heynote.git
synced 2025-02-25 14:42:10 +01:00
Handle the fact that the syntax tree is being parsed in a separate thread, which can lead to broken UI on slow environments
This commit is contained in:
parent
8867937567
commit
f20c09ce19
@ -13,37 +13,39 @@ let firstBlockDelimiterSize
|
|||||||
|
|
||||||
function getBlocks(state) {
|
function getBlocks(state) {
|
||||||
const blocks = [];
|
const blocks = [];
|
||||||
|
const tree = ensureSyntaxTree(state, state.doc.length)
|
||||||
ensureSyntaxTree(state, state.doc.length).iterate({
|
if (tree) {
|
||||||
enter: (type) => {
|
tree.iterate({
|
||||||
if (type.type.id == Document || type.type.id == Note) {
|
enter: (type) => {
|
||||||
return true
|
if (type.type.id == Document || type.type.id == Note) {
|
||||||
} else if (type.type.id === NoteDelimiter) {
|
return true
|
||||||
const langNode = type.node.getChild("NoteLanguage")
|
} else if (type.type.id === NoteDelimiter) {
|
||||||
const language = state.doc.sliceString(langNode.from, langNode.to)
|
const langNode = type.node.getChild("NoteLanguage")
|
||||||
const isAuto = !!type.node.getChild("Auto")
|
const language = state.doc.sliceString(langNode.from, langNode.to)
|
||||||
const contentNode = type.node.nextSibling
|
const isAuto = !!type.node.getChild("Auto")
|
||||||
blocks.push({
|
const contentNode = type.node.nextSibling
|
||||||
language: {
|
blocks.push({
|
||||||
name: language,
|
language: {
|
||||||
auto: isAuto,
|
name: language,
|
||||||
},
|
auto: isAuto,
|
||||||
content: {
|
},
|
||||||
from: contentNode.from,
|
content: {
|
||||||
to: contentNode.to,
|
from: contentNode.from,
|
||||||
},
|
to: contentNode.to,
|
||||||
delimiter: {
|
},
|
||||||
from: type.from,
|
delimiter: {
|
||||||
to: type.to,
|
from: type.from,
|
||||||
},
|
to: type.to,
|
||||||
})
|
},
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
},
|
||||||
return false;
|
mode: IterMode.IgnoreMounts,
|
||||||
},
|
});
|
||||||
mode: IterMode.IgnoreMounts,
|
firstBlockDelimiterSize = blocks[0]?.delimiter.to
|
||||||
});
|
}
|
||||||
firstBlockDelimiterSize = blocks[0]?.delimiter.to
|
|
||||||
return blocks
|
return blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +54,9 @@ export const blockState = StateField.define({
|
|||||||
return getBlocks(state);
|
return getBlocks(state);
|
||||||
},
|
},
|
||||||
update(blocks, transaction) {
|
update(blocks, transaction) {
|
||||||
//console.log("blocks", blocks)
|
// if blocks are empty it likely means we didn't get a parsed syntax tree, and then we want to update
|
||||||
if (transaction.docChanged) {
|
// the blocks on all updates (and not just document changes)
|
||||||
|
if (transaction.docChanged || blocks.length === 0) {
|
||||||
//console.log("updating block state", transaction)
|
//console.log("updating block state", transaction)
|
||||||
return getBlocks(transaction.state);
|
return getBlocks(transaction.state);
|
||||||
}
|
}
|
||||||
@ -115,7 +118,9 @@ const noteBlockWidget = () => {
|
|||||||
return decorate(state);
|
return decorate(state);
|
||||||
},
|
},
|
||||||
update(widgets, transaction) {
|
update(widgets, transaction) {
|
||||||
if (transaction.docChanged) {
|
// if widgets are empty it likely means we didn't get a parsed syntax tree, and then we want to update
|
||||||
|
// the decorations on all updates (and not just document changes)
|
||||||
|
if (transaction.docChanged || widgets.isEmpty) {
|
||||||
return decorate(transaction.state);
|
return decorate(transaction.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user