| 2451 | } |
| 2452 | |
| 2453 | void UICodeEditor::scrollToVisibleIndex( Int64 visibleIndex, bool centered, |
| 2454 | bool forceExactPosition ) { |
| 2455 | Rectf scrollArea = getVisibleScrollArea(); |
| 2456 | Float lineHeight = getLineHeight(); |
| 2457 | Int64 minDistance = mHScrollBar->isVisible() ? 3 : 2; |
| 2458 | scrollArea.Top += lineHeight; |
| 2459 | scrollArea.Bottom = eemax( scrollArea.Top, scrollArea.Bottom - minDistance * lineHeight ); |
| 2460 | |
| 2461 | Vector2f offsetEnd{ 0.f, static_cast<Float>( mDocView.getLineYOffset( |
| 2462 | static_cast<VisibleIndex>( visibleIndex ), lineHeight ) ) }; |
| 2463 | |
| 2464 | // Vertical Scroll |
| 2465 | Float halfScreenSize = eefloor( getViewportDimensions().getHeight() * 0.5f ); |
| 2466 | if ( centered || forceExactPosition ) { |
| 2467 | setScrollY( |
| 2468 | eeclamp( offsetEnd.y - ( centered ? halfScreenSize : 0 ), 0.f, getMaxScroll().y ) ); |
| 2469 | } else if ( offsetEnd.y < scrollArea.Top ) { |
| 2470 | setScrollY( eeclamp( offsetEnd.y - lineHeight, 0.f, getMaxScroll().y ) ); |
| 2471 | } else if ( offsetEnd.y > scrollArea.Bottom - lineHeight ) { |
| 2472 | setScrollY( |
| 2473 | eeclamp( offsetEnd.y - scrollArea.getHeight() - lineHeight, 0.f, getMaxScroll().y ) ); |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | void UICodeEditor::scrollTo( TextRange position, bool centered, bool forceExactPosition, |
| 2478 | bool scrollX ) { |