Skip to content

Commit

Permalink
CellML Text view: make sure that the styling is done before updating …
Browse files Browse the repository at this point in the history
…our viewer (opencor#1926).
  • Loading branch information
agarny committed Dec 20, 2018
1 parent 18f1e13 commit 716b108
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugins/editing/CellMLTextView/CMakeLists.txt
Expand Up @@ -22,6 +22,7 @@ add_plugin(CellMLTextView
src/cellmltextviewwidget.cpp
HEADERS_MOC
src/cellmltextviewconverter.h
src/cellmltextviewlexer.h
src/cellmltextviewparser.h
src/cellmltextviewplugin.h
src/cellmltextviewscanner.h
Expand Down
Expand Up @@ -180,6 +180,10 @@ void CellmlTextViewLexer::styleText(int pBytesStart, int pBytesEnd)
if (editor()->SendScintilla(QsciScintillaBase::SCI_GETENDSTYLED) != pBytesEnd)
qFatal("FATAL ERROR | %s:%d: the styling of the text must be incremental.", __FILE__, __LINE__);
#endif

// Let people know that we are done with our styling

emit done();
}

//==============================================================================
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewlexer.h
Expand Up @@ -40,6 +40,8 @@ namespace CellMLTextView {

class CellmlTextViewLexer : public QsciLexerCustom
{
Q_OBJECT

public:
enum {
Default,
Expand Down Expand Up @@ -99,6 +101,9 @@ class CellmlTextViewLexer : public QsciLexerCustom

int fullTextBytesPosition(int pPosition) const;
int textBytesPosition(const QString &pText, int pPosition) const;

signals:
void done();
};

//==============================================================================
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewwidget.cpp
Expand Up @@ -515,11 +515,18 @@ void CellmlTextViewWidget::initialize(const QString &pFileName, bool pUpdate)
// The conversion was successful, so we can apply our CellML Text
// lexer to our editor

editingWidget->editorWidget()->setLexer(new CellmlTextViewLexer(this));
CellmlTextViewLexer *lexer = new CellmlTextViewLexer(this);

editingWidget->editorWidget()->setLexer(lexer);

// Update our viewer whenever necessary
// Note: normally, we would update our viewer when the text has
// changed or the cursor position has changed. However, when
// it comes to the text being changed, we need to make sure
// that the styling is done, hence checking for the lexer to
// be done...

connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::textChanged,
connect(lexer, &CellmlTextViewLexer::done,
this, &CellmlTextViewWidget::updateViewer);
connect(editingWidget->editorWidget(), &EditorWidget::EditorWidget::cursorPositionChanged,
this, &CellmlTextViewWidget::updateViewer);
Expand Down

0 comments on commit 716b108

Please sign in to comment.