| 247 | } |
| 248 | |
| 249 | int TextEditor::positionToIndex(const std::pair<float, float>& position) const { |
| 250 | float line_height = font().lineHeight(); |
| 251 | int line = std::min<int>(line_breaks_.size(), (position.second - yMargin()) / line_height); |
| 252 | std::pair<int, int> range = lineRange(line); |
| 253 | |
| 254 | float full_width = font().stringWidth(text_.text().c_str() + range.first, |
| 255 | range.second - range.first, text_.characterOverride()); |
| 256 | |
| 257 | float line_x = (width() - full_width) * 0.5f; |
| 258 | float x_margin = xMargin(); |
| 259 | if (justification() & Font::kLeft) |
| 260 | line_x = x_margin; |
| 261 | else if (justification() & Font::kRight) |
| 262 | line_x = width() - x_margin - full_width; |
| 263 | |
| 264 | int index = font().widthOverflowIndex(text_.text().c_str() + range.first, range.second - range.first, |
| 265 | position.first - line_x, true, text_.characterOverride()); |
| 266 | return std::min(range.first + index, range.second); |
| 267 | } |
| 268 | |
| 269 | bool TextEditor::enterPressed() { |
| 270 | if (!active_) |
nothing calls this directly
no test coverage detected