From 4d540f7f58252f7774a8652b3e6b0c2fe9a257f0 Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Mon, 12 May 2014 13:27:56 -0700 Subject: [PATCH 1/2] Fix for issue #7458: View doesn't scroll down after Edit > Move Line Down --- src/editor/EditorCommandHandlers.js | 36 +++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index 5cb11d464c9..e03cf0bf9da 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -726,14 +726,17 @@ define(function (require, exports, module) { return; } - var doc = editor.document, - lineSelections = editor.convertToLineSelections(editor.getSelections()), - isInlineWidget = !!EditorManager.getFocusedInlineWidget(), - firstLine = editor.getFirstVisibleLine(), - lastLine = editor.getLastVisibleLine(), - totalLines = editor.lineCount(), - lineLength = 0, - edits = []; + var doc = editor.document, + lineSelections = editor.convertToLineSelections(editor.getSelections()), + isInlineWidget = !!EditorManager.getFocusedInlineWidget(), + firstLine = editor.getFirstVisibleLine(), + lastLine = editor.getLastVisibleLine(), + totalLines = editor.lineCount(), + lineLength = 0, + edits = [], + newSels = [], + sel = {}, + pos = {}; _.each(lineSelections, function (lineSel) { var sel = lineSel.selectionForEdit, @@ -799,11 +802,26 @@ define(function (require, exports, module) { break; } }); + + // Make sure correct selections are made and scrolled into view if (edits.length) { - var newSels = doc.doMultipleEdits(edits); + newSels = doc.doMultipleEdits(edits); + if (direction === DIRECTION_UP) { editor.setSelections(newSels); + sel = _.first(editor.getSelections()); + pos.ch = sel.start.ch; + pos.line = sel.start.line; + } else if (direction === DIRECTION_DOWN) { + sel = _.last(editor.getSelections()); + pos.ch = sel.end.ch; + pos.line = sel.end.line; + } else { + console.error("EditorCommandHandler.moveLine() called with invalid argument 'direction' = %d", direction); + pos = null; } + + editor._codeMirror.scrollIntoView(pos); } } From b04029c069d9757db3f74cee6fef7badde7f2e90 Mon Sep 17 00:00:00 2001 From: Lance Campbell Date: Tue, 20 May 2014 07:10:50 -0700 Subject: [PATCH 2/2] Simplify solution to only scroll to primary selection --- src/editor/EditorCommandHandlers.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/editor/EditorCommandHandlers.js b/src/editor/EditorCommandHandlers.js index e03cf0bf9da..c2e269833c3 100644 --- a/src/editor/EditorCommandHandlers.js +++ b/src/editor/EditorCommandHandlers.js @@ -735,7 +735,6 @@ define(function (require, exports, module) { lineLength = 0, edits = [], newSels = [], - sel = {}, pos = {}; _.each(lineSelections, function (lineSel) { @@ -803,19 +802,17 @@ define(function (require, exports, module) { } }); - // Make sure correct selections are made and scrolled into view + // Make sure selections are correct and primary selection is scrolled into view if (edits.length) { newSels = doc.doMultipleEdits(edits); + pos.ch = 0; + if (direction === DIRECTION_UP) { editor.setSelections(newSels); - sel = _.first(editor.getSelections()); - pos.ch = sel.start.ch; - pos.line = sel.start.line; + pos.line = editor.getSelection().start.line; } else if (direction === DIRECTION_DOWN) { - sel = _.last(editor.getSelections()); - pos.ch = sel.end.ch; - pos.line = sel.end.line; + pos.line = editor.getSelection().end.line; } else { console.error("EditorCommandHandler.moveLine() called with invalid argument 'direction' = %d", direction); pos = null;