mirror of
https://github.com/heyman/heynote.git
synced 2024-11-21 23:43:22 +01:00
Remove timeout parameter for getBlocksFromSyntaxTree() since we now expect the syntax tree to already be available.
This commit is contained in:
parent
29d4eb26cc
commit
c3892163af
@ -24,14 +24,11 @@ let firstBlockDelimiterSize
|
||||
/**
|
||||
* Return a list of blocks in the document from the syntax tree.
|
||||
* syntaxTreeAvailable() should have been called before this function to ensure the syntax tree is available.
|
||||
* @param {*} state
|
||||
* @param {*} timeout
|
||||
* @returns
|
||||
*/
|
||||
function getBlocksFromSyntaxTree(state, timeout=50) {
|
||||
function getBlocksFromSyntaxTree(state) {
|
||||
//const timer = startTimer()
|
||||
const blocks = [];
|
||||
const tree = syntaxTree(state, state.doc.length, timeout)
|
||||
const tree = syntaxTree(state, state.doc.length)
|
||||
if (tree) {
|
||||
tree.iterate({
|
||||
enter: (type) => {
|
||||
@ -73,15 +70,9 @@ function getBlocksFromSyntaxTree(state, timeout=50) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blocks for the document state.
|
||||
* If the syntax tree is available, we'll extract the blocks from that. Otherwise
|
||||
* the blocks are parsed from the string contents of the document, which is much faster
|
||||
* than waiting for the tree parsing to finnish.
|
||||
* Parse blocks from document's string contents using String.indexOf()
|
||||
*/
|
||||
function getBlocks(state) {
|
||||
if (syntaxTreeAvailable(state, state.doc.length)) {
|
||||
return getBlocksFromSyntaxTree(state)
|
||||
}
|
||||
function getBlocksFromString(state) {
|
||||
//const timer = startTimer()
|
||||
const blocks = []
|
||||
const doc = state.doc
|
||||
@ -137,13 +128,27 @@ function getBlocks(state) {
|
||||
blocks.push(block);
|
||||
pos = blockEnd;
|
||||
}
|
||||
//console.log("getBlocks (string parsing) took", timer(), "ms")
|
||||
//console.log("getBlocksFromString() took", timer(), "ms")
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the blocks from the document state.
|
||||
* If the syntax tree is available, we'll extract the blocks from that. Otherwise
|
||||
* the blocks are parsed from the string contents of the document, which is much faster
|
||||
* than waiting for the tree parsing to finnish.
|
||||
*/
|
||||
function getBlocks(state) {
|
||||
if (syntaxTreeAvailable(state, state.doc.length)) {
|
||||
return getBlocksFromSyntaxTree(state)
|
||||
} else {
|
||||
return getBlocksFromString(state)
|
||||
}
|
||||
}
|
||||
|
||||
export const blockState = StateField.define({
|
||||
create(state) {
|
||||
return getBlocks(state, 1000);
|
||||
return getBlocks(state);
|
||||
},
|
||||
update(blocks, transaction) {
|
||||
// if blocks are empty it likely means we didn't get a parsed syntax tree, and then we want to update
|
||||
|
Loading…
Reference in New Issue
Block a user