Skip to content

Commit

Permalink
[sublime bindings] Add shortcut Ctrl-K Ctrl-D: find_under_expand_skip
Browse files Browse the repository at this point in the history
  • Loading branch information
axellew authored and marijnh committed Dec 23, 2019
1 parent 4f0c03c commit 11272b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions keymap/sublime.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@
cm.state.sublimeFindFullWord = cm.doc.sel;
};

cmds.skipAndSelectNextOccurrence = function(cm) {
var prevAnchor = cm.getCursor("anchor"), prevHead = cm.getCursor("head");
cmds.selectNextOccurrence(cm);
if (CodeMirror.cmpPos(prevAnchor, prevHead) != 0) {
cm.doc.setSelections(cm.doc.listSelections()
.filter(function (sel) {
return sel.anchor != prevAnchor || sel.head != prevHead;
}));
}
}

function addCursorToSelection(cm, dir) {
var ranges = cm.listSelections(), newRanges = [];
for (var i = 0; i < ranges.length; i++) {
Expand Down Expand Up @@ -605,6 +616,7 @@
"Shift-Cmd-F2": "clearBookmarks",
"Alt-F2": "selectBookmarks",
"Backspace": "smartBackspace",
"Cmd-K Cmd-D": "skipAndSelectNextOccurrence",
"Cmd-K Cmd-K": "delLineRight",
"Cmd-K Cmd-U": "upcaseAtCursor",
"Cmd-K Cmd-L": "downcaseAtCursor",
Expand Down Expand Up @@ -665,6 +677,7 @@
"Shift-Ctrl-F2": "clearBookmarks",
"Alt-F2": "selectBookmarks",
"Backspace": "smartBackspace",
"Ctrl-K Ctrl-D": "skipAndSelectNextOccurrence",
"Ctrl-K Ctrl-K": "delLineRight",
"Ctrl-K Ctrl-U": "upcaseAtCursor",
"Ctrl-K Ctrl-L": "downcaseAtCursor",
Expand Down
12 changes: 10 additions & 2 deletions test/sublime_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
hasSel(0, 0, 0, 0,
2, 0, 2, 0), val("\nabcde\n\nfghijkl\nmn"));

stTest("skipAndSelectNextOccurrence", "a foo bar\nfoobar foo",
setSel(0, 2, 0, 5), "skipAndSelectNextOccurrence", hasSel(1, 0, 1, 3),
"skipAndSelectNextOccurrence", hasSel(1, 7, 1, 10),
"skipAndSelectNextOccurrence", hasSel(0, 2, 0, 5),
Pos(0, 3), "skipAndSelectNextOccurrence", hasSel(0, 2, 0, 5),
"skipAndSelectNextOccurrence", hasSel(1, 7, 1, 10),
setSel(0, 6, 0, 9), "skipAndSelectNextOccurrence", hasSel(1, 3, 1, 6));

stTest("selectNextOccurrence", "a foo bar\nfoobar foo",
setSel(0, 2, 0, 5),
"selectNextOccurrence", hasSel(0, 2, 0, 5,
Expand All @@ -141,8 +149,8 @@
1, 0, 1, 3,
1, 7, 1, 10),
Pos(0, 3), "selectNextOccurrence", hasSel(0, 2, 0, 5),
"selectNextOccurrence", hasSel(0, 2, 0, 5,
1, 7, 1, 10),
"selectNextOccurrence", hasSel(0, 2, 0, 5,
1, 7, 1, 10),
setSel(0, 6, 0, 9),
"selectNextOccurrence", hasSel(0, 6, 0, 9,
1, 3, 1, 6));
Expand Down

0 comments on commit 11272b2

Please sign in to comment.