소스 검색

Keep the cursor in the same position on screen when the editor resizes

James Allen 9 년 전
부모
커밋
d00619ff3d
1개의 변경된 파일과 12개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      services/web/public/coffee/ide/editor/directives/aceEditor.coffee

+ 12 - 0
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}")