| 3279 | } |
| 3280 | |
| 3281 | Int64 UICodeEditor::getColFromXOffset( VisibleIndex visibleIndex, const Float& x ) const { |
| 3282 | if ( x < 0 || !mFont || mDoc->isLoading() ) |
| 3283 | return 0; |
| 3284 | |
| 3285 | TextPosition pos = mDoc->sanitizePosition( mDocView.getVisibleIndexPosition( visibleIndex ) ); |
| 3286 | |
| 3287 | if ( mDocView.isWrappedLine( pos.line() ) ) { |
| 3288 | auto visibleIndexRange = mDocView.getVisibleIndexRange( visibleIndex ); |
| 3289 | auto firstVisibleIndex = mDocView.toVisibleIndex( visibleIndexRange.start().line() ); |
| 3290 | Float xOffset = firstVisibleIndex != visibleIndex |
| 3291 | ? mDocView.getLinePadding( visibleIndexRange.start().line() ) |
| 3292 | : 0; |
| 3293 | |
| 3294 | auto line = mDoc->line( visibleIndexRange.start().line() ) |
| 3295 | .getText() |
| 3296 | .view() |
| 3297 | .substr( visibleIndexRange.start().column(), visibleIndexRange.length() ); |
| 3298 | |
| 3299 | if ( !isMonospaceLine( pos.line() ) ) { |
| 3300 | return visibleIndexRange.start().column() + |
| 3301 | Text::findCharacterFromPos( |
| 3302 | Vector2i( eemax( -xOffset + x, 0.f ), 0 ), true, mFont, getCharacterSize(), |
| 3303 | line, mFontStyleConfig.Style, mTabWidth, 0.f, |
| 3304 | mTabStops ? 0 : std::optional<Float>(), |
| 3305 | mDoc->line( pos.line() ).getTextHints() | getWidgetTextDrawHints(), |
| 3306 | mTextDirection ); |
| 3307 | } |
| 3308 | |
| 3309 | Int64 len = line.length(); |
| 3310 | Float glyphWidth = getGlyphWidth(); |
| 3311 | for ( int i = 0; i < len; i++ ) { |
| 3312 | bool isTab = ( line[i] == '\t' ); |
| 3313 | Float advance = isTab ? Text::tabAdvance( glyphWidth, mTabWidth, |
| 3314 | mTabStops ? xOffset : std::optional<Float>{} ) |
| 3315 | : glyphWidth; |
| 3316 | if ( xOffset >= x ) { |
| 3317 | auto col = xOffset - x > advance * 0.5f ? eemax<Int64>( 0, i - 1 ) : i; |
| 3318 | return visibleIndexRange.start().column() + col; |
| 3319 | } else if ( isTab && ( xOffset + advance > x ) ) { |
| 3320 | auto col = |
| 3321 | x - xOffset > ( advance * 0.5f ) ? eemin<Int64>( i + 1, line.size() - 1 ) : i; |
| 3322 | return visibleIndexRange.start().column() + col; |
| 3323 | } |
| 3324 | xOffset += advance; |
| 3325 | } |
| 3326 | return visibleIndexRange.start().column() + static_cast<Int64>( line.size() ) - 1; |
| 3327 | } |
| 3328 | |
| 3329 | if ( !isMonospaceLine( pos.line() ) ) { |
| 3330 | return Text::findCharacterFromPos( |
| 3331 | Vector2i( x, 0 ), true, mFont, getCharacterSize(), mDoc->line( pos.line() ).getText(), |
| 3332 | mFontStyleConfig.Style, mTabWidth, 0.f, mTabStops ? 0 : std::optional<Float>(), |
| 3333 | mDoc->line( pos.line() ).getTextHints() | getWidgetTextDrawHints(), mTextDirection ); |
| 3334 | } |
| 3335 | |
| 3336 | const String& line = mDoc->line( pos.line() ).getText(); |
| 3337 | Int64 len = line.length(); |
| 3338 | Float glyphWidth = getGlyphWidth(); |
nothing calls this directly
no test coverage detected