mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-21 23:09:40 +00:00
Truncate long citation label in the middle rather than the end.
Fixes: #10769
This commit is contained in:
parent
52fffee7f2
commit
623f7b4795
@ -1326,9 +1326,15 @@ docstring const BiblioInfo::getLabel(vector<docstring> keys,
|
||||
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();
|
||||
@ -1353,9 +1359,8 @@ docstring const BiblioInfo::getLabel(vector<docstring> keys,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -458,8 +458,8 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1233,13 +1233,21 @@ docstring const protectArgument(docstring & arg, char const l,
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -276,6 +276,8 @@ docstring const protectArgument(docstring & arg, char const l = '[',
|
||||
/// 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
|
||||
@ -294,7 +296,8 @@ docstring const protectArgument(docstring & arg, char const l = '[',
|
||||
///
|
||||
/// 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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user