Skip to content

Commit

Permalink
Fix: for variable declaration in formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Canna71 committed Dec 17, 2022
1 parent 2763e6d commit 7e9eae8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Extensions/PostProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import parse from 'src/Math/Parsing';
export const getPostPrcessor = (settings: MathpadSettings):MarkdownPostProcessor => {
return debounce((element: HTMLElement, context: MarkdownPostProcessorContext) => {
// todo: debounce and then use context.containerEl
const codes = (context as any).containerEl.querySelectorAll("code, div[data-mathpad-input]");
const codes = (context as any).containerEl.querySelectorAll("code, div[data-mathpad-input], mjx-container[data-mathpad-input]");
const engine = createEngine();

// const settings = getSettings();
// console.log(codes);
for (let index = 0; index < codes.length; index++) {
const code = codes.item(index) as HTMLElement;
processCode(code, engine, context, settings);
Expand All @@ -30,8 +29,10 @@ function processCode(code: HTMLElement, engine: Engine, context: MarkdownPostPro
} else {
text = code.dataset.mathpadInput;
}


// console.log("processCode " + text)
const pr = parse(text, settings);

if(pr.isValid){
const containerWidth = Math.clamp((context as any).containerEl.offsetWidth,200,700);
const plotWidth = settings.plotWidth>0?settings.plotWidth:containerWidth;
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/ResultField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const resultField = StateField.define<DecorationSet>({

const nodeA = tree.resolve(caretPos, 1);
const nodeB = tree.resolve(caretPos, -1);
console.log(nodeA.name, nodeB.name);
// console.log(nodeA.name, nodeB.name);
// formatting_formatting-code_inline-code_list-1
// inline-code_list-1
// we try to avoid recomputing if editing outside inline-code
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/ResultMarkdownChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class MathResult extends MarkdownRenderChild {
const mathEl = renderMath(latex || this.padScope.noteLatex, this.block);

finishRenderMath();
mathEl.dataset.mathpadInput = this.padScope.input + "=?";
mathEl.dataset.mathpadInput = this.padScope.input +
((this.padScope.parseResult.isVarDec || this.padScope.parseResult.isFnDec) ? "" : "=?");
return mathEl;
}
}
1 change: 1 addition & 0 deletions src/Math/PadScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export default class PadScope {

process(engine: Engine, parseResult: ParseResult): PadScope {
try {
// console.log("processing:", parseResult)
// save processing options and scope
this._input = parseResult.text;
this._scope = engine.getScope();
Expand Down

0 comments on commit 7e9eae8

Please sign in to comment.