From 98d2974b76e3d03caa8def8e3026b9c8020aec14 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 29 Oct 2021 02:13:18 +0400 Subject: [PATCH] [vim] always use 'new Pos' to allow converting it into a class --- keymap/vim.js | 162 +++++++++++++++++++++++------------------------ test/vim_test.js | 92 +++++++++++++-------------- 2 files changed, 127 insertions(+), 127 deletions(-) diff --git a/keymap/vim.js b/keymap/vim.js index 2331a0af19..8491a49314 100644 --- a/keymap/vim.js +++ b/keymap/vim.js @@ -44,8 +44,10 @@ })(function(CodeMirror) { 'use strict'; + var Pos = CodeMirror.Pos; + function transformCursor(cm, range) { - var vim = cm.state.vim + var vim = cm.state.vim; if (!vim || vim.insertMode) return range.head; var head = vim.sel.head; if (!head) return range.head; @@ -57,7 +59,7 @@ } if (range.from() == range.anchor && !range.empty()) { if (range.head.line == head.line && range.head.ch != head.ch) - return new CodeMirror.Pos(range.head.line, range.head.ch - 1); + return new Pos(range.head.line, range.head.ch - 1); } return range.head; @@ -268,8 +270,6 @@ { name: 'global', shortName: 'g' } ]; - var Pos = CodeMirror.Pos; - var Vim = function() { function enterVimMode(cm) { cm.setOption('disableInput', true); @@ -1620,17 +1620,17 @@ var chOffset = Math.abs(lastSel.head.ch - lastSel.anchor.ch); if (lastSel.visualLine) { // Linewise Visual mode: The same number of lines. - newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch); + newHead = new Pos(oldAnchor.line + lineOffset, oldAnchor.ch); } else if (lastSel.visualBlock) { // Blockwise Visual mode: The same number of lines and columns. - newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset); + newHead = new Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset); } else if (lastSel.head.line == lastSel.anchor.line) { // Normal Visual mode within one line: The same number of characters. - newHead = Pos(oldAnchor.line, oldAnchor.ch + chOffset); + newHead = new Pos(oldAnchor.line, oldAnchor.ch + chOffset); } else { // Normal Visual mode with several lines: The same number of lines, in the // last line the same number of characters as in the last line the last time. - newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch); + newHead = new Pos(oldAnchor.line + lineOffset, oldAnchor.ch); } vim.visualMode = true; vim.visualLine = lastSel.visualLine; @@ -1670,7 +1670,7 @@ ranges[i].head.ch = lineLength(cm, ranges[i].head.line); } } else if (mode == 'line') { - ranges[0].head = Pos(ranges[0].head.line + 1, 0); + ranges[0].head = new Pos(ranges[0].head.line + 1, 0); } } } else { @@ -1732,22 +1732,22 @@ var motions = { moveToTopLine: function(cm, _head, motionArgs) { var line = getUserVisibleLines(cm).top + motionArgs.repeat -1; - return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); + return new Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); }, moveToMiddleLine: function(cm) { var range = getUserVisibleLines(cm); var line = Math.floor((range.top + range.bottom) * 0.5); - return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); + return new Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); }, moveToBottomLine: function(cm, _head, motionArgs) { var line = getUserVisibleLines(cm).bottom - motionArgs.repeat +1; - return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); + return new Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line))); }, expandToLine: function(_cm, head, motionArgs) { // Expands forward to end of line, and then to next line if repeat is // >1. Does not handle backward motion! var cur = head; - return Pos(cur.line + motionArgs.repeat - 1, Infinity); + return new Pos(cur.line + motionArgs.repeat - 1, Infinity); }, findNext: function(cm, _head, motionArgs) { var state = getSearchState(cm); @@ -1804,7 +1804,7 @@ // For whatever reason, when we use the "to" as returned by searchcursor.js directly, // the resulting selection is extended by 1 char. Let's shrink it so that only the // match is selected. - var to = Pos(next[1].line, next[1].ch - 1); + var to = new Pos(next[1].line, next[1].ch - 1); if (vim.visualMode) { // If we were in visualLine or visualBlock mode, get out of it. @@ -1853,8 +1853,8 @@ if (vim.visualBlock && motionArgs.sameLine) { var sel = vim.sel; return [ - clipCursorToContent(cm, Pos(sel.anchor.line, sel.head.ch)), - clipCursorToContent(cm, Pos(sel.head.line, sel.anchor.ch)) + clipCursorToContent(cm, new Pos(sel.anchor.line, sel.head.ch)), + clipCursorToContent(cm, new Pos(sel.head.line, sel.anchor.ch)) ]; } else { return ([vim.sel.head, vim.sel.anchor]); @@ -1894,7 +1894,7 @@ // Vim places the cursor on the first non-whitespace character of // the line if there is one, else it places the cursor at the end // of the line, regardless of whether a mark was found. - best = Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line))); + best = new Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line))); } return best; }, @@ -1902,7 +1902,7 @@ var cur = head; var repeat = motionArgs.repeat; var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat; - return Pos(cur.line, ch); + return new Pos(cur.line, ch); }, moveByLines: function(cm, head, motionArgs, vim) { var cur = head; @@ -1944,8 +1944,8 @@ endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line)); vim.lastHPos = endCh; } - vim.lastHSPos = cm.charCoords(Pos(line, endCh),'div').left; - return Pos(line, endCh); + vim.lastHSPos = cm.charCoords(new Pos(line, endCh),'div').left; + return new Pos(line, endCh); }, moveByDisplayLines: function(cm, head, motionArgs, vim) { var cur = head; @@ -1967,7 +1967,7 @@ var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos }; var res = cm.coordsChar(goalCoords, 'div'); } else { - var resCoords = cm.charCoords(Pos(cm.firstLine(), 0), 'div'); + var resCoords = cm.charCoords(new Pos(cm.firstLine(), 0), 'div'); resCoords.left = vim.lastHSPos; res = cm.coordsChar(resCoords, 'div'); } @@ -2047,7 +2047,7 @@ // Go to the start of the line where the text begins, or the end for // whitespace-only lines var cursor = head; - return Pos(cursor.line, + return new Pos(cursor.line, findFirstNonWhiteSpaceCharacter(cm.getLine(cursor.line))); }, moveToMatchedSymbol: function(cm, head) { @@ -2059,7 +2059,7 @@ for (; ch < lineText.length; ch++) { symbol = lineText.charAt(ch); if (symbol && isMatchableSymbol(symbol)) { - var style = cm.getTokenTypeAt(Pos(line, ch + 1)); + var style = cm.getTokenTypeAt(new Pos(line, ch + 1)); if (style !== "string" && style !== "comment") { break; } @@ -2068,21 +2068,21 @@ if (ch < lineText.length) { // Only include angle brackets in analysis if they are being matched. var re = (ch === '<' || ch === '>') ? /[(){}[\]<>]/ : /[(){}[\]]/; - var matched = cm.findMatchingBracket(Pos(line, ch), {bracketRegex: re}); + var matched = cm.findMatchingBracket(new Pos(line, ch), {bracketRegex: re}); return matched.to; } else { return cursor; } }, moveToStartOfLine: function(_cm, head) { - return Pos(head.line, 0); + return new Pos(head.line, 0); }, moveToLineOrEdgeOfDocument: function(cm, _head, motionArgs) { var lineNum = motionArgs.forward ? cm.lastLine() : cm.firstLine(); if (motionArgs.repeatIsExplicit) { lineNum = motionArgs.repeat - cm.getOption('firstLineNumber'); } - return Pos(lineNum, + return new Pos(lineNum, findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum))); }, textObjectManipulation: function(cm, head, motionArgs, vim) { @@ -2245,7 +2245,7 @@ if (anchor.line == cm.firstLine()) { anchor.ch = 0; } else { - anchor = Pos(anchor.line - 1, lineLength(cm, anchor.line - 1)); + anchor = new Pos(anchor.line - 1, lineLength(cm, anchor.line - 1)); } } text = cm.getRange(anchor, head); @@ -2392,7 +2392,7 @@ }, scrollToCursor: function(cm, actionArgs) { var lineNum = cm.getCursor().line; - var charCoords = cm.charCoords(Pos(lineNum, 0), 'local'); + var charCoords = cm.charCoords(new Pos(lineNum, 0), 'local'); var height = cm.getScrollInfo().clientHeight; var y = charCoords.top; var lineHeight = charCoords.bottom - y; @@ -2444,9 +2444,9 @@ var head = actionArgs.head || cm.getCursor('head'); var height = cm.listSelections().length; if (insertAt == 'eol') { - head = Pos(head.line, lineLength(cm, head.line)); + head = new Pos(head.line, lineLength(cm, head.line)); } else if (insertAt == 'bol') { - head = Pos(head.line, 0); + head = new Pos(head.line, 0); } else if (insertAt == 'charAfter') { head = offsetCursor(head, 0, 1); } else if (insertAt == 'firstNonBlank') { @@ -2458,10 +2458,10 @@ if (sel.head.line < sel.anchor.line) { head = sel.head; } else { - head = Pos(sel.anchor.line, 0); + head = new Pos(sel.anchor.line, 0); } } else { - head = Pos( + head = new Pos( Math.min(sel.head.line, sel.anchor.line), Math.min(sel.head.ch, sel.anchor.ch)); height = Math.abs(sel.head.line - sel.anchor.line) + 1; @@ -2473,10 +2473,10 @@ if (sel.head.line >= sel.anchor.line) { head = offsetCursor(sel.head, 0, 1); } else { - head = Pos(sel.anchor.line, 0); + head = new Pos(sel.anchor.line, 0); } } else { - head = Pos( + head = new Pos( Math.min(sel.head.line, sel.anchor.line), Math.max(sel.head.ch, sel.anchor.ch) + 1); height = Math.abs(sel.head.line - sel.anchor.line) + 1; @@ -2522,7 +2522,7 @@ vim.visualLine = !!actionArgs.linewise; vim.visualBlock = !!actionArgs.blockwise; head = clipCursorToContent( - cm, Pos(anchor.line, anchor.ch + repeat - 1)); + cm, new Pos(anchor.line, anchor.ch + repeat - 1)); vim.sel = { anchor: anchor, head: head @@ -2585,13 +2585,13 @@ // Repeat is the number of lines to join. Minimum 2 lines. var repeat = Math.max(actionArgs.repeat, 2); curStart = cm.getCursor(); - curEnd = clipCursorToContent(cm, Pos(curStart.line + repeat - 1, + curEnd = clipCursorToContent(cm, new Pos(curStart.line + repeat - 1, Infinity)); } var finalCh = 0; for (var i = curStart.line; i < curEnd.line; i++) { finalCh = lineLength(cm, curStart.line); - var tmp = Pos(curStart.line + 1, + var tmp = new Pos(curStart.line + 1, lineLength(cm, curStart.line + 1)); var text = cm.getRange(curStart, tmp); text = actionArgs.keepSpaces @@ -2599,7 +2599,7 @@ : text.replace(/\n\s*/g, ' '); cm.replaceRange(text, curStart, tmp); } - var curFinalPos = Pos(curStart.line, finalCh); + var curFinalPos = new Pos(curStart.line, finalCh); if (vim.visualMode) { exitVisualMode(cm, false); } @@ -2610,7 +2610,7 @@ var insertAt = copyCursor(cm.getCursor()); if (insertAt.line === cm.firstLine() && !actionArgs.after) { // Special case for inserting newline before start of document. - cm.replaceRange('\n', Pos(cm.firstLine(), 0)); + cm.replaceRange('\n', new Pos(cm.firstLine(), 0)); cm.setCursor(cm.firstLine(), 0); } else { insertAt.line = (actionArgs.after) ? insertAt.line : @@ -2711,7 +2711,7 @@ // first delete the selected text cm.replaceSelections(emptyStrings); // Set new selections as per the block length of the yanked text - selectionEnd = Pos(selectionStart.line + text.length-1, selectionStart.ch); + selectionEnd = new Pos(selectionStart.line + text.length-1, selectionStart.ch); cm.setCursor(selectionStart); selectBlock(cm, selectionEnd); cm.replaceSelections(text); @@ -2738,7 +2738,7 @@ for (var i = 0; i < text.length; i++) { var line = cur.line+i; if (line > cm.lastLine()) { - cm.replaceRange('\n', Pos(line, 0)); + cm.replaceRange('\n', new Pos(line, 0)); } var lastCh = lineLength(cm, line); if (lastCh < cur.ch) { @@ -2746,18 +2746,18 @@ } } cm.setCursor(cur); - selectBlock(cm, Pos(cur.line + text.length-1, cur.ch)); + selectBlock(cm, new Pos(cur.line + text.length-1, cur.ch)); cm.replaceSelections(text); curPosFinal = cur; } else { cm.replaceRange(text, cur); // Now fine tune the cursor to where we want it. if (linewise && actionArgs.after) { - curPosFinal = Pos( + curPosFinal = new Pos( cur.line + 1, findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1))); } else if (linewise && !actionArgs.after) { - curPosFinal = Pos( + curPosFinal = new Pos( cur.line, findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line))); } else if (!linewise && actionArgs.after) { @@ -2805,7 +2805,7 @@ if (replaceTo > line.length) { replaceTo=line.length; } - curEnd = Pos(curStart.line, replaceTo); + curEnd = new Pos(curStart.line, replaceTo); } if (replaceWith=='\n') { if (!vim.visualMode) cm.replaceRange('', curStart, curEnd); @@ -2861,13 +2861,13 @@ } else { numberStr = baseStr + zeroPadding + numberStr; } - var from = Pos(cur.line, start); - var to = Pos(cur.line, end); + var from = new Pos(cur.line, start); + var to = new Pos(cur.line, end); cm.replaceRange(numberStr, from, to); } else { return; } - cm.setCursor(Pos(cur.line, start + numberStr.length - 1)); + cm.setCursor(new Pos(cur.line, start + numberStr.length - 1)); }, repeatLastEdit: function(cm, actionArgs, vim) { var lastEditInputState = vim.lastEditInputState; @@ -2904,7 +2904,7 @@ var line = Math.min(Math.max(cm.firstLine(), cur.line), cm.lastLine() ); var maxCh = lineLength(cm, line) - 1 + !!includeLineBreak; var ch = Math.min(Math.max(0, cur.ch), maxCh); - return Pos(line, ch); + return new Pos(line, ch); } function copyArgs(args) { var ret = {}; @@ -2920,7 +2920,7 @@ offsetCh = offsetLine.ch; offsetLine = offsetLine.line; } - return Pos(cur.line + offsetLine, cur.ch + offsetCh); + return new Pos(cur.line + offsetLine, cur.ch + offsetCh); } function commandMatches(keys, keyMap, context, inputState) { // Partial matches are not applied. They inform the key handler @@ -2980,7 +2980,7 @@ }; } function copyCursor(cur) { - return Pos(cur.line, cur.ch); + return new Pos(cur.line, cur.ch); } function cursorEqual(cur1, cur2) { return cur1.ch == cur2.ch && cur1.line == cur2.line; @@ -3027,7 +3027,7 @@ function extendLineToColumn(cm, lineNum, column) { var endCh = lineLength(cm, lineNum); var spaces = new Array(column-endCh+1).join(' '); - cm.setCursor(Pos(lineNum, endCh)); + cm.setCursor(new Pos(lineNum, endCh)); cm.replaceRange(spaces, cm.getCursor()); } // This functions selects a rectangular block @@ -3108,13 +3108,13 @@ if (block) { var width = block.width; var height = block.height; - selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width); + selectionEnd = new Pos(selectionStart.line + height, selectionStart.ch + width); var selections = []; // selectBlock creates a 'proper' rectangular block. // We do not want that in all cases, so we manually set selections. for (var i = selectionStart.line; i < selectionEnd.line; i++) { - var anchor = Pos(i, selectionStart.ch); - var head = Pos(i, selectionEnd.ch); + var anchor = new Pos(i, selectionStart.ch); + var head = new Pos(i, selectionEnd.ch); var range = {anchor: anchor, head: head}; selections.push(range); } @@ -3126,8 +3126,8 @@ var ch = end.ch - start.ch; selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch}; if (lastSelection.visualLine) { - selectionStart = Pos(selectionStart.line, 0); - selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line)); + selectionStart = new Pos(selectionStart.line, 0); + selectionEnd = new Pos(selectionEnd.line, lineLength(cm, selectionEnd.line)); } cm.setSelection(selectionStart, selectionEnd); } @@ -3176,7 +3176,7 @@ head = cursorMax(head, end); head = offsetCursor(head, 0, -1); if (head.ch == -1 && head.line != cm.firstLine()) { - head = Pos(head.line - 1, lineLength(cm, head.line - 1)); + head = new Pos(head.line - 1, lineLength(cm, head.line - 1)); } } return [anchor, head]; @@ -3234,8 +3234,8 @@ var ranges = []; for (var i = 0; i < height; i++) { ranges.push({ - anchor: Pos(top + i, fromCh), - head: Pos(top + i, toCh) + anchor: new Pos(top + i, fromCh), + head: new Pos(top + i, toCh) }); } return { @@ -3356,7 +3356,7 @@ if (!start) { start = wordStart; } } } - return { start: Pos(cur.line, start), end: Pos(cur.line, end) }; + return { start: new Pos(cur.line, start), end: new Pos(cur.line, end) }; } /** @@ -3530,7 +3530,7 @@ } } if (state.nextCh || state.curMoveThrough) { - return Pos(line, state.index); + return new Pos(line, state.index); } return cur; } @@ -3642,7 +3642,7 @@ break; } words.push(word); - cur = Pos(word.line, forward ? (word.to - 1) : word.from); + cur = new Pos(word.line, forward ? (word.to - 1) : word.from); } var shortCircuit = words.length != repeat; var firstWord = words[0]; @@ -3653,25 +3653,25 @@ // We did not start in the middle of a word. Discard the extra word at the end. lastWord = words.pop(); } - return Pos(lastWord.line, lastWord.from); + return new Pos(lastWord.line, lastWord.from); } else if (forward && wordEnd) { - return Pos(lastWord.line, lastWord.to - 1); + return new Pos(lastWord.line, lastWord.to - 1); } else if (!forward && wordEnd) { // ge if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) { // We did not start in the middle of a word. Discard the extra word at the end. lastWord = words.pop(); } - return Pos(lastWord.line, lastWord.to); + return new Pos(lastWord.line, lastWord.to); } else { // b - return Pos(lastWord.line, lastWord.from); + return new Pos(lastWord.line, lastWord.from); } } function moveToEol(cm, head, motionArgs, vim, keepHPos) { var cur = head; - var retval= Pos(cur.line + motionArgs.repeat - 1, Infinity); + var retval= new Pos(cur.line + motionArgs.repeat - 1, Infinity); var end=cm.clipPos(retval); end.ch--; if (!keepHPos) { @@ -3693,14 +3693,14 @@ } start = idx; } - return Pos(cm.getCursor().line, idx); + return new Pos(cm.getCursor().line, idx); } function moveToColumn(cm, repeat) { // repeat is always >= 1, so repeat - 1 always corresponds // to the column we want to go to. var line = cm.getCursor().line; - return clipCursorToContent(cm, Pos(line, repeat - 1)); + return clipCursorToContent(cm, new Pos(line, repeat - 1)); } function updateMark(cm, vim, markName, pos) { @@ -3952,7 +3952,7 @@ repeat--; } - return Pos(curr_index.ln, curr_index.pos); + return new Pos(curr_index.ln, curr_index.pos); } // TODO: perhaps this finagling of start and end positions belongs @@ -3975,8 +3975,8 @@ // cursor is on a matching open bracket. var offset = curChar === openSym ? 1 : 0; - start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, undefined, {'bracketRegex': bracketRegexp}); - end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, undefined, {'bracketRegex': bracketRegexp}); + start = cm.scanForBracket(new Pos(cur.line, cur.ch + offset), -1, undefined, {'bracketRegex': bracketRegexp}); + end = cm.scanForBracket(new Pos(cur.line, cur.ch + offset), 1, undefined, {'bracketRegex': bracketRegexp}); if (!start || !end) { return { start: cur, end: cur }; @@ -4057,8 +4057,8 @@ } return { - start: Pos(cur.line, start), - end: Pos(cur.line, end) + start: new Pos(cur.line, start), + end: new Pos(cur.line, end) }; } @@ -4448,7 +4448,7 @@ // SearchCursor may have returned null because it hit EOF, wrap // around and try again. cursor = cm.getSearchCursor(query, - (prev) ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0) ); + (prev) ? new Pos(cm.lastLine()) : new Pos(cm.firstLine(), 0) ); if (!cursor.find(prev)) { return; } @@ -4484,7 +4484,7 @@ // SearchCursor may have returned null because it hit EOF, wrap // around and try again. cursor = cm.getSearchCursor(query, - (prev) ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0) ); + (prev) ? new Pos(cm.lastLine()) : new Pos(cm.firstLine(), 0) ); if (!cursor.find(prev)) { return; } @@ -4540,7 +4540,7 @@ function getMarkPos(cm, vim, markName) { if (markName == '\'' || markName == '`') { - return vimGlobalState.jumpList.find(cm, -1) || Pos(0, 0); + return vimGlobalState.jumpList.find(cm, -1) || new Pos(0, 0); } else if (markName == '.') { return getLastEditPos(cm); } @@ -4951,8 +4951,8 @@ var lineStart = params.line || cm.firstLine(); var lineEnd = params.lineEnd || params.line || cm.lastLine(); if (lineStart == lineEnd) { return; } - var curStart = Pos(lineStart, 0); - var curEnd = Pos(lineEnd, lineLength(cm, lineEnd)); + var curStart = new Pos(lineStart, 0); + var curEnd = new Pos(lineEnd, lineLength(cm, lineEnd)); var text = cm.getRange(curStart, curEnd).split('\n'); var numberRegex = pattern ? pattern : (number == 'decimal') ? /(-?)([\d]+)/ : @@ -5158,7 +5158,7 @@ lineStart = lineEnd; lineEnd = lineStart + count - 1; } - var startPos = clipCursorToContent(cm, Pos(lineStart, 0)); + var startPos = clipCursorToContent(cm, new Pos(lineStart, 0)); var cursor = cm.getSearchCursor(query, startPos); doReplace(cm, confirm, global, lineStart, lineEnd, cursor, query, replacePart, params.callback); }, diff --git a/test/vim_test.js b/test/vim_test.js index 3506b8818d..b6bb4cf366 100644 --- a/test/vim_test.js +++ b/test/vim_test.js @@ -571,14 +571,14 @@ testVim('paragraph_motions', function(cm, vim, helpers) { // ip inside empty space cm.setCursor(10, 0); helpers.doKeys('v', 'i', 'p'); - eqCursorPos(Pos(7, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(12, 0), cm.getCursor('head')); + eqCursorPos(new Pos(7, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(12, 0), cm.getCursor('head')); helpers.doKeys('i', 'p'); - eqCursorPos(Pos(7, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(13, 1), cm.getCursor('head')); + eqCursorPos(new Pos(7, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(13, 1), cm.getCursor('head')); helpers.doKeys('2', 'i', 'p'); - eqCursorPos(Pos(7, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(16, 1), cm.getCursor('head')); + eqCursorPos(new Pos(7, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(16, 1), cm.getCursor('head')); // should switch to visualLine mode cm.setCursor(14, 0); @@ -587,31 +587,31 @@ testVim('paragraph_motions', function(cm, vim, helpers) { cm.setCursor(14, 0); helpers.doKeys('', 'V', 'i', 'p'); - eqCursorPos(Pos(16, 1), cm.getCursor('head')); + eqCursorPos(new Pos(16, 1), cm.getCursor('head')); // ap inside empty space cm.setCursor(10, 0); helpers.doKeys('', 'v', 'a', 'p'); - eqCursorPos(Pos(7, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(13, 1), cm.getCursor('head')); + eqCursorPos(new Pos(7, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(13, 1), cm.getCursor('head')); helpers.doKeys('a', 'p'); - eqCursorPos(Pos(7, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(16, 1), cm.getCursor('head')); + eqCursorPos(new Pos(7, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(16, 1), cm.getCursor('head')); cm.setCursor(13, 0); helpers.doKeys('v', 'a', 'p'); - eqCursorPos(Pos(13, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(14, 0), cm.getCursor('head')); + eqCursorPos(new Pos(13, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(14, 0), cm.getCursor('head')); cm.setCursor(16, 0); helpers.doKeys('v', 'a', 'p'); - eqCursorPos(Pos(14, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(16, 1), cm.getCursor('head')); + eqCursorPos(new Pos(14, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(16, 1), cm.getCursor('head')); cm.setCursor(0, 0); helpers.doKeys('v', 'a', 'p'); - eqCursorPos(Pos(0, 0), cm.getCursor('anchor')); - eqCursorPos(Pos(4, 0), cm.getCursor('head')); + eqCursorPos(new Pos(0, 0), cm.getCursor('anchor')); + eqCursorPos(new Pos(4, 0), cm.getCursor('head')); cm.setCursor(0, 0); helpers.doKeys('d', 'i', 'p'); @@ -1473,7 +1473,7 @@ testSelection('vi{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'vi{', '\n\tbar\n\t'); testSelection('va{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'va{', '{\n\tbar\n\t}'); testVim('mouse_select', function(cm, vim, helpers) { - cm.setSelection(Pos(0, 2), Pos(0, 4), {origin: '*mouse'}); + cm.setSelection(new Pos(0, 2), new Pos(0, 4), {origin: '*mouse'}); is(cm.state.vim.visualMode); is(!cm.state.vim.visualLine); is(!cm.state.vim.visualBlock); @@ -1665,7 +1665,7 @@ testVim('i_overwrite_backspace', function(cm, vim, helpers) { helpers.doKeys('i'); helpers.doKeys(''); helpers.doKeys('Backspace'); - helpers.assertCursorAt(Pos(0, 9, "after")); + helpers.assertCursorAt(new Pos(0, 9, "after")); eq('0123456789', cm.getValue()); }, { value: '0123456789'}); testVim('i_forward_delete', function(cm, vim, helpers) { @@ -2225,20 +2225,20 @@ testVim('visual_crossover_left', function(cm, vim, helpers) { testVim('visual_crossover_up', function(cm, vim, helpers) { cm.setCursor(3, 2); helpers.doKeys('v', 'j', 'k', 'k'); - eqCursorPos(Pos(2, 2), cm.getCursor('head')); - eqCursorPos(Pos(3, 3), cm.getCursor('anchor')); + eqCursorPos(new Pos(2, 2), cm.getCursor('head')); + eqCursorPos(new Pos(3, 3), cm.getCursor('anchor')); helpers.doKeys('k'); - eqCursorPos(Pos(1, 2), cm.getCursor('head')); - eqCursorPos(Pos(3, 3), cm.getCursor('anchor')); + eqCursorPos(new Pos(1, 2), cm.getCursor('head')); + eqCursorPos(new Pos(3, 3), cm.getCursor('anchor')); }, { value: 'cross\ncross\ncross\ncross\ncross\n'}); testVim('visual_crossover_down', function(cm, vim, helpers) { cm.setCursor(1, 2); helpers.doKeys('v', 'k', 'j', 'j'); - eqCursorPos(Pos(2, 3), cm.getCursor('head')); - eqCursorPos(Pos(1, 2), cm.getCursor('anchor')); + eqCursorPos(new Pos(2, 3), cm.getCursor('head')); + eqCursorPos(new Pos(1, 2), cm.getCursor('anchor')); helpers.doKeys('j'); - eqCursorPos(Pos(3, 3), cm.getCursor('head')); - eqCursorPos(Pos(1, 2), cm.getCursor('anchor')); + eqCursorPos(new Pos(3, 3), cm.getCursor('head')); + eqCursorPos(new Pos(1, 2), cm.getCursor('anchor')); }, { value: 'cross\ncross\ncross\ncross\ncross\n'}); testVim('visual_exit', function(cm, vim, helpers) { helpers.doKeys('', 'l', 'j', 'j', ''); @@ -2393,14 +2393,14 @@ testVim('reselect_visual_block', function(cm, vim, helpers) { helpers.doKeys('', 'k', 'h', ''); cm.setCursor(2, 1); helpers.doKeys('v', 'l', 'g', 'v'); - eqCursorPos(Pos(1, 2), vim.sel.anchor); - eqCursorPos(Pos(0, 1), vim.sel.head); + eqCursorPos(new Pos(1, 2), vim.sel.anchor); + eqCursorPos(new Pos(0, 1), vim.sel.head); // Ensure selection is done with visual block mode rather than one // continuous range. eq(cm.getSelections().join(''), '23oo') helpers.doKeys('g', 'v'); - eqCursorPos(Pos(2, 1), vim.sel.anchor); - eqCursorPos(Pos(2, 2), vim.sel.head); + eqCursorPos(new Pos(2, 1), vim.sel.anchor); + eqCursorPos(new Pos(2, 2), vim.sel.head); helpers.doKeys(''); // Ensure selection of deleted range cm.setCursor(1, 1); @@ -2435,14 +2435,14 @@ testVim('o_visual', function(cm, vim, helpers) { testVim('o_visual_block', function(cm, vim, helpers) { cm.setCursor(0, 1); helpers.doKeys('','3','j','l','l', 'o'); - eqCursorPos(Pos(3, 3), vim.sel.anchor); - eqCursorPos(Pos(0, 1), vim.sel.head); + eqCursorPos(new Pos(3, 3), vim.sel.anchor); + eqCursorPos(new Pos(0, 1), vim.sel.head); helpers.doKeys('O'); - eqCursorPos(Pos(3, 1), vim.sel.anchor); - eqCursorPos(Pos(0, 3), vim.sel.head); + eqCursorPos(new Pos(3, 1), vim.sel.anchor); + eqCursorPos(new Pos(0, 3), vim.sel.head); helpers.doKeys('o'); - eqCursorPos(Pos(0, 3), vim.sel.anchor); - eqCursorPos(Pos(3, 1), vim.sel.head); + eqCursorPos(new Pos(0, 3), vim.sel.anchor); + eqCursorPos(new Pos(3, 1), vim.sel.head); }, { value: 'abcd\nefgh\nijkl\nmnop'}); testVim('changeCase_visual', function(cm, vim, helpers) { cm.setCursor(0, 0); @@ -3563,7 +3563,7 @@ testVim('zb_to_bottom', function(cm, vim, helpers){ cm.setCursor(lineNum, 0); helpers.doKeys('z', 'b'); var scrollInfo = cm.getScrollInfo(); - eq(scrollInfo.top + scrollInfo.clientHeight, cm.charCoords(Pos(lineNum, 0), 'local').bottom); + eq(scrollInfo.top + scrollInfo.clientHeight, cm.charCoords(new Pos(lineNum, 0), 'local').bottom); }, { value: (function(){ return new Array(500).join('\n'); })()}); @@ -3572,7 +3572,7 @@ testVim('zt_to_top', function(cm, vim, helpers){ cm.setSize(600, 35*cm.defaultTextHeight()); cm.setCursor(lineNum, 0); helpers.doKeys('z', 't'); - eq(cm.getScrollInfo().top, cm.charCoords(Pos(lineNum, 0), 'local').top); + eq(cm.getScrollInfo().top, cm.charCoords(new Pos(lineNum, 0), 'local').top); }, { value: (function(){ return new Array(500).join('\n'); })()}); @@ -4659,10 +4659,10 @@ testVim('noremap_swap', function(cm, vim, helpers) { cm.setCursor(0, 0); // 'a' should act like 'i'. helpers.doKeys('a'); - eqCursorPos(Pos(0, 0), cm.getCursor()); + eqCursorPos(new Pos(0, 0), cm.getCursor()); // ...and 'i' should act like 'a'. helpers.doKeys('', 'i'); - eqCursorPos(Pos(0, 1), cm.getCursor()); + eqCursorPos(new Pos(0, 1), cm.getCursor()); // unmap all mappings CodeMirror.Vim.mapclear(); }, { value: 'foo' }); @@ -4673,13 +4673,13 @@ testVim('noremap_map_interaction', function(cm, vim, helpers) { CodeMirror.Vim.map('l', 'j'); cm.setCursor(0, 0); helpers.doKeys(';'); - eqCursorPos(Pos(0, 1), cm.getCursor()); + eqCursorPos(new Pos(0, 1), cm.getCursor()); helpers.doKeys('l'); - eqCursorPos(Pos(1, 1), cm.getCursor()); + eqCursorPos(new Pos(1, 1), cm.getCursor()); // map should be able to point to a noremap CodeMirror.Vim.map('m', ';'); helpers.doKeys('m'); - eqCursorPos(Pos(1, 2), cm.getCursor()); + eqCursorPos(new Pos(1, 2), cm.getCursor()); // unmap all mappings CodeMirror.Vim.mapclear(); }, { value: 'wOrd1\nwOrd2' }); @@ -4690,9 +4690,9 @@ testVim('noremap_map_interaction2', function(cm, vim, helpers) { CodeMirror.Vim.noremap(';', 'h'); cm.setCursor(0, 0); helpers.doKeys('l'); - eqCursorPos(Pos(0, 1), cm.getCursor()); + eqCursorPos(new Pos(0, 1), cm.getCursor()); helpers.doKeys('m'); - eqCursorPos(Pos(0, 0), cm.getCursor()); + eqCursorPos(new Pos(0, 0), cm.getCursor()); // unmap all mappings CodeMirror.Vim.mapclear(); }, { value: 'wOrd1\nwOrd2' });