MCPcopy
hub / github.com/pandao/editor.md / takeToken

Function takeToken

lib/codemirror/lib/codemirror.js:6566–6585  ·  view source on GitHub ↗
(cm, pos, precise, asArray)

Source from the content-addressed store, hash-verified

6564
6565 // Utility for getTokenAt and getLineTokens
6566 function takeToken(cm, pos, precise, asArray) {
6567 function getObj(copy) {
6568 return {start: stream.start, end: stream.pos,
6569 string: stream.current(),
6570 type: style || null,
6571 state: copy ? copyState(doc.mode, state) : state};
6572 }
6573
6574 var doc = cm.doc, mode = doc.mode, style;
6575 pos = clipPos(doc, pos);
6576 var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
6577 var stream = new StringStream(line.text, cm.options.tabSize), tokens;
6578 if (asArray) tokens = [];
6579 while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
6580 stream.start = stream.pos;
6581 style = readToken(mode, stream, state);
6582 if (asArray) tokens.push(getObj(true));
6583 }
6584 return asArray ? tokens : getObj();
6585 }
6586
6587 // Run the given mode's parser over a line, calling f for each token.
6588 function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {

Callers 1

codemirror.jsFile · 0.70

Calls 5

clipPosFunction · 0.70
getLineFunction · 0.70
getStateBeforeFunction · 0.70
readTokenFunction · 0.70
getObjFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…