From 04a88cb15a7939b1e65e2b27c2f37f440bd508c3 Mon Sep 17 00:00:00 2001 From: kotaindah55 Date: Mon, 3 Feb 2025 23:40:47 +0200 Subject: [PATCH] fix: remove short-circuting when offset is non-zero Short-circuiting while offset is a non-zero value causes unexpected result when the parser intializes parsing. If it happens, the current context isn't obtained. Hence, tokens that intended to be resolved when facing the end of current line (i.e. due to current context being different with the previous one) may not be resolved. --- src/editor-mode/parser/ParserState.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/editor-mode/parser/ParserState.ts b/src/editor-mode/parser/ParserState.ts index b0143ee..b4646d3 100644 --- a/src/editor-mode/parser/ParserState.ts +++ b/src/editor-mode/parser/ParserState.ts @@ -174,7 +174,6 @@ export class ParserState { this.curCtx = ctx; } resolveContext() { - if (this.offset) { return } while (this.cursorPos() == "before") { this.nextCursor() } this.setContext(this.getContext()); let isSkip = false, @@ -207,9 +206,11 @@ export class ParserState { toBeResolved = true; offset -= 1; } - toBeResolved && this.queue.resolve(NonHighlightFormats, offset); - includesHl && this.queue.resolve([Format.HIGHLIGHT], offset); - isSkip && this.skipCursorRange(); - this.curCtx && this.nextCursor(); + if (!this.offset) { + if (toBeResolved) { this.queue.resolve(NonHighlightFormats, offset) } + if (includesHl) { this.queue.resolve([Format.HIGHLIGHT], offset) } + } + if (isSkip) { this.skipCursorRange() } + if (this.curCtx) { this.nextCursor() } } } \ No newline at end of file