@@ -1227,40 +1227,47 @@ var VirtualRenderer = function(container, theme) {
1227
1227
1228
1228
var pos = this . $cursorLayer . getPixelPosition ( cursor ) ;
1229
1229
1230
- var left = pos . left ;
1231
- var top = pos . top ;
1232
-
1230
+ var newLeft = pos . left ;
1231
+ var newTop = pos . top ;
1232
+
1233
1233
var topMargin = $viewMargin && $viewMargin . top || 0 ;
1234
1234
var bottomMargin = $viewMargin && $viewMargin . bottom || 0 ;
1235
1235
1236
1236
if ( this . $scrollAnimation ) {
1237
1237
this . $stopAnimation = true ;
1238
1238
}
1239
-
1240
- var scrollTop = this . $scrollAnimation ? this . session . getScrollTop ( ) : this . scrollTop ;
1241
-
1242
- if ( scrollTop + topMargin > top ) {
1243
- if ( offset && scrollTop + topMargin > top + this . lineHeight )
1244
- top -= offset * this . $size . scrollerHeight ;
1245
- if ( top === 0 )
1246
- top = - this . scrollMargin . top ;
1247
- this . session . setScrollTop ( top ) ;
1248
- } else if ( scrollTop + this . $size . scrollerHeight - bottomMargin < top + this . lineHeight ) {
1249
- if ( offset && scrollTop + this . $size . scrollerHeight - bottomMargin < top - this . lineHeight )
1250
- top += offset * this . $size . scrollerHeight ;
1251
- this . session . setScrollTop ( top + this . lineHeight + bottomMargin - this . $size . scrollerHeight ) ;
1239
+
1240
+ var currentTop = this . $scrollAnimation ? this . session . getScrollTop ( ) : this . scrollTop ;
1241
+
1242
+ if ( currentTop + topMargin > newTop ) {
1243
+ if ( offset && currentTop + topMargin > newTop + this . lineHeight )
1244
+ newTop -= offset * this . $size . scrollerHeight ;
1245
+ if ( newTop === 0 )
1246
+ newTop = - this . scrollMargin . top ;
1247
+ this . session . setScrollTop ( newTop ) ;
1248
+ } else if ( currentTop + this . $size . scrollerHeight - bottomMargin < newTop + this . lineHeight ) {
1249
+ if ( offset && currentTop + this . $size . scrollerHeight - bottomMargin < newTop - this . lineHeight )
1250
+ newTop += offset * this . $size . scrollerHeight ;
1251
+ this . session . setScrollTop ( newTop + this . lineHeight + bottomMargin - this . $size . scrollerHeight ) ;
1252
1252
}
1253
1253
1254
- var scrollLeft = this . scrollLeft ;
1254
+ var currentLeft = this . scrollLeft ;
1255
+ // Show 2 context characters of the line when moving to it
1256
+ var twoCharsWidth = 2 * this . layerConfig . characterWidth ;
1255
1257
1256
- if ( scrollLeft > left ) {
1257
- if ( left < this . $padding + 2 * this . layerConfig . characterWidth )
1258
- left = - this . scrollMargin . left ;
1259
- this . session . setScrollLeft ( left ) ;
1260
- } else if ( scrollLeft + this . $size . scrollerWidth < left + this . characterWidth ) {
1261
- this . session . setScrollLeft ( Math . round ( left + this . characterWidth - this . $size . scrollerWidth ) ) ;
1262
- } else if ( scrollLeft <= this . $padding && left - scrollLeft < this . characterWidth ) {
1263
- this . session . setScrollLeft ( 0 ) ;
1258
+ if ( newLeft - twoCharsWidth < currentLeft ) {
1259
+ newLeft -= twoCharsWidth ;
1260
+ if ( newLeft < this . $padding + twoCharsWidth ) {
1261
+ newLeft = - this . scrollMargin . left ;
1262
+ }
1263
+ this . session . setScrollLeft ( newLeft ) ;
1264
+ } else {
1265
+ newLeft += twoCharsWidth ;
1266
+ if ( currentLeft + this . $size . scrollerWidth < newLeft + this . characterWidth ) {
1267
+ this . session . setScrollLeft ( Math . round ( newLeft + this . characterWidth - this . $size . scrollerWidth ) ) ;
1268
+ } else if ( currentLeft <= this . $padding && newLeft - currentLeft < this . characterWidth ) {
1269
+ this . session . setScrollLeft ( 0 ) ;
1270
+ }
1264
1271
}
1265
1272
} ;
1266
1273
0 commit comments