| 1138 | } |
| 1139 | |
| 1140 | void AutoCompletePlugin::postDraw( UICodeEditor* editor, const Vector2f& startScroll, |
| 1141 | const Float& lineHeight, const TextPosition& cursor ) { |
| 1142 | bool drawsSuggestions = |
| 1143 | !( mSuggestions.empty() || !mSuggestionsEditor || mSuggestionsEditor != editor ); |
| 1144 | bool drawsSignature = mSignatureHelpVisible && mSignatureHelpEditor == editor && |
| 1145 | !mSignatureHelp.signatures.empty() && mSignatureHelpPosition.isValid(); |
| 1146 | if ( !drawsSuggestions && !drawsSignature ) |
| 1147 | return; |
| 1148 | |
| 1149 | TextDocument& doc = editor->getDocument(); |
| 1150 | TextPosition start = doc.startOfWord( editor->getDocument().startOfWord( cursor ) ); |
| 1151 | Primitives primitives; |
| 1152 | const SyntaxColorScheme& scheme = editor->getColorScheme(); |
| 1153 | const auto& normalStyle = scheme.getEditorSyntaxStyle( "suggestion"_sst ); |
| 1154 | const auto& selectedStyle = scheme.getEditorSyntaxStyle( "suggestion_selected"_sst ); |
| 1155 | bool drawUp = true; |
| 1156 | mRowHeight = lineHeight + mBoxPadding.Top + mBoxPadding.Bottom; |
| 1157 | |
| 1158 | if ( !drawsSuggestions ) { |
| 1159 | if ( drawsSignature ) |
| 1160 | drawSignatureHelp( editor, startScroll, lineHeight, drawUp ); |
| 1161 | return; |
| 1162 | } |
| 1163 | |
| 1164 | SymbolsList suggestions; |
| 1165 | { |
| 1166 | Lock l( mSuggestionsMutex ); |
| 1167 | suggestions = mSuggestions; |
| 1168 | } |
| 1169 | |
| 1170 | auto offset = editor->getTextPositionOffset( start ); |
| 1171 | Vector2f cursorPos( startScroll.x + offset.x, startScroll.y + offset.y + lineHeight ); |
| 1172 | size_t largestString = 0; |
| 1173 | size_t max = eemin<size_t>( mSuggestionsMaxVisible, suggestions.size() ); |
| 1174 | |
| 1175 | const auto& barStyle = scheme.getEditorSyntaxStyle( "suggestion_scrollbar"_sst ); |
| 1176 | if ( cursorPos.y + mRowHeight * max > editor->getPixelsSize().getHeight() ) { |
| 1177 | cursorPos.y -= lineHeight + mRowHeight * max; |
| 1178 | drawUp = false; |
| 1179 | } |
| 1180 | |
| 1181 | size_t maxIndex = |
| 1182 | eemin<size_t>( mSuggestionsStartIndex + mSuggestionsMaxVisible, suggestions.size() ); |
| 1183 | |
| 1184 | std::vector<String> visibleStrings; |
| 1185 | size_t visibleStrIndex = 0; |
| 1186 | visibleStrings.resize( maxIndex - mSuggestionsStartIndex ); |
| 1187 | for ( size_t i = mSuggestionsStartIndex; i < maxIndex; i++ ) { |
| 1188 | bool needsEllipsis = suggestions[i].text.size() > mMaxLabelCharacters; |
| 1189 | String str{ needsEllipsis ? suggestions[i].text.substr( 0, mMaxLabelCharacters ) |
| 1190 | : suggestions[i].text }; |
| 1191 | if ( needsEllipsis ) |
| 1192 | str[str.size() - 1] = 0x2026 /* u'…' */; |
| 1193 | auto nlPos = str.find_first_of( '\n' ); |
| 1194 | if ( nlPos == String::InvalidPos ) |
| 1195 | str = str.substr( 0, nlPos ); |
| 1196 | String::trimInPlace( str ); |
| 1197 | largestString = eemax<size_t>( largestString, editor->getTextWidth( str ) ); |
nothing calls this directly
no test coverage detected