Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed off by one error in operating on text objects #1370

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 8 additions & 16 deletions keymap/vim.js
Expand Up @@ -1658,26 +1658,18 @@
var cur = cm.getCursor();
var line = cm.getLine(cur.line);
var idx = cur.ch;

// Seek to first word or non-whitespace character, depending on if
// noSymbol is true.
var textAfterIdx = line.substring(idx);
var firstMatchedChar;
if (noSymbol) {
firstMatchedChar = textAfterIdx.search(/\w/);
} else {
firstMatchedChar = textAfterIdx.search(/\S/);
}
if (firstMatchedChar == -1) {
return null;
}
idx += firstMatchedChar;
textAfterIdx = line.substring(idx);
var textBeforeIdx = line.substring(0, idx);

// If the cursor is sitting on whitespace, expand the selection to all
// the adjacent consecutive whitespace
var expandWhitespace = line[idx].match(/\s/);

var matchRegex;
// Greedy matchers for the "word" we are trying to expand.
if (bigWord) {
if (expandWhitespace) {
matchRegex = /^\s+/;
} else if (bigWord) {
matchRegex = /^\S+/;
} else {
if ((/\w/).test(line.charAt(idx))) {
Expand All @@ -1689,7 +1681,7 @@

var wordAfterRegex = matchRegex.exec(textAfterIdx);
var wordStart = idx;
var wordEnd = idx + wordAfterRegex[0].length - 1;
var wordEnd = idx + wordAfterRegex[0].length;
// TODO: Find a better way to do this. It will be slow on very long lines.
var wordBeforeRegex = matchRegex.exec(reverse(textBeforeIdx));
if (wordBeforeRegex) {
Expand Down