(...args)
| 54 | // movement (e.g. "w"). |
| 55 | // |
| 56 | runMovement(...args) { |
| 57 | // Normalize the various argument forms. |
| 58 | const [direction, granularity] = (typeof (args[0]) === "string") && (args.length === 1) |
| 59 | ? args[0].trim().split(/\s+/) |
| 60 | : (args.length === 1 ? args[0] : args.slice(0, 2)); |
| 61 | |
| 62 | // Native word movements behave differently on Linux and Windows, see #1441. So we implement |
| 63 | // some of them character-by-character. |
| 64 | if ((granularity === vimword) && (direction === forward)) { |
| 65 | // Extend selection to the end of the 'vimword'. |
| 66 | while (this.nextCharacterIsWordCharacter()) { |
| 67 | if (this.extendByOneCharacter(forward) === 0) { |
| 68 | return; |
| 69 | } |
| 70 | } |
| 71 | // Extend selection after the 'vimword' to position before next word. |
| 72 | while (this.getNextForwardCharacter() && !this.nextCharacterIsWordCharacter()) { |
| 73 | if (this.extendByOneCharacter(forward) === 0) { |
| 74 | return; |
| 75 | } |
| 76 | } |
| 77 | // In Caret Mode collapse selection to the end. |
| 78 | if (this.alterMethod === "move") { |
| 79 | this.selection.collapseToEnd(); |
| 80 | } |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | // As above, we implement this character-by-character to get consistent behavior on Windows and |
| 85 | // Linux. |
| 86 | if ((granularity === word) && (direction === forward)) { |
| 87 | // Extend selection to the start of the next 'word' (non-word characters, e.g. whitespace). |
| 88 | while (this.getNextForwardCharacter() && !this.nextCharacterIsWordCharacter()) { |
| 89 | if (this.extendByOneCharacter(forward) === 0) { |
| 90 | return; |
| 91 | } |
| 92 | } |
| 93 | // Extend selection to the end of the 'word'. |
| 94 | while (this.nextCharacterIsWordCharacter()) { |
| 95 | if (this.extendByOneCharacter(forward) === 0) { |
| 96 | return; |
| 97 | } |
| 98 | } |
| 99 | // In Caret Mode collapse selection to the end. |
| 100 | if (this.alterMethod === "move") { |
| 101 | this.selection.collapseToEnd(); |
| 102 | } |
| 103 | return; |
| 104 | } else { |
| 105 | this.selection.modify(this.alterMethod, direction, granularity); |
| 106 | return; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // Swap the anchor node/offset and the focus node/offset. This allows us to work with both ends of |
| 111 | // the selection, and implements "o" for visual mode. |
no test coverage detected