MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / findWord

Function findWord

mini-code-edit/cm/keymap/vim.js:96–114  ·  view source on GitHub ↗
(line, pos, dir, regexps)

Source from the content-addressed store, hash-verified

94
95 var word = [/\w/, /[^\w\s]/], bigWord = [/\S/];
96 function findWord(line, pos, dir, regexps) {
97 var stop = 0, next = -1;
98 if (dir > 0) { stop = line.length; next = 0; }
99 var start = stop, end = stop;
100 // Find bounds of next one.
101 outer: for (; pos != stop; pos += dir) {
102 for (var i = 0; i < regexps.length; ++i) {
103 if (regexps[i].test(line.charAt(pos + next))) {
104 start = pos;
105 for (; pos != stop; pos += dir) {
106 if (!regexps[i].test(line.charAt(pos + next))) break;
107 }
108 end = pos;
109 break outer;
110 }
111 }
112 }
113 return {from: Math.min(start, end), to: Math.max(start, end)};
114 }
115 function moveToWord(cm, regexps, dir, where) {
116 var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line), word;
117 while (true) {

Callers 1

moveToWordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected