| 4369 | } |
| 4370 | |
| 4371 | std::vector<Rectf> UICodeEditor::getTextRangeRectangles( |
| 4372 | const TextRange& range, const Vector2f& startScroll, |
| 4373 | std::optional<const DocumentLineRange> lineRange, std::optional<Float> lineHeight, |
| 4374 | std::optional<DocumentViewLineRange> visibleLineRange, bool visualizeNewLines ) { |
| 4375 | std::vector<Rectf> rects; |
| 4376 | Float lh = lineHeight ? *lineHeight : getLineHeight(); |
| 4377 | Int64 startLine = |
| 4378 | eemax<Int64>( lineRange ? lineRange->first : range.start().line(), range.start().line() ); |
| 4379 | Int64 endLine = |
| 4380 | eemin<Int64>( lineRange ? lineRange->second : range.end().line(), range.end().line() ); |
| 4381 | for ( auto ln = startLine; ln <= endLine; ln++ ) { |
| 4382 | if ( !mDocView.isLineVisible( ln ) ) |
| 4383 | continue; |
| 4384 | const String& line = mDoc->line( ln ).getText(); |
| 4385 | Rectf selRect; |
| 4386 | if ( mDocView.isWrappedLine( ln ) ) { |
| 4387 | auto fromInfo = mDocView.getVisibleLineRange( |
| 4388 | ln == range.start().line() ? range.start() : mDoc->startOfLine( { ln, 0 } ) ); |
| 4389 | auto toInfo = mDocView.getVisibleLineRange( |
| 4390 | ln == range.end().line() ? range.end() : mDoc->endOfLine( { ln, 0 } ) ); |
| 4391 | auto realFromInfoVisibleIndex = fromInfo.visibleIndex; |
| 4392 | auto realToInfoVisibleIndex = toInfo.visibleIndex; |
| 4393 | if ( visibleLineRange ) { |
| 4394 | if ( fromInfo.visibleIndex < visibleLineRange->first ) |
| 4395 | fromInfo.visibleIndex = visibleLineRange->first; |
| 4396 | if ( toInfo.visibleIndex > visibleLineRange->second ) |
| 4397 | toInfo.visibleIndex = visibleLineRange->second; |
| 4398 | } |
| 4399 | |
| 4400 | for ( Int64 visibleIdx = static_cast<Int64>( fromInfo.visibleIndex ); |
| 4401 | visibleIdx <= static_cast<Int64>( toInfo.visibleIndex ); visibleIdx++ ) { |
| 4402 | auto info = |
| 4403 | mDocView.getVisibleIndexPosition( static_cast<VisibleIndex>( visibleIdx ) ); |
| 4404 | Vector2d startOffset; |
| 4405 | Vector2d endOffset; |
| 4406 | if ( ln == range.start().line() && fromInfo.range.start().line() == ln && |
| 4407 | realFromInfoVisibleIndex == static_cast<VisibleIndex>( visibleIdx ) ) { |
| 4408 | startOffset = |
| 4409 | getTextPositionOffset( range.start(), lh, false, visualizeNewLines ); |
| 4410 | } else { |
| 4411 | startOffset = getTextPositionOffset( info, lh ); |
| 4412 | } |
| 4413 | selRect.Top = startScroll.y + startOffset.y; |
| 4414 | selRect.Bottom = selRect.Top + lh; |
| 4415 | selRect.Left = startScroll.x + startOffset.x; |
| 4416 | if ( ln == range.end().line() && toInfo.range.end().line() == ln && |
| 4417 | realToInfoVisibleIndex == static_cast<VisibleIndex>( visibleIdx ) ) { |
| 4418 | endOffset = getTextPositionOffset( range.end(), lh ); |
| 4419 | } else { |
| 4420 | auto nextInfo = mDocView.getVisibleIndexPosition( |
| 4421 | static_cast<VisibleIndex>( visibleIdx + 1 ) ); |
| 4422 | if ( nextInfo.line() == info.line() ) { |
| 4423 | endOffset = getTextPositionOffset( { info.line(), nextInfo.column() }, lh, |
| 4424 | true, visualizeNewLines ); |
| 4425 | } else { |
| 4426 | endOffset = getTextPositionOffset( mDoc->endOfLine( { ln, 0 } ), lh, true, |
| 4427 | visualizeNewLines ); |
| 4428 | } |
no test coverage detected