Changed the name of the "joinSelection" function to "joinlines".
Also changed it's behavior so that when there is no selection, it will join with the next line.
This commit is contained in:
parent
8f8410f01b
commit
470efff782
1 changed files with 31 additions and 12 deletions
|
|
@ -619,27 +619,46 @@ exports.commands = [{
|
|||
multiSelectAction: "forEach",
|
||||
scrollIntoView: "cursor"
|
||||
}, {
|
||||
name: "joinSelection",
|
||||
name: "joinlines",
|
||||
bindKey: bindKey(null, null),
|
||||
exec: function(editor) {
|
||||
var isBackwards = editor.selection.isBackwards();
|
||||
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor();
|
||||
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead();
|
||||
var selectedRange = editor.selection.getRange();
|
||||
var selectedText = editor.session.doc.getTextRange(selectedRange);
|
||||
var newLine = editor.session.doc.getLine(selectionStart.row) + " ";
|
||||
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length
|
||||
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange());
|
||||
var insertLine = editor.session.doc.getLine(selectionStart.row);
|
||||
|
||||
for (var i = selectionStart.row + 1; i <= selectionEnd.row; i++) {
|
||||
var curLine = editor.session.doc.getLine(i);
|
||||
newLine += lang.stringTrimLeft(lang.stringTrimRight(curLine)) + " ";
|
||||
selectedText = selectedText.replace(/\n\s*/, " ");
|
||||
var selectedCount = selectedText.length;
|
||||
|
||||
for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) {
|
||||
var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i)));
|
||||
|
||||
if (curLine.length !== 0) {
|
||||
curLine = " " + curLine;
|
||||
}
|
||||
|
||||
insertLine += curLine;
|
||||
};
|
||||
|
||||
newLine += editor.session.doc.getNewLineCharacter();
|
||||
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) {
|
||||
// Don't insert a newline at the end of the document
|
||||
insertLine += editor.session.doc.getNewLineCharacter();
|
||||
}
|
||||
|
||||
editor.clearSelection();
|
||||
editor.selection.moveCursorTo(selectionStart.row, 0);
|
||||
editor.selection.selectTo(selectionEnd.row + 1, 0);
|
||||
selectedRange = editor.selection.getRange();
|
||||
editor.session.doc.replace(selectedRange, newLine);
|
||||
editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine);
|
||||
|
||||
if (selectedCount > 0) {
|
||||
// Select the text that was previously selected
|
||||
editor.selection.moveCursorTo(selectionStart.row, selectionStart.column);
|
||||
editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount);
|
||||
} else {
|
||||
// If the joined line had something in it, start the cursor at that something
|
||||
firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol;
|
||||
editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol);
|
||||
}
|
||||
},
|
||||
multiSelectAction: "forEach"
|
||||
}, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue