Преглед изворни кода

Store first visible line instead of scrollTop

scrollTop is affected by changing viewport size and switching between
Ace and CM
Alasdair Smith пре 8 година
родитељ
комит
ba9fa9a0be

+ 5 - 8
services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionAdapter.coffee

@@ -7,19 +7,16 @@ define [
 		getCursor: () ->
 			@editor.getCursorPosition()
 
-		getCursorForSession: (session) ->
-			session.selection.getCursor()
-
-		getScrollTopForSession: (session) ->
-			session.getScrollTop()
+		getEditorScrollPosition: () ->
+			@editor.getFirstVisibleRow()
 
 		setCursor: (pos) ->
 			pos = pos.cursorPosition or { row: 0, column: 0 }
 			@editor.moveCursorToPosition(pos)
 
-		setScrollTop: (pos) ->
-			pos = pos.scrollTop or 0
-			@editor.getSession().setScrollTop(pos)
+		setEditorScrollPosition: (pos) ->
+			pos = pos.firstVisibleLine or 0
+			@editor.scrollToLine(pos)
 
 		clearSelection: () ->
 			@editor.selection.clearSelection()

+ 5 - 5
services/web/public/coffee/ide/editor/directives/aceEditor/cursor-position/CursorPositionManager.coffee

@@ -22,7 +22,7 @@ define [], () ->
 		onSessionChange: (e) =>
 			if e.oldSession?
 				@storeCursorPosition(e.oldSession)
-				@storeScrollTopPosition(e.oldSession)
+				@storeFirstVisibleLine()
 
 			@doc_id = @$scope.sharejsDoc?.doc_id
 
@@ -32,15 +32,15 @@ define [], () ->
 
 		onUnload: (session) =>
 			@storeCursorPosition(session)
-			@storeScrollTopPosition(session)
+			@storeFirstVisibleLine()
 
 		onCursorChange: () =>
 			@emitCursorUpdateEvent()
 
-		storeScrollTopPosition: (session) ->
+		storeFirstVisibleLine: () ->
 			if @doc_id?
 				docPosition = @localStorage("doc.position.#{@doc_id}") || {}
-				docPosition.scrollTop = @adapter.getScrollTopForSession(session)
+				docPosition.firstVisibleLine = @adapter.getEditorScrollPosition()
 				@localStorage("doc.position.#{@doc_id}", docPosition)
 
 		storeCursorPosition: (session) ->
@@ -57,4 +57,4 @@ define [], () ->
 			return if !@doc_id?
 			pos = @localStorage("doc.position.#{@doc_id}") || {}
 			@adapter.setCursor(pos)
-			@adapter.setScrollTop(pos)
+			@adapter.setEditorScrollPosition(pos)