From 03eee835df3e62ecf67c5f65dbc1d4ff8e35df23 Mon Sep 17 00:00:00 2001 From: AMiniLegend Date: Wed, 21 May 2014 16:39:47 -0400 Subject: [PATCH] Updated ExpandToLine, JoinLines, and InvertSelection based on feedback. --- lib/ace/commands/default_commands.js | 47 +++++++++++----------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index 5cd9f61f..77cdfc61 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -606,39 +606,33 @@ exports.commands = [{ }, { name: "expandtoline", bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"), - 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(); - - editor.clearSelection(); - - editor.selection.moveCursorTo(selectionStart.row, 0); - editor.selection.selectTo(selectionEnd.row + 1, 0); + exec: function(editor) { + var range = editor.selection.getRange(); + + range.start.column = range.end.column = 0; + range.end.row++; + editor.selection.setRange(range, false); }, multiSelectAction: "forEach", - scrollIntoView: "cursor" + scrollIntoView: "cursor", + readOnly: true }, { name: "joinlines", bindKey: bindKey(null, null), - exec: function(editor) { + 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 firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length var selectedText = editor.session.doc.getTextRange(editor.selection.getRange()); + var selectedCount = selectedText.replace(/\n\s*/, " ").length; 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++) { var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i))); - if (curLine.length !== 0) { - curLine = " " + curLine; + curLine = " " + curLine; } - insertLine += curLine; }; @@ -660,17 +654,16 @@ exports.commands = [{ editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol); } }, - multiSelectAction: "forEach" + multiSelectAction: "forEach", + readOnly: true }, { name: "invertSelection", bindKey: bindKey(null, null), - exec: function(editor) { + exec: function(editor) { var endRow = editor.session.doc.getLength() - 1; var endCol = editor.session.doc.getLine(endRow).length; - var initialScroll = editor.session.getScrollTop(); var ranges = editor.selection.rangeList.ranges; var newRanges = []; - var tmpRanges = ranges; // If multiple selections don't exist, rangeList will return 0 so replace with single range 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)); } } - + editor.exitMultiSelectMode(); 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++) { editor.selection.addRange(newRanges[i], false); } - - // Make it so the user sees no change in scrolling - editor.session.setScrollTop(initialScroll); - } + }, + readOnly: true, + scrollIntoView: "none" }]; });