From 9f7b59905ac386e806eccd3e12103c5f7226e798 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Tue, 2 Aug 2022 12:44:41 +0200 Subject: [PATCH] Attempt to fix line wrapper bugs --- packages/web/line_wrapper.ts | 66 +++++++++++++++++---------------- packages/web/styles/editor.scss | 6 --- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/packages/web/line_wrapper.ts b/packages/web/line_wrapper.ts index 54f35c76..c093396f 100644 --- a/packages/web/line_wrapper.ts +++ b/packages/web/line_wrapper.ts @@ -18,43 +18,45 @@ interface WrapElement { function wrapLines(view: EditorView, wrapElements: WrapElement[]) { let widgets: Range[] = []; let elementStack: string[] = []; - for (let { from, to } of view.visibleRanges) { - const doc = view.state.doc; - syntaxTree(view.state).iterate({ - from, - to, - enter: ({ type, from, to }) => { - for (let wrapElement of wrapElements) { - if (type.name == wrapElement.selector) { + const doc = view.state.doc; + // Disabling the visible ranges for now, because it may be a bit buggy. + // RISK: this may actually become slow for large documents. + // for (let { from, to } of view.visibleRanges) { + syntaxTree(view.state).iterate({ + // from, + // to, + enter: ({ type, from, to }) => { + for (let wrapElement of wrapElements) { + if (type.name == wrapElement.selector) { + if (wrapElement.nesting) { + elementStack.push(type.name); + } + const bodyText = doc.sliceString(from, to); + let idx = from; + for (let line of bodyText.split("\n")) { + let cls = wrapElement.class; if (wrapElement.nesting) { - elementStack.push(type.name); - } - const bodyText = doc.sliceString(from, to); - let idx = from; - for (let line of bodyText.split("\n")) { - let cls = wrapElement.class; - if (wrapElement.nesting) { - cls = `${cls} ${cls}-${elementStack.length}`; - } - widgets.push( - Decoration.line({ - class: cls, - }).range(doc.lineAt(idx).from) - ); - idx += line.length + 1; + cls = `${cls} ${cls}-${elementStack.length}`; } + widgets.push( + Decoration.line({ + class: cls, + }).range(doc.lineAt(idx).from) + ); + idx += line.length + 1; } } - }, - leave({ type }) { - for (let wrapElement of wrapElements) { - if (type.name == wrapElement.selector && wrapElement.nesting) { - elementStack.pop(); - } + } + }, + leave({ type }) { + for (let wrapElement of wrapElements) { + if (type.name == wrapElement.selector && wrapElement.nesting) { + elementStack.pop(); } - }, - }); - } + } + }, + }); + // } // Widgets have to be sorted by `from` in ascending order widgets = widgets.sort((a, b) => { return a.from < b.from ? -1 : 1; diff --git a/packages/web/styles/editor.scss b/packages/web/styles/editor.scss index 3eb931d6..c58ca25f 100644 --- a/packages/web/styles/editor.scss +++ b/packages/web/styles/editor.scss @@ -1,12 +1,7 @@ @import "constants.scss"; -//div.rhs-open #editor .cm-editor .cm-content { -// max-width: 550px; -//} - .cm-editor { font-size: var(--ident); - //overflow-y: hidden; padding: 0 20px; .cm-content { @@ -256,7 +251,6 @@ color: #989797; background-color: rgba(210, 210, 210, 0.2); border-radius: 5px; - // font-style: italic; font-size: 75%; line-height: 75%; }