MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / readWordBefore

Function readWordBefore

src/cm/colorView.ts:81–94  ·  view source on GitHub ↗
(doc: Text, index: number)

Source from the content-addressed store, hash-verified

79}
80
81function readWordBefore(doc: Text, index: number): string {
82 let pos = index;
83 while (pos >= 0 && isWhitespace(charAt(doc, pos))) pos--;
84 if (pos < 0) return "";
85 if (charAt(doc, pos) === "(") {
86 pos--;
87 }
88 while (pos >= 0 && isWhitespace(charAt(doc, pos))) pos--;
89 const end = pos;
90 while (pos >= 0 && isAlpha(charAt(doc, pos))) pos--;
91 const start = pos + 1;
92 if (end < start) return "";
93 return doc.sliceString(start, end + 1).toLowerCase();
94}
95
96function shouldRenderColor(doc: Text, start: number, end: number): boolean {
97 const immediatePrev = charAt(doc, start - 1);

Callers 1

shouldRenderColorFunction · 0.85

Calls 3

charAtFunction · 0.85
isAlphaFunction · 0.85
isWhitespaceFunction · 0.70

Tested by

no test coverage detected