| 2083 | } |
| 2084 | |
| 2085 | Float UICodeEditor::getLineWidth( const Int64& docLine ) { |
| 2086 | if ( docLine >= (Int64)mDoc->linesCount() || !mDocView.isLineVisible( docLine ) ) |
| 2087 | return 0; |
| 2088 | |
| 2089 | bool isMonospaceLine = this->isMonospaceLine( docLine ); |
| 2090 | |
| 2091 | if ( mDocView.isWrappedLine( docLine ) ) { |
| 2092 | auto vline = mDocView.getVisibleLineInfo( docLine ); |
| 2093 | const auto& line = mDoc->line( docLine ).getText(); |
| 2094 | Float width = 0; |
| 2095 | |
| 2096 | if ( !isMonospaceLine ) { |
| 2097 | auto found = mLinesWidthCache.find( docLine ); |
| 2098 | if ( found != mLinesWidthCache.end() && |
| 2099 | mDoc->getLineHash( docLine ) == found->second.first ) |
| 2100 | return found->second.second; |
| 2101 | } |
| 2102 | |
| 2103 | for ( size_t i = 0; i < vline.visualLines.size(); i++ ) { |
| 2104 | auto pos = vline.visualLines[i].column(); |
| 2105 | auto len = |
| 2106 | i + 1 < vline.visualLines.size() ? vline.visualLines[i + 1].column() : line.size(); |
| 2107 | auto vlineStr = line.view().substr( pos, len - pos ); |
| 2108 | auto curWidth = |
| 2109 | getTextWidth( vlineStr, isMonospaceLine, {}, |
| 2110 | mDoc->line( docLine ).getTextHints() | getWidgetTextDrawHints() ); |
| 2111 | width = eemax( width, curWidth ); |
| 2112 | } |
| 2113 | |
| 2114 | if ( !isMonospaceLine ) { |
| 2115 | mLinesWidthCache[docLine] = { line.getHash(), width }; |
| 2116 | } |
| 2117 | |
| 2118 | return width; |
| 2119 | } |
| 2120 | |
| 2121 | if ( !isMonospaceLine ) { |
| 2122 | auto& line = mDoc->line( docLine ); |
| 2123 | auto found = mLinesWidthCache.find( docLine ); |
| 2124 | if ( found != mLinesWidthCache.end() && line.getHash() == found->second.first ) |
| 2125 | return found->second.second; |
| 2126 | Float width = getTextWidth( line.getText(), {}, mTabStops ? 0 : std::optional<Float>{}, |
| 2127 | line.getTextHints() | getWidgetTextDrawHints() ); |
| 2128 | mLinesWidthCache[docLine] = { line.getHash(), width }; |
| 2129 | return width; |
| 2130 | } |
| 2131 | |
| 2132 | return getTextWidth( mDoc->line( docLine ).getText(), isMonospaceLine, |
| 2133 | mTabStops ? 0 : std::optional<Float>{}, |
| 2134 | mDoc->line( docLine ).getTextHints() | getWidgetTextDrawHints() ); |
| 2135 | } |
| 2136 | |
| 2137 | void UICodeEditor::updateScrollBar() { |
| 2138 | Int64 notVisibleLineCount = (Int64)getTotalVisibleLines() - (Int64)getViewPortLineCount().y; |