Skip to content

Commit

Permalink
fixed textutil
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 14, 2024
1 parent 3fa3901 commit f9096cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/textutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,19 @@ static void emojiconifyPlainText(RTParse &p, const QString &in)
QLatin1String(
R"html(<span style="font-family: 'Apple Color Emoji', 'Noto Color Emoji', 'Segoe UI Emoji'; font-size:1.5em">)html")
#endif
+ QStringView{in}.mid(emojisStartIdx, idx - emojisStartIdx) + QLatin1String("</span>"));
+ QStringView{in}.mid(emojisStartIdx, idx - emojisStartIdx).toString() + QLatin1String("</span>"));
};
while (!(ref = reg.findEmoji(in, idx)).isEmpty()) {
int position;
while (std::tie(ref, position) = reg.findEmoji(in, idx), !ref.isEmpty()) {
if (emojisStartIdx == -1) {
emojisStartIdx = ref.position();
p.putPlain(in.left(ref.position()));
} else if (ref.position() != idx) { // a text gap
emojisStartIdx = position;
p.putPlain(in.left(position));
} else if (position != idx) { // a text gap
dump_emoji();
emojisStartIdx = ref.position();
p.putPlain(in.mid(idx, ref.position() - idx));
emojisStartIdx = position;
p.putPlain(in.mid(idx, position - idx));
}
idx = ref.position() + ref.size();
idx = position + ref.size();
}
if (emojisStartIdx == -1)
p.putPlain(in);
Expand Down Expand Up @@ -421,7 +422,7 @@ QString TextUtil::linkify(const QString &in)
}
int len = x2 - x1;
QString pre = out.mid(x1, x2 - x1);
pre = resolveEntities(&pre);
pre = resolveEntities(pre);

// go backward hacking off unwanted punctuation
int cutoff;
Expand Down Expand Up @@ -517,7 +518,7 @@ QString TextUtil::emoticonify(const QString &in)
QListIterator<PsiIcon *> it = iconset->iterator();
while (it.hasNext()) {
PsiIcon *icon = it.next();
if (icon->regExp().isEmpty())
if (icon->regExp().pattern().isEmpty())
continue;

// some hackery
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/emojiregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int EmojiRegistry::count() const
return count;
}

QStringView EmojiRegistry::findEmoji(const QString &in, int idx) const
std::pair<QStringView,int> EmojiRegistry::findEmoji(const QString &in, int idx) const
{
int emojiStart = -1;

Expand Down Expand Up @@ -130,7 +130,7 @@ QStringView EmojiRegistry::findEmoji(const QString &in, int idx) const
if (in[idx].isHighSurrogate())
idx++;
}
return emojiStart == -1 ? QStringView() : QStringView{in}.mid(emojiStart, idx - emojiStart);
return emojiStart == -1 ? std::make_pair(QStringView(),-1) : std::make_pair(QStringView{in}.mid(emojiStart, idx - emojiStart), emojiStart);
}

EmojiRegistry::EmojiRegistry() : groups(std::move(db)), ranges_(std::move(ranges)) { }
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/emojiregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EmojiRegistry {
bool isEmoji(const QString &code) const;

/// Find emoji in a string starting from the specified position
QStringView findEmoji(const QString &in, int startPos = 0) const;
std::pair<QStringView, int> findEmoji(const QString &in, int startPos = 0) const;

/*!
* \brief startCategory returns category of what the string starts with if the sequence looks valida for emoji
Expand Down

0 comments on commit f9096cb

Please sign in to comment.