MCPcopy
hub / github.com/csev/py4e / findWordAt

Function findWordAt

tools/pythonauto/static/codemirrorepl/codemirror.js:3771–3784  ·  view source on GitHub ↗
(doc, pos)

Source from the content-addressed store, hash-verified

3769
3770 // Find the word at the given position (as returned by coordsChar).
3771 function findWordAt(doc, pos) {
3772 var line = getLine(doc, pos.line).text;
3773 var start = pos.ch, end = pos.ch;
3774 if (line) {
3775 if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
3776 var startChar = line.charAt(start);
3777 var check = isWordChar(startChar) ? isWordChar
3778 : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
3779 : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
3780 while (start > 0 && check(line.charAt(start - 1))) --start;
3781 while (end < line.length && check(line.charAt(end))) ++end;
3782 }
3783 return new Range(Pos(pos.line, start), Pos(pos.line, end));
3784 }
3785
3786 // EDITOR METHODS
3787

Callers 3

registerEventHandlersFunction · 0.70
leftButtonSelectFunction · 0.70
extendToFunction · 0.70

Calls 3

PosFunction · 0.85
getLineFunction · 0.70
isWordCharFunction · 0.70

Tested by

no test coverage detected