Navigation Menu

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
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Apr 4, 2023
1 parent cb09be0 commit 7886f7e
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 @@ -443,6 +443,8 @@ Returns ``True`` if a ``font`` is a fixed pitch font.

virtual void contextMenuEvent( QContextMenuEvent *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 @@ -135,6 +135,10 @@ QgsCodeEditor::QgsCodeEditor( QWidget *parent, const QString &title, bool foldin
break;
}
}

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

// Workaround a bug in QScintilla 2.8.X
Expand Down Expand Up @@ -240,6 +244,21 @@ void QgsCodeEditor::contextMenuEvent( QContextMenuEvent *event )
menu->exec( mapToGlobal( event->pos() ) );
}

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 @@ -456,6 +456,7 @@ class GUI_EXPORT QgsCodeEditor : public QsciScintilla
void focusOutEvent( QFocusEvent *event ) override;
void keyPressEvent( QKeyEvent *event ) override;
void contextMenuEvent( QContextMenuEvent *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 7886f7e

Please sign in to comment.