style: change "gOffset" to "globalOffset"

This commit is contained in:
kotaindah55 2025-02-08 21:56:49 +02:00
parent 660ae524f8
commit 57d5b9db37
4 changed files with 17 additions and 17 deletions

View file

@ -39,7 +39,7 @@ export class Parser {
if (prevLine = this.state.prevLine) {
state.setContext(state.getContext(prevLine));
}
if (hlOpen && state.gOffset == hlOpen.to) {
if (hlOpen && state.globalOffset == hlOpen.to) {
Tokenizer.colorTag(state);
}
state.resolveContext();
@ -167,7 +167,7 @@ export class Parser {
lastToken.from >= this.state.line.from &&
this.queue.isQueued(Format.HIGHLIGHT)
) {
this.state.setGOffset(lastToken.from);
this.state.setGlobalOffset(lastToken.from);
} else {
return false;
}

View file

@ -36,7 +36,7 @@ export class ParserState {
) { this.offset = 0 }
}
/** global offset */
get gOffset() {
get globalOffset() {
return this.offset + this.line.from;
}
get linePos() {
@ -73,13 +73,13 @@ export class ParserState {
}
return true;
}
setGOffset(gOffset: number) {
if (gOffset > this.doc.length) {
setGlobalOffset(globalOffset: number) {
if (globalOffset > this.doc.length) {
this.line = this.doc.line(this.doc.lines);
this.offset = this.line.to;
} else {
this.line = this.doc.lineAt(gOffset);
this.offset = gOffset - this.line.from;
this.line = this.doc.lineAt(globalOffset);
this.offset = globalOffset - this.line.from;
}
}
isSpace(side: -1 | 0 | 1 = 0) {
@ -128,10 +128,10 @@ export class ParserState {
return false;
}
cursorPos(endSide: 0 | -1 = 0): "after" | "before" | "touch" | null {
let offset = this.gOffset;
let globalOffset = this.globalOffset;
if (!this.cursor) { return null }
if (offset < this.cursor.from) { return "after" }
if (offset > this.cursor.to + endSide) { return "before" }
if (globalOffset < this.cursor.from) { return "after" }
if (globalOffset > this.cursor.to + endSide) { return "before" }
return "touch";
}
processCursor() {

View file

@ -69,7 +69,7 @@ export class TokenQueue {
* will be stated as `ACTIVE` or `INACTIVE` depending on presence of
* closing delimiter in the queue.
*/
resolve(types: MainFormat[], to = this.state.gOffset) {
resolve(types: MainFormat[], to = this.state.globalOffset) {
for (let type of types) {
let status: TokenStatus,
open = this.open[type],
@ -94,7 +94,7 @@ export class TokenQueue {
}
}
/** Resolve all existing token in the queue. Often used when facing boundary or a blank line. */
resolveAll(to = this.state.gOffset) {
resolveAll(to = this.state.globalOffset) {
this.resolve([Format.INSERTION, Format.SPOILER, Format.SUPERSCRIPT, Format.SUBSCRIPT, Format.HIGHLIGHT], to);
}
clear() {

View file

@ -59,8 +59,8 @@ export const Tokenizer = {
type,
status: TokenStatus.PENDING,
role,
from: state.gOffset,
to: state.gOffset + length,
from: state.globalOffset,
to: state.globalOffset + length,
pointer: state.queue.getOpen(type)?.pointer ?? state.tokens.length,
size: 2
};
@ -96,7 +96,7 @@ export const Tokenizer = {
},
content(state: ParserState, type: MainFormat) {
// content should be indexed right after its opening delimiter
let from = state.gOffset;
let from = state.globalOffset;
let token: Token = {
type,
status: TokenStatus.PENDING,
@ -126,8 +126,8 @@ export const Tokenizer = {
type: Format.COLOR_TAG,
status: TokenStatus.ACTIVE,
role: TokenRole.INLINE_TAG,
from: state.gOffset,
to: state.gOffset + tagLen,
from: state.globalOffset,
to: state.globalOffset + tagLen,
pointer: state.tokens.length,
size: 1
};