Skip to content

Commit

Permalink
Merge d37f364 into c8ab6bf
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Sep 20, 2018
2 parents c8ab6bf + d37f364 commit 095d874
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
3 changes: 2 additions & 1 deletion doc/downloads/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var jsonData = { "versions": [
}
],
"changes": [
{ "change": "<strong>General:</strong> improved HiDPI support on Windows (see issue <a href=\"https://github.com/opencor/opencor/issues/1776\">#1776</a>)." }
{ "change": "<strong>General:</strong> improved HiDPI support on Windows (see issue <a href=\"https://github.com/opencor/opencor/issues/1776\">#1776</a>)." },
{ "change": "<strong>Editor widget:</strong> properly highlight/replace text that was found using a regular expression (see issue <a href=\"https://github.com/opencor/opencor/issues/1816\">#1816</a>)." },
]
},
{ "major": 0, "minor": 4, "patch": 1, "day": 20, "month": 5, "year": 2015, "type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int QScintillaWidget::findTextInRange(int pStartRange, int pEndRange,
int crtTargetStart = int(SendScintilla(SCI_GETTARGETSTART));
int crtTargetEnd = int(SendScintilla(SCI_GETTARGETEND));

// Find and return the position, if any, of the given text within the given
// Find and return the position, if any, of the given text in the given
// range

SendScintilla(SCI_SETSEARCHFLAGS,
Expand Down
17 changes: 13 additions & 4 deletions src/plugins/widget/EditorWidget/src/editorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void EditorWidget::updateSettings(EditorWidget *pEditorWidget)

// Show/hide our find/replace widget

setFindReplaceVisible(pEditorWidget->isFindReplaceVisible());
setFindReplaceVisible(pEditorWidget->isFindReplaceVisible(), false);

// Update the find/replace widget itself
// Note: we must inactivate (and then reactivate) our find/replace widget
Expand Down Expand Up @@ -495,6 +495,15 @@ void EditorWidget::selectAll()

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

void EditorWidget::highlightAll()
{
// Highlight all the occurences of the text, if any, in our editor

mEditor->highlightAll();
}

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

bool EditorWidget::wordWrap() const
{
// Return whether we word wrap the text
Expand Down Expand Up @@ -578,7 +587,7 @@ bool EditorWidget::isFindReplaceVisible() const

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

void EditorWidget::setFindReplaceVisible(bool pVisible)
void EditorWidget::setFindReplaceVisible(bool pVisible, bool pSelectWord)
{
// Set our find text and highlight all its occurrences, if we are to show
// our find/replace widget
Expand All @@ -589,11 +598,11 @@ void EditorWidget::setFindReplaceVisible(bool pVisible)
// reactivate our find/replace widget...

if (pVisible) {
QString selText;
QString selText = QString();

if (hasSelectedText()) {
selText = selectedText();
} else {
} else if (pSelectWord) {
int line;
int column;

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/widget/EditorWidget/src/editorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class EDITORWIDGET_EXPORT EditorWidget : public Core::Widget

void selectAll();

void highlightAll();

bool wordWrap() const;
void setWordWrap(bool pWordWrap);

Expand All @@ -135,7 +137,7 @@ class EDITORWIDGET_EXPORT EditorWidget : public Core::Widget
void setZoomLevel(int pZoomLevel);

bool isFindReplaceVisible() const;
void setFindReplaceVisible(bool pVisible);
void setFindReplaceVisible(bool pVisible, bool pSelectWord = true);

int styleAt(int pPosition) const;

Expand Down
23 changes: 17 additions & 6 deletions src/plugins/widget/EditorWidget/src/editorwidgeteditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void EditorWidgetEditorWidget::processAll(Action pAction)
QByteArray replaceText = mFindReplace->replaceText().toUtf8();
const char *rawReplaceText = replaceText.constData();
ulong rawReplaceTextLen = ulong(strlen(rawReplaceText));
int textLenDiff = replaceText.length()-findTextLen;
int selFoundTextLen = 0;

forever {
// Find the first occurrence of the given text, going backward from the
Expand All @@ -326,21 +326,29 @@ void EditorWidgetEditorWidget::processAll(Action pAction)

break;
} else {
// Either highlight or replace the found text
// Determine the length of our found text
// Note: we cannot and must not use findTextLen since we may be
// finding text using a regular expression...

int foundTextLen = int(SendScintilla(SCI_GETTARGETEND))-findTextPos;

// Either highlight or replace our found text

if (pAction == HighlightAll) {
SendScintilla(SCI_SETINDICATORCURRENT, mHighlightIndicatorNumber);
SendScintilla(SCI_INDICATORFILLRANGE, ulong(findTextPos), findTextLen);
SendScintilla(SCI_INDICATORFILLRANGE, ulong(findTextPos), foundTextLen);

int line = int(SendScintilla(SCI_LINEFROMPOSITION, findTextPos));

mHighlightedLines << line;
} else {
if (findTextPos < selectionStart)
selectionShift += textLenDiff;
selectionShift += replaceText.length()-foundTextLen;
else if (findTextPos == selectionStart)
selFoundTextLen = foundTextLen;

SendScintilla(SCI_SETTARGETSTART, findTextPos);
SendScintilla(SCI_SETTARGETEND, findTextPos+findTextLen);
SendScintilla(SCI_SETTARGETEND, findTextPos+foundTextLen);

SendScintilla(replaceCommand, rawReplaceTextLen, rawReplaceText);
}
Expand All @@ -363,7 +371,10 @@ void EditorWidgetEditorWidget::processAll(Action pAction)
endUndoAction();

SendScintilla(SCI_SETSELECTIONSTART, selectionStart+selectionShift);
SendScintilla(SCI_SETSELECTIONEND, selectionEnd+selectionShift+textLenDiff);
SendScintilla(SCI_SETSELECTIONEND, selectionEnd+selectionShift
+(selFoundTextLen?
replaceText.length()-selFoundTextLen:
0));

setHandleChanges(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ void EditorWidgetFindReplaceWidget::updateFrom(EditorWidgetFindReplaceWidget *pF

mGui->findEdit->setText(pFindReplace->findText());
mGui->replaceEdit->setText(pFindReplace->replaceText());

// Update our find options from the given find/replace widget

mCaseSensitiveAction->setChecked(pFindReplace->isCaseSensitive());
mWholeWordsOnlyAction->setChecked(pFindReplace->searchWholeWordsOnly());
mRegularExpressionAction->setChecked(pFindReplace->useRegularExpression());

// (Re)highlight all our occurrences of our owner since our find text may
// have changed as a result of our find/replace widget having been updated

mOwner->highlightAll();
}

//==============================================================================
Expand Down

0 comments on commit 095d874

Please sign in to comment.