This is the most expensive part of window update; applying line span generation for wrapped text and unicode character sizes which may vary in byte count and physical pixel width It can take about a millisecond to do during editing on release buildj; but this is fast enough for now. There are several ways in which this function can be optimized: - Only regenerate spans which have changed, since on
| 415 | // - Have a no-wrap text mode and save a lot of the wrapping work. |
| 416 | // - Do some threading |
| 417 | void ZepWindow::UpdateLineSpans() |
| 418 | { |
| 419 | TIME_SCOPE(UpdateLineSpans); |
| 420 | |
| 421 | m_maxDisplayLines = (long)std::max(0.0f, std::floor(m_textRegion->rect.Height() / m_defaultLineSize)); |
| 422 | |
| 423 | const auto& textBuffer = m_pBuffer->GetWorkingBuffer(); |
| 424 | |
| 425 | long bufferLine = 0; |
| 426 | long spanLine = 0; |
| 427 | float bufferPosYPx = 0.0f; |
| 428 | float xOffset = m_xPad; |
| 429 | |
| 430 | bool isMarkdown = m_pBuffer->GetFileExtension() == ".md"; |
| 431 | |
| 432 | // Nuke the existing spans |
| 433 | // In future we can in-place modify for speed |
| 434 | std::for_each(m_windowLines.begin(), m_windowLines.end(), [](SpanInfo* pInfo) { delete pInfo; }); |
| 435 | m_windowLines.clear(); |
| 436 | |
| 437 | //auto& display = GetEditor().GetDisplay(); |
| 438 | |
| 439 | auto widgetMarkers = m_pBuffer->GetRangeMarkers(RangeMarkerType::Widget); |
| 440 | auto itrWidgetMarkers = widgetMarkers.begin(); |
| 441 | |
| 442 | // Process every buffer line |
| 443 | for (;;) |
| 444 | { |
| 445 | // We haven't processed this line yet, so we can't display anything |
| 446 | // else |
| 447 | if (m_pBuffer->GetLineCount() <= bufferLine) |
| 448 | break; |
| 449 | |
| 450 | ByteRange lineByteRange; |
| 451 | if (!m_pBuffer->GetLineOffsets(bufferLine, lineByteRange)) |
| 452 | break; |
| 453 | |
| 454 | // Padding at the top of the line |
| 455 | NVec2f topPadding = NVec2f(DPI_Y((float)GetEditor().GetConfig().lineMargins.x), DPI_Y((float)GetEditor().GetConfig().lineMargins.y)); |
| 456 | |
| 457 | auto markersOnLine = m_pBuffer->GetRangeMarkersOnLine(RangeMarkerType::All, bufferLine); |
| 458 | auto lineWidgetHeight = ArrangeLineMarkers(markersOnLine); |
| 459 | |
| 460 | // Move the line down by the height of the widget |
| 461 | bufferPosYPx += lineWidgetHeight.x; |
| 462 | |
| 463 | // TODO: Find a clean way to do this extra work during layout for extensions that need it |
| 464 | ZepTextType type = ZepTextType::Text; |
| 465 | if (isMarkdown) |
| 466 | { |
| 467 | uint32_t headerCount = 0; |
| 468 | // Markdown experiment |
| 469 | for (auto ch = lineByteRange.first; ch < lineByteRange.second; ch += utf8_codepoint_length(textBuffer[ch])) |
| 470 | { |
| 471 | if (textBuffer[ch] != '#') |
| 472 | break; |
| 473 | headerCount++; |
| 474 | } |
nothing calls this directly
no test coverage detected