Skip to content

Commit

Permalink
Avoid loss of text in code editors when certain modifiers are pressed
Browse files Browse the repository at this point in the history
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

(cherry picked from commit 8f5476e)
  • Loading branch information
nyalldawson committed Apr 4, 2023
1 parent cec7e48 commit f499307
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/gui/auto_generated/codeeditors/qgscodeeditor.sip.in
Expand Up @@ -223,6 +223,8 @@ it is visible.

virtual void keyPressEvent( QKeyEvent * event );

virtual bool eventFilter( QObject * watched, QEvent * event );


virtual void initializeLexer();
%Docstring
Expand Down
19 changes: 19 additions & 0 deletions src/gui/codeeditors/qgscodeeditor.cpp
Expand Up @@ -104,6 +104,10 @@ QgsCodeEditor::QgsCodeEditor( QWidget *parent, const QString &title, bool foldin
setSciWidget();
initializeLexer();
} );

#if QSCINTILLA_VERSION < 0x020d03
installEventFilter( this );
#endif
}

// Workaround a bug in QScintilla 2.8.X
Expand Down Expand Up @@ -150,6 +154,21 @@ void QgsCodeEditor::keyPressEvent( QKeyEvent *event )
}
}

bool QgsCodeEditor::eventFilter( QObject *watched, QEvent *event )
{
#if QSCINTILLA_VERSION < 0x020d03
if ( watched == this && event->type() == QEvent::InputMethod )
{
// swallow input method events, which cause loss of selected text.
// See https://sourceforge.net/p/scintilla/bugs/1913/ , which was ported to QScintilla
// in version 2.13.3
return true;
}
#endif

return QsciScintilla::eventFilter( watched, event );
}

void QgsCodeEditor::initializeLexer()
{

Expand Down
1 change: 1 addition & 0 deletions src/gui/codeeditors/qgscodeeditor.h
Expand Up @@ -246,6 +246,7 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla

void focusOutEvent( QFocusEvent * event ) override;
void keyPressEvent( QKeyEvent * event ) override;
bool eventFilter( QObject * watched, QEvent * event ) override;

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

0 comments on commit f499307

Please sign in to comment.