MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / findSentence

Function findSentence

lib/web/CodeMirror/keymap/vim.js:3800–3971  ·  view source on GitHub ↗
(cm, cur, repeat, dir)

Source from the content-addressed store, hash-verified

3798 }
3799
3800 function findSentence(cm, cur, repeat, dir) {
3801
3802 /*
3803 Takes an index object
3804 {
3805 line: the line string,
3806 ln: line number,
3807 pos: index in line,
3808 dir: direction of traversal (-1 or 1)
3809 }
3810 and modifies the line, ln, and pos members to represent the
3811 next valid position or sets them to null if there are
3812 no more valid positions.
3813 */
3814 function nextChar(cm, idx) {
3815 if (idx.pos + idx.dir < 0 || idx.pos + idx.dir >= idx.line.length) {
3816 idx.ln += idx.dir;
3817 if (!isLine(cm, idx.ln)) {
3818 idx.line = null;
3819 idx.ln = null;
3820 idx.pos = null;
3821 return;
3822 }
3823 idx.line = cm.getLine(idx.ln);
3824 idx.pos = (idx.dir > 0) ? 0 : idx.line.length - 1;
3825 }
3826 else {
3827 idx.pos += idx.dir;
3828 }
3829 }
3830
3831 /*
3832 Performs one iteration of traversal in forward direction
3833 Returns an index object of the new location
3834 */
3835 function forward(cm, ln, pos, dir) {
3836 var line = cm.getLine(ln);
3837 var stop = (line === "");
3838
3839 var curr = {
3840 line: line,
3841 ln: ln,
3842 pos: pos,
3843 dir: dir,
3844 }
3845
3846 var last_valid = {
3847 ln: curr.ln,
3848 pos: curr.pos,
3849 }
3850
3851 var skip_empty_lines = (curr.line === "");
3852
3853 // Move one step to skip character we start on
3854 nextChar(cm, curr);
3855
3856 while (curr.line !== null) {
3857 last_valid.ln = curr.ln;

Callers 1

VimFunction · 0.85

Calls 3

reverseFunction · 0.85
forwardFunction · 0.85
PosFunction · 0.50

Tested by

no test coverage detected