mirror of https://github.com/procxx/kepka.git
Use input method commit events to commit replacements.
Partially fixes #4727.
This commit is contained in:
parent
4870558827
commit
3f7947b404
|
@ -696,6 +696,9 @@ protected:
|
||||||
void dropEvent(QDropEvent *e) override {
|
void dropEvent(QDropEvent *e) override {
|
||||||
return outer()->dropEventInner(e);
|
return outer()->dropEventInner(e);
|
||||||
}
|
}
|
||||||
|
void inputMethodEvent(QInputMethodEvent *e) override {
|
||||||
|
return outer()->inputMethodEventInner(e);
|
||||||
|
}
|
||||||
|
|
||||||
bool canInsertFromMimeData(const QMimeData *source) const override {
|
bool canInsertFromMimeData(const QMimeData *source) const override {
|
||||||
return outer()->canInsertFromMimeDataInner(source);
|
return outer()->canInsertFromMimeDataInner(source);
|
||||||
|
@ -2067,9 +2070,7 @@ void InputField::setPlaceholderHidden(bool forcePlaceholderHidden) {
|
||||||
|
|
||||||
void InputField::startPlaceholderAnimation() {
|
void InputField::startPlaceholderAnimation() {
|
||||||
const auto textLength = [&] {
|
const auto textLength = [&] {
|
||||||
const auto layout = textCursor().block().layout();
|
return getTextWithTags().text.size() + _lastPreEditText.size();
|
||||||
return getTextWithTags().text.size()
|
|
||||||
+ (layout ? layout->preeditAreaText().size() : 0);
|
|
||||||
};
|
};
|
||||||
const auto placeholderShifted = _forcePlaceholderHidden
|
const auto placeholderShifted = _forcePlaceholderHidden
|
||||||
|| (_focused && _st.placeholderScale > 0.)
|
|| (_focused && _st.placeholderScale > 0.)
|
||||||
|
@ -2324,6 +2325,19 @@ bool InputField::handleMarkdownKey(QKeyEvent *e) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputField::inputMethodEventInner(QInputMethodEvent *e) {
|
||||||
|
const auto preedit = e->preeditString();
|
||||||
|
if (_lastPreEditText != preedit) {
|
||||||
|
_lastPreEditText = preedit;
|
||||||
|
startPlaceholderAnimation();
|
||||||
|
}
|
||||||
|
const auto text = e->commitString();
|
||||||
|
_inner->QTextEdit::inputMethodEvent(e);
|
||||||
|
if (!processMarkdownReplaces(text)) {
|
||||||
|
processInstantReplaces(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const InstantReplaces &InputField::instantReplaces() const {
|
const InstantReplaces &InputField::instantReplaces() const {
|
||||||
return _mutableInstantReplaces;
|
return _mutableInstantReplaces;
|
||||||
}
|
}
|
||||||
|
@ -2378,6 +2392,13 @@ void InputField::processInstantReplaces(const QString &appended) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto position = textCursor().position();
|
const auto position = textCursor().position();
|
||||||
|
for (const auto &tag : _textAreaPossibleTags) {
|
||||||
|
if (tag.start < position
|
||||||
|
&& tag.start + tag.length >= position
|
||||||
|
&& (tag.tag == kTagCode || tag.tag == kTagPre)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto typed = getTextWithTagsPart(
|
const auto typed = getTextWithTagsPart(
|
||||||
std::max(position - replaces.maxLength, 0),
|
std::max(position - replaces.maxLength, 0),
|
||||||
position - 1).text;
|
position - 1).text;
|
||||||
|
|
|
@ -317,6 +317,7 @@ private:
|
||||||
void keyPressEventInner(QKeyEvent *e);
|
void keyPressEventInner(QKeyEvent *e);
|
||||||
void contextMenuEventInner(QContextMenuEvent *e);
|
void contextMenuEventInner(QContextMenuEvent *e);
|
||||||
void dropEventInner(QDropEvent *e);
|
void dropEventInner(QDropEvent *e);
|
||||||
|
void inputMethodEventInner(QInputMethodEvent *e);
|
||||||
|
|
||||||
QMimeData *createMimeDataFromSelectionInner() const;
|
QMimeData *createMimeDataFromSelectionInner() const;
|
||||||
bool canInsertFromMimeDataInner(const QMimeData *source) const;
|
bool canInsertFromMimeDataInner(const QMimeData *source) const;
|
||||||
|
@ -371,6 +372,7 @@ private:
|
||||||
|
|
||||||
TextWithTags _lastTextWithTags;
|
TextWithTags _lastTextWithTags;
|
||||||
std::vector<PossibleTag> _textAreaPossibleTags;
|
std::vector<PossibleTag> _textAreaPossibleTags;
|
||||||
|
QString _lastPreEditText;
|
||||||
|
|
||||||
// Tags list which we should apply while setText() call or insert from mime data.
|
// Tags list which we should apply while setText() call or insert from mime data.
|
||||||
TagList _insertedTags;
|
TagList _insertedTags;
|
||||||
|
|
Loading…
Reference in New Issue