Skip to content

Commit

Permalink
[sublime bindings] Fix sub-word motion at start of word
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Dec 20, 2019
1 parent 27ec446 commit 0a2b876
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions keymap/sublime.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
var line = doc.getLine(start.line);
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
var state = "start", type;
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var state = "start", type, startPos = start.ch;
for (var pos = startPos, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var next = line.charAt(dir < 0 ? pos - 1 : pos);
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
if (cat == "w" && next.toUpperCase() == next) cat = "W";
if (state == "start") {
if (cat != "o") { state = "in"; type = cat; }
else startPos = pos + dir
} else if (state == "in") {
if (type != cat) {
if (type == "w" && cat == "W" && dir < 0) pos--;
if (type == "W" && cat == "w" && dir > 0) { // From uppercase to lowercase
if (pos == start.ch + 1) { type = "w"; continue; }
if (pos == startPos + 1) { type = "w"; continue; }
else pos--;
}
break;
Expand Down

0 comments on commit 0a2b876

Please sign in to comment.