Skip to content
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

Fix issue with large buffers where block delimiters wouldn't be "atomic" when first starting Heynote, before the first edit #81

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/editor/block/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { emptyBlockSelected } from "./select-all.js";
// tracks the size of the first delimiter
let firstBlockDelimiterSize

export function getBlocks(state) {
function getBlocks(state, timeout=50) {
const blocks = [];
const tree = ensureSyntaxTree(state, state.doc.length)
const tree = ensureSyntaxTree(state, state.doc.length, timeout)
if (tree) {
tree.iterate({
enter: (type) => {
Expand Down Expand Up @@ -57,16 +57,14 @@ export function getBlocks(state) {

export const blockState = StateField.define({
create(state) {
return getBlocks(state);
return getBlocks(state, 1000);
},
update(blocks, transaction) {
// if blocks are empty it likely means we didn't get a parsed syntax tree, and then we want to update
// the blocks on all updates (and not just document changes)
if (transaction.docChanged || blocks.length === 0) {
//console.log("updating block state", transaction)
return getBlocks(transaction.state);
}
//return widgets.map(transaction.changes);
return blocks
},
})
Expand Down
4 changes: 2 additions & 2 deletions src/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { heynoteDark } from "./theme/dark.js"
import { heynoteBase } from "./theme/base.js"
import { customSetup } from "./setup.js"
import { heynoteLang } from "./lang-heynote/heynote.js"
import { noteBlockExtension, blockLineNumbers, getBlocks } from "./block/block.js"
import { noteBlockExtension, blockLineNumbers, blockState } from "./block/block.js"
import { heynoteEvent, SET_CONTENT } from "./annotation.js";
import { changeCurrentBlockLanguage, triggerCurrenciesLoaded } from "./block/commands.js"
import { formatBlockContent } from "./block/format-code.js"
Expand Down Expand Up @@ -128,7 +128,7 @@ export class HeynoteEditor {
}

getBlocks() {
return getBlocks(this.view.state)
return this.view.state.facet(blockState)
}

focus() {
Expand Down