Skip to content

Commit

Permalink
Major: 0.2.15.18
Browse files Browse the repository at this point in the history
Bug Fixed:
1. Fixed #6 Infinite replace all bug.
2. Fixed #5 search function creashed bug.
  • Loading branch information
Saki committed Dec 24, 2013
1 parent fdf1c0f commit ec282df
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 135 deletions.
59 changes: 36 additions & 23 deletions src/app/kccodeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,17 @@ void KCCodeEditor::showCompileBar()
}
}

void KCCodeEditor::setUseLastCuror()
{
searchUseLastCursor=true;
}

void KCCodeEditor::showSearchBar()
{
if(replaceBar->isVisible())
{
searcherConnections.disConnectAll();
replaceBar->setConnected(false);
replaceBar->hideAnime();
}

Expand All @@ -235,11 +241,15 @@ void KCCodeEditor::showSearchBar()
editor->backupSearchTextCursor();
}
searchBar->animeShow();
searcherConnections+=connect(searchBar, SIGNAL(requireLostFocus()),
editor, SLOT(setFocus()));
searcherConnections+=connect(searchBar, SIGNAL(requireLostFocus()),
this, SLOT(setUseLastCuror()));
connectSearchWidgetWithEditor(searchBar);
if(!searchBar->getConnected())
{
searchBar->setConnected(true);
connectSearchWidgetWithEditor(searchBar);
searcherConnections+=connect(searchBar, SIGNAL(requireLostFocus()),
editor, SLOT(setFocus()));
searcherConnections+=connect(searchBar, SIGNAL(requireLostFocus()),
this, SLOT(setUseLastCuror()));
}
}

QTextCursor _textCursor=editor->textCursor();
Expand All @@ -250,34 +260,37 @@ void KCCodeEditor::showSearchBar()
searchBar->setTextFocus();
}

void KCCodeEditor::setUseLastCuror()
{
searchUseLastCursor=true;
}

void KCCodeEditor::showReplaceBar()
{
if(searchBar->isVisible())
{
searchBar->animeHide();
searcherConnections.disConnectAll();
searchBar->setConnected(false);
searchBar->animeHide();
}

if(!replaceBar->isVisible())
{
if(!searchUseLastCursor)
{
editor->backupSearchTextCursor();
}
replaceBar->showAnime();

connectSearchWidgetWithEditor(replaceBar);
searcherConnections+=connect(replaceBar, SIGNAL(requireLostFocus()),
editor, SLOT(setFocus()));
searcherConnections+=connect(replaceBar, SIGNAL(requireLostFocus()),
this, SLOT(setUseLastCuror()));
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplace,
editor,&KCTextEditor::replace);
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplaceAndFind,
editor,&KCTextEditor::replaceAndFind);
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplaceAll,
editor,&KCTextEditor::replaceAll);
if(!replaceBar->getConnected())
{
replaceBar->setConnected(true);
connectSearchWidgetWithEditor(replaceBar);
searcherConnections+=connect(replaceBar, SIGNAL(requireLostFocus()),
editor, SLOT(setFocus()));
searcherConnections+=connect(replaceBar, SIGNAL(requireLostFocus()),
this, SLOT(setUseLastCuror()));
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplace,
editor,&KCTextEditor::replace);
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplaceAndFind,
editor,&KCTextEditor::replaceAndFind);
searcherConnections+=connect(replaceBar,&KCReplaceWindow::requireReplaceAll,
editor,&KCTextEditor::replaceAll);
}
}

QTextCursor _textCursor=editor->textCursor();
Expand Down
10 changes: 10 additions & 0 deletions src/app/kcsearchwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,13 @@ void KCSearchWidget::resizeEvent(QResizeEvent *event)
{
searchText->setFixedWidth(event->size().width());
}
bool KCSearchWidget::getConnected() const
{
return connected;
}

void KCSearchWidget::setConnected(bool value)
{
connected = value;
}

4 changes: 4 additions & 0 deletions src/app/kcsearchwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class KCSearchWidget : public QWidget
static const int searchTextPartWidth;
void restoreLastSearchText();

bool getConnected() const;
void setConnected(bool value);

signals:
void requireShowPreviousResult();
void requireShowNextResult();
Expand Down Expand Up @@ -83,6 +86,7 @@ public slots:
};

int currResultNum;
bool connected;

QGridLayout *searchLayout;
QToolButton *prevResult, *nextResult;
Expand Down
59 changes: 35 additions & 24 deletions src/app/kctextblockdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,57 @@ void KCTextBlockData::resetForSearch()
{
needSearchAgain=false;
matchedTextPositions.clear();
matchedInfo gmin,gmax;
gmin.pos=INT_MIN;
gmax.pos=INT_MAX;
matchedTextPositions<<gmin<<gmax; //two guard elements
}

QList<matchedInfo>::iterator KCTextBlockData::getFirstMatchedTextPosition()
void KCTextBlockData::setSearchCode(const unsigned long long &searchCode)
{
return matchedTextPositions.begin()+1; //skip the guard elements
this->searchCode=searchCode;
}

QList<matchedInfo>::iterator KCTextBlockData::getEndMatchedTextPosition()
KCTextBlockData::matchedInfo KCTextBlockData::getMatchedInfo(int index)
{
return matchedTextPositions.end()-1; //skip the guard elements
return matchedTextPositions.at(index);
}

void KCTextBlockData::setSearchCode(const unsigned long long &searchCode)
int KCTextBlockData::matchedCount()
{
this->searchCode=searchCode;
return matchedTextPositions.count();
}

void KCTextBlockData::insertMatchedTextPositions(const int &pos,
const int &matchedLen)
const int &matchedLen)
{
auto i=matchedTextPositions.begin(),
l=matchedTextPositions.end();
while(i<l)
matchedInfo newElement;
newElement.pos=pos;
newElement.matchedLength=matchedLen;
switch(matchedTextPositions.count())
{
if(i->pos<=pos && pos <= (i+1)->pos)
case 0:
matchedTextPositions.append(newElement);
break;
case 1:
matchedTextPositions.insert(pos>matchedTextPositions.at(0).pos?1:0,
newElement);
break;
default:
int finalPosition=matchedTextPositions.count()-1;
bool insertFlag=false;
for(int i=0;i<finalPosition;i++)
{
break;
if(matchedTextPositions.at(i).pos<=pos &&
matchedTextPositions.at(i+1).pos>=pos)
{
insertFlag=true;
matchedTextPositions.insert(i+1,newElement);
break;
}
}

i++;
if(!insertFlag)
{
matchedTextPositions.append(newElement);
}
break;
}

matchedInfo newElement;
newElement.pos=pos;
newElement.matchedLength=matchedLen;
matchedTextPositions.insert(i+1,newElement);
}

void KCTextBlockData::insertQuotationInfo(const int &beginPos, const int &endPos)
Expand Down Expand Up @@ -105,7 +116,7 @@ void KCTextBlockData::endUsingSearchDatas()

bool KCTextBlockData::hasMatched()
{
return matchedTextPositions.size()>2;
return !matchedTextPositions.isEmpty();
}

void KCTextBlockData::resetParentheseInfos()
Expand Down
17 changes: 9 additions & 8 deletions src/app/kctextblockdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
#include <QString>
#include <QMutex>

struct matchedInfo
{
int pos;
int matchedLength;
};

struct quotationInfo
{
int beginPos;
Expand All @@ -56,14 +50,21 @@ struct markUnit
class KCTextBlockData : public QTextBlockUserData
{
public:
struct matchedInfo
{
int pos;
int matchedLength;
};

KCTextBlockData();
void beginUsingSearchDatas();
void endUsingSearchDatas();

void resetForSearch();
void setSearchCode(const unsigned long long int &searchCode);
QList<matchedInfo>::iterator getFirstMatchedTextPosition();
QList<matchedInfo>::iterator getEndMatchedTextPosition();
matchedInfo getMatchedInfo(int index);
int matchedCount();

void insertMatchedTextPositions(const int &pos, const int &matchedLen);
bool isSearched(const unsigned long long int &searchCodeNow);
bool hasMatched();
Expand Down
Loading

0 comments on commit ec282df

Please # to comment.