LASSERT(max_size >= 16, max_size = 16);
// we can't display more than 10 of these, anyway
+ // but since we truncate in the middle,
+ // we need to split into two halfs.
bool const too_many_keys = keys.size() > 10;
- if (too_many_keys)
- keys.resize(10);
+ vector<docstring> lkeys;
+ if (too_many_keys) {
+ lkeys.insert(lkeys.end(), keys.end() - 5, keys.end());
+ keys.resize(5);
+ keys.insert(keys.end(), lkeys.begin(), lkeys.end());
+ }
CiteEngineType const engine_type = buf.params().citeEngineType();
DocumentClass const & dc = buf.params().documentClass();
ret = data.getLabel(xrefptrs, buf, ret, ci, key + 1 != ken, i == 1);
}
- if (too_many_keys)
- ret.push_back(0x2026);//HORIZONTAL ELLIPSIS
- support::truncateWithEllipsis(ret, max_size);
+ support::truncateWithEllipsis(ret, max_size, true);
+
return ret;
}
cache.recalculate = false;
cache.generated_label = glabel;
unsigned int const maxLabelChars = 45;
- cache.screen_label = glabel.substr(0, maxLabelChars + 1);
- support::truncateWithEllipsis(cache.screen_label, maxLabelChars);
+ cache.screen_label = glabel;
+ support::truncateWithEllipsis(cache.screen_label, maxLabelChars, true);
}
}
-bool truncateWithEllipsis(docstring & str, size_t const len)
+bool truncateWithEllipsis(docstring & str, size_t const len, bool const mid)
{
if (str.size() <= len)
return false;
- str.resize(len);
- if (len > 0)
- str[len - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+ if (mid && len > 0) {
+ size_t const hlen = len / 2;
+ docstring suffix = str.substr(str.size() - hlen);
+ str.resize(hlen);
+ str[hlen - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+ str += suffix;
+ } else {
+ str.resize(len);
+ if (len > 0)
+ str[len - 1] = 0x2026;// HORIZONTAL ELLIPSIS
+ }
return true;
}
/// Truncates a string with an ellipsis at the end. Leaves str unchanged and
/// returns false if it is shorter than len. Otherwise resizes str to len, with
/// U+2026 HORIZONTAL ELLIPSIS at the end, and returns true.
+/// If mid is true, the ellipsis will be put to the mid of the string, and the first
+/// and last half is appended/prepended.
///
/// Warning (Unicode): The cases where we want to truncate the text and it does
/// not end up converted into a QString for UI display must be really
///
/// FIXME: apply those principles in the current code.
///
-bool truncateWithEllipsis(docstring & str, size_t const len);
+bool truncateWithEllipsis(docstring & str, size_t const len,
+ bool const mid = false);
/// Word-wraps the provided docstring, returning a line-broken string
/// of width no wider than width, with the string broken at spaces.