Handle IMEs
This commit is contained in:
@@ -44,8 +44,8 @@ from PyQt6.QtCore import (
|
|||||||
)
|
)
|
||||||
from PyQt6.QtGui import (
|
from PyQt6.QtGui import (
|
||||||
QAction, QCursor, QDragEnterEvent, QDragMoveEvent, QDropEvent, QKeyEvent,
|
QAction, QCursor, QDragEnterEvent, QDragMoveEvent, QDropEvent, QKeyEvent,
|
||||||
QKeySequence, QMouseEvent, QPalette, QPixmap, QResizeEvent, QShortcut,
|
QKeySequence, QInputMethodEvent, QMouseEvent, QPalette, QPixmap, QResizeEvent,
|
||||||
QTextBlock, QTextCursor, QTextDocument, QTextOption
|
QShortcut, QTextBlock, QTextCursor, QTextDocument, QTextOption,
|
||||||
)
|
)
|
||||||
from PyQt6.QtWidgets import (
|
from PyQt6.QtWidgets import (
|
||||||
QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
QApplication, QFrame, QGridLayout, QHBoxLayout, QLabel, QLineEdit, QMenu,
|
||||||
@@ -1017,6 +1017,29 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
super().resizeEvent(event)
|
super().resizeEvent(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def inputMethodEvent(self, event: QInputMethodEvent) -> None:
|
||||||
|
"""Handle text being input from CJK input methods"""
|
||||||
|
super().inputMethodEvent(event)
|
||||||
|
if event.commitString():
|
||||||
|
self.ensureCursorVisible()
|
||||||
|
if self._completer.isVisible():
|
||||||
|
rect = self.cursorRect()
|
||||||
|
pos = self.mapToGlobal(rect.bottomLeft())
|
||||||
|
self._completer.move(pos)
|
||||||
|
|
||||||
|
def inputMethodQuery(self, query: Qt.InputMethodQuery):
|
||||||
|
"""Adjust completion windows for CJK input methods to consider
|
||||||
|
the viewport margins.
|
||||||
|
"""
|
||||||
|
if query == Qt.InputMethodQuery.ImCursorRectangle:
|
||||||
|
rect = self.cursorRect()
|
||||||
|
vM = self.viewportMargins()
|
||||||
|
rect.translate(vM.left(), vM.top())
|
||||||
|
|
||||||
|
return rect
|
||||||
|
|
||||||
|
return super().inputMethodQuery(query)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Public Slots
|
# Public Slots
|
||||||
##
|
##
|
||||||
|
|||||||
Reference in New Issue
Block a user