Skip to content

Commit 8f5476e

Browse files
committedApr 4, 2023
Avoid loss of text in code editors when certain modifiers are pressed
These are triggered when a InputMethod event is sent to the widget. There's upstream discussion at https://sourceforge.net/p/scintilla/bugs/1913/ and the fix was added to QScintilla version 2.13.3 As the loss of text is an extreme risk, just disable input method handling in these widgets on affected versions entirely. Fixes #52459
1 parent ad7e2a3 commit 8f5476e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed
 

‎python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,8 @@ Returns ``True`` if a ``font`` is a fixed pitch font.
483483

484484
virtual void contextMenuEvent( QContextMenuEvent *event );
485485

486+
virtual bool eventFilter( QObject *watched, QEvent *event );
487+
486488

487489
virtual void initializeLexer();
488490
%Docstring

‎src/gui/codeeditors/qgscodeeditor.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ QgsCodeEditor::QgsCodeEditor( QWidget *parent, const QString &title, bool foldin
138138
break;
139139
}
140140
}
141+
142+
#if QSCINTILLA_VERSION < 0x020d03
143+
installEventFilter( this );
144+
#endif
141145
}
142146

143147
// Workaround a bug in QScintilla 2.8.X
@@ -312,6 +316,21 @@ void QgsCodeEditor::contextMenuEvent( QContextMenuEvent *event )
312316
}
313317
}
314318

319+
bool QgsCodeEditor::eventFilter( QObject *watched, QEvent *event )
320+
{
321+
#if QSCINTILLA_VERSION < 0x020d03
322+
if ( watched == this && event->type() == QEvent::InputMethod )
323+
{
324+
// swallow input method events, which cause loss of selected text.
325+
// See https://sourceforge.net/p/scintilla/bugs/1913/ , which was ported to QScintilla
326+
// in version 2.13.3
327+
return true;
328+
}
329+
#endif
330+
331+
return QsciScintilla::eventFilter( watched, event );
332+
}
333+
315334
void QgsCodeEditor::initializeLexer()
316335
{
317336

‎src/gui/codeeditors/qgscodeeditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
502502
void focusOutEvent( QFocusEvent *event ) override;
503503
void keyPressEvent( QKeyEvent *event ) override;
504504
void contextMenuEvent( QContextMenuEvent *event ) override;
505+
bool eventFilter( QObject *watched, QEvent *event ) override;
505506

506507
/**
507508
* Called when the dialect specific code lexer needs to be initialized (or reinitialized).

0 commit comments

Comments
 (0)
Please sign in to comment.