Skip to content

Commit

Permalink
Backport PR spyder-ide#23316 on branch 6.x (PR: Prevent Chinese input…
Browse files Browse the repository at this point in the history
… method to block edit input area (spyder-ide#23319)
  • Loading branch information
ccordoba12 authored Dec 20, 2024
1 parent 02caed1 commit fb655eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 6 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def __init__(self, parent=None):
# To not use Spyder calltips obtained through the monitor
self.calltips = False

# ---- Public methods ----------------------------------------------------
# ---- Public methods
# -------------------------------------------------------------------------
def insert_horizontal_ruler(self):
"""
Insert a horizontal ruler with the appropriate color according
Expand All @@ -69,7 +70,8 @@ def insert_horizontal_ruler(self):
cursor.movePosition(cursor.End)
cursor.insertFrame(ruler)

# ---- Private methods ---------------------------------------------------
# ---- Private methods
# -------------------------------------------------------------------------
def _key_paren_left(self, text):
""" Action for '(' """
self.current_prompt_pos = self.parentWidget()._prompt_pos
Expand All @@ -79,7 +81,8 @@ def _key_paren_left(self, text):
self.show_object_info(last_obj)
self.insert_text(text)

# ---- Qt methods --------------------------------------------------------
# ---- Qt methods
# -------------------------------------------------------------------------
def showEvent(self, event):
"""Reimplement Qt Method"""
self.sig_visibility_changed.emit(True)
Expand Down
26 changes: 25 additions & 1 deletion spyder/widgets/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from qtpy.QtCore import QPoint, QRegularExpression, Qt, QUrl
from qtpy.QtGui import (
QDesktopServices, QFontMetrics, QTextCursor, QTextDocument)
from qtpy.QtWidgets import QApplication
from qtpy.QtWidgets import QApplication, QPlainTextEdit, QTextEdit
from spyder_kernels.utils.dochelpers import (getargspecfromtext, getobj,
getsignaturefromtext)

Expand Down Expand Up @@ -1498,6 +1498,30 @@ def _enter_array(self, inline):
self.sig_text_was_inserted.emit()
cursor.endEditBlock()

# ---- Qt methods
# -------------------------------------------------------------------------
def inputMethodQuery(self, query):
"""
Prevent Chinese input method to block edit input area.
Notes
-----
This was suggested by a user in spyder-ide/spyder#23313. So, it's not
tested by us.
"""
if query == Qt.ImInputItemClipRectangle:
cursor_rect = self.cursorRect()
margins = self.viewportMargins()
cursor_rect.moveTopLeft(
cursor_rect.topLeft() + QPoint(margins.left(), margins.top())
)
return cursor_rect

if isinstance(self, QPlainTextEdit):
QPlainTextEdit.inputMethodQuery(self, query)
elif isinstance(self, QTextEdit):
QTextEdit.inputMethodQuery(self, query)


class TracebackLinksMixin(object):
"""Mixin to make file names in tracebacks and anchors clickable."""
Expand Down

0 comments on commit fb655eb

Please sign in to comment.