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

Function charIdxInLine

mini-code-edit/cm/keymap/vim.js:165–181  ·  view source on GitHub ↗
(cm, cHar, motion_options)

Source from the content-addressed store, hash-verified

163 }
164
165 function charIdxInLine(cm, cHar, motion_options) {
166 // Search for cHar in line.
167 // motion_options: {forward, inclusive}
168 // If inclusive = true, include it too.
169 // If forward = true, search forward, else search backwards.
170 // If char is not found on this line, do nothing
171 var cur = cm.getCursor(), line = cm.getLine(cur.line), idx;
172 var ch = toLetter(cHar), mo = motion_options;
173 if (mo.forward) {
174 idx = line.indexOf(ch, cur.ch + 1);
175 if (idx != -1 && mo.inclusive) idx += 1;
176 } else {
177 idx = line.lastIndexOf(ch, cur.ch);
178 if (idx != -1 && !mo.inclusive) idx += 1;
179 }
180 return idx;
181 }
182
183 function moveTillChar(cm, cHar, motion_options) {
184 // Move to cHar in line, as found by charIdxInLine.

Callers 2

moveTillCharFunction · 0.85
delTillCharFunction · 0.85

Calls 1

toLetterFunction · 0.85

Tested by

no test coverage detected