MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / stringCtx

Function stringCtx

docs/components/editor.js:27–51  ·  view source on GitHub ↗
(src, caret)

Source from the content-addressed store, hash-verified

25
26 // Walk from 0 to caret toggling code/string. `quote === ''` means code.
27 const stringCtx = (src, caret) => {
28 let i = 0, quote = '', isF = false;
29 while (i < caret) {
30 if (!quote) {
31 if (src[i] === '#') {
32 const nl = src.indexOf('\n', i);
33 if (nl === -1 || nl >= caret) return { inStr: false, isF: false };
34 i = nl + 1; continue;
35 }
36 const m = src.slice(i).match(STRING_START);
37 if (m && i + m[0].length <= caret) {
38 quote = m[2]; isF = /[fF]/.test(m[1]);
39 i += m[0].length; continue;
40 }
41 i++;
42 } else {
43 if (quote.length === 1 && src[i] === '\\') { i += 2; continue; }
44 if (src.slice(i, i + quote.length) === quote) {
45 i += quote.length; quote = ''; isF = false; continue;
46 }
47 i++;
48 }
49 }
50 return { inStr: !!quote, isF };
51 };
52
53 const lineAt = (text, caret) => {
54 const start = text.lastIndexOf('\n', caret - 1) + 1;

Callers 1

createEditorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected