Skip to content

Commit

Permalink
Merge 6c92012 into a430b7a
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 1, 2018
2 parents a430b7a + 6c92012 commit a852ecb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 28 deletions.
1 change: 1 addition & 0 deletions doc/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var jsonData = { "versions": [
}
],
"changes": [
{ "change": "<strong>Property Editor widget:</strong> prevent infinite \"Replace all\" actions (see issue <a href=\"https://github.com/opencor/opencor/issues/1677\">#1677</a>)." },
{ "change": "<strong>Third-party libraries:</strong> upgraded <a href=\"https://libgit2.github.com/\">libgit2</a> to version 0.27.1 (see issue <a href=\"https://github.com/opencor/opencor/issues/1672\">#1672</a>)." }
]
},
Expand Down
75 changes: 53 additions & 22 deletions src/plugins/support/QScintillaSupport/src/qscintillawidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,9 @@ QScintillaWidget::QScintillaWidget(QsciLexer *pLexer, QWidget *pParent) :
mCursorPositionWidget = new QLabel(this);
mEditingModeWidget = new QLabel(this);

// Keep track of the change to the UI
// Keep track of various changes

connect(this, &QScintillaWidget::SCN_UPDATEUI,
this, &QScintillaWidget::updateUi);

// Keep track of changes to our editor and resize the margin line numbers
// accordingly

connect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::updateMarginLineNumbersWidth);

// Keep track of changes to our editor that may affect our ability to select
// all of its text

connect(this, &QScintillaWidget::selectionChanged,
this, &QScintillaWidget::checkCanSelectAll);
connect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::checkCanSelectAll);

// Keep track of the change in the cursor position

connect(this, &QScintillaWidget::cursorPositionChanged,
this, &QScintillaWidget::updateCursorPosition);
trackChanges(true);
}

//==============================================================================
Expand Down Expand Up @@ -633,6 +613,57 @@ void QScintillaWidget::wheelEvent(QWheelEvent *pEvent)

//==============================================================================

void QScintillaWidget::trackChanges(bool pTrackChanges)
{
// Keep track of changes to the UI

if (pTrackChanges) {
connect(this, &QScintillaWidget::SCN_UPDATEUI,
this, &QScintillaWidget::updateUi);
} else {
disconnect(this, &QScintillaWidget::SCN_UPDATEUI,
this, &QScintillaWidget::updateUi);
}

// Keep track of changes to our editor and resize the margin line numbers
// accordingly

if (pTrackChanges) {
connect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::updateMarginLineNumbersWidth);
} else {
disconnect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::updateMarginLineNumbersWidth);
}

// Keep track of changes to our editor that may affect our ability to select
// all of its text

if (pTrackChanges) {
connect(this, &QScintillaWidget::selectionChanged,
this, &QScintillaWidget::checkCanSelectAll);
connect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::checkCanSelectAll);
} else {
disconnect(this, &QScintillaWidget::selectionChanged,
this, &QScintillaWidget::checkCanSelectAll);
disconnect(this, &QScintillaWidget::textChanged,
this, &QScintillaWidget::checkCanSelectAll);
}

// Keep track of changes to the cursor position

if (pTrackChanges) {
connect(this, &QScintillaWidget::cursorPositionChanged,
this, &QScintillaWidget::updateCursorPosition);
} else {
disconnect(this, &QScintillaWidget::cursorPositionChanged,
this, &QScintillaWidget::updateCursorPosition);
}
}

//==============================================================================

void QScintillaWidget::zoomIn()
{
// Zoom in the default way and then update our margin line numbers width
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/support/QScintillaSupport/src/qscintillawidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class QSCINTILLASUPPORT_EXPORT QScintillaWidget : public QsciScintilla
void keyPressEvent(QKeyEvent *pEvent) override;
void wheelEvent(QWheelEvent *pEvent) override;

void trackChanges(bool pTrackChanges);

private:
QFont mFont;

Expand Down
26 changes: 20 additions & 6 deletions src/plugins/widget/EditorWidget/src/editorwidgeteditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ void EditorWidgetEditorWidget::doHighlightReplaceAll(bool pHighlightAll)
int horizontalScrollBarPosition = horizontalScrollBar()->value();
int verticalScrollBarPosition = verticalScrollBar()->value();

// Stop tracking changes if we are replacing all

if (!pHighlightAll)
trackChanges(false);

// Go to the beginning of our editor

QsciScintilla::setCursorPosition(0, 0);
Expand All @@ -307,16 +312,20 @@ void EditorWidgetEditorWidget::doHighlightReplaceAll(bool pHighlightAll)

int origPosition = -1;
int crtPosition;
int findTextLength = mFindReplace->findText().length();
QString replaceText = mFindReplace->replaceText();

while (findNext()) {
// Retrieve our new position
// Retrieve our current position

crtPosition = currentPosition();

// Check whether we are back to our original position, in case we are
// trying to highlight all the occurrences of the text
// Check whether we are back to our original position
// Note: we want to do this both when highlighting all (obviously), but
// also when replacing all in case we were to replace, say, "abc"
// with "abcd"...

if (pHighlightAll && (crtPosition == origPosition))
if (crtPosition == origPosition)
break;

// Our new position is fine, so highlight/replace the occurrence of the
Expand All @@ -328,12 +337,12 @@ void EditorWidgetEditorWidget::doHighlightReplaceAll(bool pHighlightAll)
int toLine;
int toColumn;

lineIndexFromPosition(crtPosition-mFindReplace->findText().length(), &fromLine, &fromColumn);
lineIndexFromPosition(crtPosition-findTextLength, &fromLine, &fromColumn);
lineIndexFromPosition(crtPosition, &toLine, &toColumn);

addHighlighting(fromLine, fromColumn, toLine, toColumn);
} else {
QScintillaSupport::QScintillaWidget::replace(mFindReplace->replaceText());
QScintillaSupport::QScintillaWidget::replace(replaceText);
}

// Initialise our first line/column, if needed
Expand All @@ -342,6 +351,11 @@ void EditorWidgetEditorWidget::doHighlightReplaceAll(bool pHighlightAll)
origPosition = crtPosition;
}

// Re-enable the tracking of changes if we are replacing all

if (!pHighlightAll)
trackChanges(true);

// Go back to our original first visible line, position (after having
// corrected it, but only if we replaced all the occurrences of the text)
// and scroll bar positions
Expand Down

0 comments on commit a852ecb

Please sign in to comment.