Limited monospace text selection on click only for single lines.

This commit is contained in:
23rd 2022-01-09 06:30:46 +03:00 committed by John Preston
parent 087c82e1d5
commit c2fcbdc883

View file

@ -478,10 +478,23 @@ bool Parser::checkEntities() {
createNewlineBlock(); createNewlineBlock();
} }
} }
const auto end = _waitingEntity->offset() + entityLength; const auto text = QString(entityBegin, entityLength);
auto data = QString(2, QChar(0));
// End of an entity.
data[0] = QChar(_waitingEntity->offset() + entityLength);
{
// It is better to trim the text to identify "Sample\n" as inline.
const auto trimmed = text.trimmed();
const auto isSingleLine = !trimmed.isEmpty()
&& ranges::none_of(trimmed, IsNewline);
data[1] = QChar(isSingleLine ? 1 : 2);
}
_monos.push_back({ _monos.push_back({
.text = QString(entityBegin, entityLength), .text = text,
.data = QString(QChar(end)), .data = std::move(data),
.type = entityType, .type = entityType,
}); });
} else if (entityType == EntityType::Url } else if (entityType == EntityType::Url
@ -740,11 +753,18 @@ void Parser::finalize(const TextParseOptions &options) {
} }
const auto shiftedIndex = block->lnkIndex(); const auto shiftedIndex = block->lnkIndex();
if (shiftedIndex <= kStringLinkIndexShift) { if (shiftedIndex <= kStringLinkIndexShift) {
if (IsMono(block->flags())) { if (IsMono(block->flags()) && (monoLnk <= _monos.size())) {
const auto entityEnd = int( {
_monos[monoLnk - 1].data.constData()->unicode()); const auto ptr = _monos[monoLnk - 1].data.constData();
if (block->from() >= entityEnd) { const auto entityEnd = int(ptr->unicode());
monoLnk++; const auto singleLine = (int((ptr + 1)->unicode()) == 1);
if (!singleLine) {
monoLnk++;
continue;
}
if (block->from() >= entityEnd) {
monoLnk++;
}
} }
const auto monoIndex = _maxLnkIndex const auto monoIndex = _maxLnkIndex
+ _maxShiftedLnkIndex + _maxShiftedLnkIndex