Repository: neovim/neovim
File: src/nvim/grid.c (C)

Code before:
  if (!grid->throttled) {
    ui_call_grid_scroll(grid->handle, row, end, col, col + width, line_count, 0);
  }
}

static void grid_draw_bordertext(VirtText vt, int col, int winbl, const int *hl_attr,
                                 BorderTextType bt, int over_flow)
{
  int default_attr = hl_attr[bt == kBorderTextTitle ? HLF_BTITLE : HLF_BFOOTER];
  if (over_flow > 0) {
    grid_line_puts(1, "<", -1,  hl_apply_winblend(winbl, default_attr));
    col += 1;
  }

  for (size_t i = 0; i < kv_size(vt);) {
    int attr = -1;
    char *text = next_virt_text_chunk(vt, &i, &attr);
    if (text == NULL) {
      break;
    }
    if (attr == -1) {  // No highlight specified.
      attr = default_attr;
    }
    if (over_flow > 0) {
      int cells = (int)mb_string2cells(text);
      if (over_flow >= cells) {
        over_flow -= cells;
        continue;
      }
      char *p = text;
      while (*p && over_flow > 0) {
        over_flow -= utf_ptr2cells(p);
        p += utfc_ptr2len(p);
      }
      text = p;
    }
    attr = hl_apply_winblend(winbl, attr);
    col += grid_line_puts(col, text, -1, attr);
  }
}

static int get_bordertext_col(int total_col, int text_width, AlignTextPos align)
{
  switch (align) {
  case kAlignLeft:
    return 1;
  case kAlignCenter:
    return MAX((total_col - text_width) / 2 + 1, 1);
  case kAlignRight:
    return MAX(total_col - text_width + 1, 1);
  }

Review comment (suggestion):
this code will be hard to understand in the future. now is the time to add a 1-line comment that says what it does. As always, a brief input/output example is 100x more helpful than a long comment:

    // Example: "..." => "..."

is there not a truncate function that can be used? `trunc_string` looks promising: https://github.com/neovim/neovim/blob/64cf63a88110459d70d140f6074fa014adaef331/src/nvim/message.c#L518

Code after:
  if (!grid->throttled) {
    ui_call_grid_scroll(grid->handle, row, end, col, col + width, line_count, 0);
  }
}

static void grid_draw_bordertext(VirtText vt, int col, int winbl, const int *hl_attr,
                                 BorderTextType bt, int over_flow)
{
  int default_attr = hl_attr[bt == kBorderTextTitle ? HLF_BTITLE : HLF_BFOOTER];
  if (over_flow > 0) {
    grid_line_puts(1, "<", -1,  hl_apply_winblend(winbl, default_attr));
    col += 1;
  }

  for (size_t i = 0; i < kv_size(vt);) {
    int attr = -1;
    char *text = next_virt_text_chunk(vt, &i, &attr);
    if (text == NULL) {
      break;
    }
    if (attr == -1) {  // No highlight specified.
      attr = default_attr;
    }
    // Skip characters from the beginning when title overflows available width.
    // over_flow contains the number of cells to skip.
    if (over_flow > 0) {
      int cells = (int)mb_string2cells(text);
      // Skip entire chunk if overflow is larger than chunk width.
      if (over_flow >= cells) {
        over_flow -= cells;
        continue;
      }
      // Skip partial characters within the chunk.
      char *p = text;
      while (*p && over_flow > 0) {
        over_flow -= utf_ptr2cells(p);
        p += utfc_ptr2len(p);
      }
      text = p;
    }
    attr = hl_apply_winblend(winbl, attr);
    col += grid_line_puts(col, text, -1, attr);
  }
}

static int get_bordertext_col(int total_col, int text_width, AlignTextPos align)
{
  switch (align) {
  case kAlignLeft:
    return 1;
  case kAlignCenter: