[LyX/master] Adapt to macOS's double-space auto correction (#12975, #13292)
Koji Yokota <[email protected]>
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 9fa59bdfe5f6d63f7b1ea0f594475424eb326fc0 Author: Koji Yokota <[email protected]> Date: Thu Apr 23 22:29:45 2026 +0900 Adapt to macOS's double-space auto correction (#12975, #13292) --- src/frontends/qt/GuiWorkArea.cpp | 29 +++++++++++++++++++++++++++++ src/frontends/qt/GuiWorkArea_Private.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp index 2671b60f07..08a223bb03 100644 --- a/src/frontends/qt/GuiWorkArea.cpp +++ b/src/frontends/qt/GuiWorkArea.cpp @@ -674,9 +674,38 @@ bool GuiWorkArea::event(QEvent * e) keyPressEvent(ke); return true; } +#ifdef Q_OS_MACOS + // see "case QEvent::InputMethod:" below + if (ke->key() == Qt::Key_Space) + d->prev_space_key_ = true; + else + d->prev_space_key_ = false; +#endif return QAbstractScrollArea::event(e); } + case QEvent::InputMethod: { + QInputMethodEvent * ev = static_cast<QInputMethodEvent*>(e); +#ifdef Q_OS_MACOS + // Hitting double spaces turns the second space into an input method + // commit string "a period plus a space" in the default English keyboard + // if this feature is turned on in the system settings. + // Responding to the following Qt::InputMethodQueries triggers the + // the keyboard to send the commit string mentioned above: + // * Qt::ImCursorPosition, + // * Qt::ImAbsolutePosition, and + // * Qt::ImTextBeforeCursor. + + if (d->prev_space_key_ && ev->commitString() == d->auto_replacement_str_) { + // delete the already typed space out of the input method + lyx::dispatch(FuncRequest(LFUN_CHAR_DELETE_BACKWARD)); + d->prev_space_key_ = false; + } +#endif + inputMethodEvent(ev); + return e->isAccepted(); + } + default: return QAbstractScrollArea::event(e); } diff --git a/src/frontends/qt/GuiWorkArea_Private.h b/src/frontends/qt/GuiWorkArea_Private.h index 5dff7ce5f7..105603757a 100644 --- a/src/frontends/qt/GuiWorkArea_Private.h +++ b/src/frontends/qt/GuiWorkArea_Private.h @@ -156,6 +156,12 @@ struct GuiWorkArea::Private QTransform item_trans_; /// whether item_rect_ and item_trans need to be reset bool item_geom_needs_reset_ = false; +#ifdef Q_OS_MACOS + /// whether previously input key was a spacekey + bool prev_space_key_ = false; + /// the replacement string that macOS sends when double spaces are hit + QString const auto_replacement_str_ = ". "; +#endif /// for debug //QLocale::Language im_lang_ = QLocale::AnyLanguage; -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs