MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / findWordAt

Function findWordAt

static/js/codemirror/codemirror.js:2574–2586  ·  view source on GitHub ↗
(line, pos)

Source from the content-addressed store, hash-verified

2572 }
2573
2574 function findWordAt(line, pos) {
2575 var start = pos.ch, end = pos.ch;
2576 if (line) {
2577 if (pos.after === false || end == line.length) --start; else ++end;
2578 var startChar = line.charAt(start);
2579 var check = isWordChar(startChar) ? isWordChar :
2580 /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);} :
2581 function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
2582 while (start > 0 && check(line.charAt(start - 1))) --start;
2583 while (end < line.length && check(line.charAt(end))) ++end;
2584 }
2585 return {from: Pos(pos.line, start), to: Pos(pos.line, end)};
2586 }
2587
2588 function selectLine(cm, line) {
2589 extendSelection(cm.doc, Pos(line, 0), clipPos(cm.doc, Pos(line + 1, 0)));

Callers 2

onMouseDownFunction · 0.85
doSelectFunction · 0.85

Calls 3

isWordCharFunction · 0.85
PosFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected