From d00619ff3d3ff672c46295cc860faed445b1c24e Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 7 Feb 2017 15:23:44 +0100 Subject: [PATCH] Keep the cursor in the same position on screen when the editor resizes --- .../coffee/ide/editor/directives/aceEditor.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 93775fd78f..9205cb7b87 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -167,10 +167,22 @@ define [ if arg == "/" ace.require("ace/ext/searchbox").Search(editor, true) + getCursorScreenPosition = () -> + session = editor.getSession() + cursorPosition = session.selection.getCursor() + sessionPos = session.documentToScreenPosition(cursorPosition.row, cursorPosition.column) + screenPos = editor.renderer.textToScreenCoordinates(sessionPos.row, sessionPos.column) + return sessionPos.row * editor.renderer.lineHeight - session.getScrollTop() + if attrs.resizeOn? for event in attrs.resizeOn.split(",") scope.$on event, () -> + previousScreenPosition = getCursorScreenPosition() editor.resize() + # Put cursor back to same vertical position on screen + newScreenPosition = getCursorScreenPosition() + session = editor.getSession() + session.setScrollTop(session.getScrollTop() + newScreenPosition - previousScreenPosition) scope.$watch "theme", (value) -> editor.setTheme("ace/theme/#{value}")