Updated ExpandToLine, JoinLines, and InvertSelection based on feedback.
This commit is contained in:
parent
470efff782
commit
03eee835df
1 changed files with 18 additions and 29 deletions
|
|
@ -606,39 +606,33 @@ exports.commands = [{
|
||||||
}, {
|
}, {
|
||||||
name: "expandtoline",
|
name: "expandtoline",
|
||||||
bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
|
bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"),
|
||||||
exec: function(editor) {
|
exec: function(editor) {
|
||||||
var isBackwards = editor.selection.isBackwards();
|
var range = editor.selection.getRange();
|
||||||
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
|
||||||
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
range.start.column = range.end.column = 0;
|
||||||
|
range.end.row++;
|
||||||
editor.clearSelection();
|
editor.selection.setRange(range, false);
|
||||||
|
|
||||||
editor.selection.moveCursorTo(selectionStart.row, 0);
|
|
||||||
editor.selection.selectTo(selectionEnd.row + 1, 0);
|
|
||||||
},
|
},
|
||||||
multiSelectAction: "forEach",
|
multiSelectAction: "forEach",
|
||||||
scrollIntoView: "cursor"
|
scrollIntoView: "cursor",
|
||||||
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "joinlines",
|
name: "joinlines",
|
||||||
bindKey: bindKey(null, null),
|
bindKey: bindKey(null, null),
|
||||||
exec: function(editor) {
|
exec: function(editor) {
|
||||||
var isBackwards = editor.selection.isBackwards();
|
var isBackwards = editor.selection.isBackwards();
|
||||||
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
||||||
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
||||||
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
|
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
|
||||||
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
|
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
|
||||||
|
var selectedCount = selectedText.replace(/\n\s*/, " ").length;
|
||||||
var insertLine = editor.session.doc.getLine(selectionStart.row);
|
var insertLine = editor.session.doc.getLine(selectionStart.row);
|
||||||
|
|
||||||
selectedText = selectedText.replace(/\n\s*/, " ");
|
|
||||||
var selectedCount = selectedText.length;
|
|
||||||
|
|
||||||
for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
|
for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
|
||||||
var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
|
var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
|
||||||
|
|
||||||
if (curLine.length !== 0) {
|
if (curLine.length !== 0) {
|
||||||
curLine = " " + curLine;
|
curLine = " " + curLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
insertLine += curLine;
|
insertLine += curLine;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -660,17 +654,16 @@ exports.commands = [{
|
||||||
editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
|
editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
multiSelectAction: "forEach"
|
multiSelectAction: "forEach",
|
||||||
|
readOnly: true
|
||||||
}, {
|
}, {
|
||||||
name: "invertSelection",
|
name: "invertSelection",
|
||||||
bindKey: bindKey(null, null),
|
bindKey: bindKey(null, null),
|
||||||
exec: function(editor) {
|
exec: function(editor) {
|
||||||
var endRow = editor.session.doc.getLength() - 1;
|
var endRow = editor.session.doc.getLength() - 1;
|
||||||
var endCol = editor.session.doc.getLine(endRow).length;
|
var endCol = editor.session.doc.getLine(endRow).length;
|
||||||
var initialScroll = editor.session.getScrollTop();
|
|
||||||
var ranges = editor.selection.rangeList.ranges;
|
var ranges = editor.selection.rangeList.ranges;
|
||||||
var newRanges = [];
|
var newRanges = [];
|
||||||
var tmpRanges = ranges;
|
|
||||||
|
|
||||||
// If multiple selections don't exist, rangeList will return 0 so replace with single range
|
// If multiple selections don't exist, rangeList will return 0 so replace with single range
|
||||||
if (ranges.length < 1) {
|
if (ranges.length < 1) {
|
||||||
|
|
@ -694,20 +687,16 @@ exports.commands = [{
|
||||||
newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
|
newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.exitMultiSelectMode();
|
editor.exitMultiSelectMode();
|
||||||
editor.clearSelection();
|
editor.clearSelection();
|
||||||
|
|
||||||
// Set the main cursor to the last range that will be seen
|
|
||||||
editor.selection.moveCursorTo(newRanges[newRanges.length-1].end.row, newRanges[newRanges.length-1].end.column, false);
|
|
||||||
|
|
||||||
for(var i = 0; i < newRanges.length; i++) {
|
for(var i = 0; i < newRanges.length; i++) {
|
||||||
editor.selection.addRange(newRanges[i], false);
|
editor.selection.addRange(newRanges[i], false);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
// Make it so the user sees no change in scrolling
|
readOnly: true,
|
||||||
editor.session.setScrollTop(initialScroll);
|
scrollIntoView: "none"
|
||||||
}
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue