MCPcopy Create free account
hub / github.com/sql-js/sql.js / findWordAt

Function findWordAt

GUI/codemirror/lib/codemirror.js:3810–3823  ·  view source on GitHub ↗
(doc, pos)

Source from the content-addressed store, hash-verified

3808
3809 // Find the word at the given position (as returned by coordsChar).
3810 function findWordAt(doc, pos) {
3811 var line = getLine(doc, pos.line).text;
3812 var start = pos.ch, end = pos.ch;
3813 if (line) {
3814 if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
3815 var startChar = line.charAt(start);
3816 var check = isWordChar(startChar) ? isWordChar
3817 : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
3818 : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
3819 while (start > 0 && check(line.charAt(start - 1))) --start;
3820 while (end < line.length && check(line.charAt(end))) ++end;
3821 }
3822 return new Range(Pos(pos.line, start), Pos(pos.line, end));
3823 }
3824
3825 // EDITOR METHODS
3826

Callers 3

registerEventHandlersFunction · 0.85
leftButtonSelectFunction · 0.85
extendToFunction · 0.85

Calls 1

getLineFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…