Skip to content

Commit

Permalink
extend search restrictions to label/citations
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Aug 20, 2019
1 parent 1814f24 commit 910eb26
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 18 deletions.
95 changes: 95 additions & 0 deletions images-ng/cite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions images-ng/label.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,7 @@
<file>images-ng/command.svg</file>
<file>images-ng/all.svg</file>
<file>images-ng/verbatim.svg</file>
<file>images-ng/cite.svg</file>
<file>images-ng/label.svg</file>
</qresource>
</RCC>
6 changes: 6 additions & 0 deletions src/qcodeedit/lib/document/qdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3192,6 +3192,12 @@ QVector<int> QDocumentLineHandle::getFormats() const
return m_formats;
}

QVector<int> QDocumentLineHandle::getCachedFormats() const
{
QReadLocker locker(&mLock);
return m_cache;
}

bool QDocumentLineHandle::isRTLByLayout() const{
if (!m_layout) return false;
else {
Expand Down
8 changes: 8 additions & 0 deletions src/qcodeedit/lib/document/qdocumentline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ int QDocumentLine::getFormatAt(int pos) const{
return formats.at(pos);
}

int QDocumentLine::getCachedFormatAt(int pos) const{
if( !m_handle ) return -1;
if (pos < 0 ) return -1;
const QVector<int>& formats = m_handle->getCachedFormats();
if( pos >= formats.size() ) return -1;
return formats.at(pos);
}

QVariant QDocumentLine::getCookie(int type){
if(!m_handle) return QVariant();
m_handle->lockForRead();
Expand Down
1 change: 1 addition & 0 deletions src/qcodeedit/lib/document/qdocumentline.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class QCE_EXPORT QDocumentLine
QVector<int> compose();
QVector<int> getFormats();
int getFormatAt(int pos) const;
int getCachedFormatAt(int pos) const;

const QVector<QParenthesis>& parentheses() const;
void setParentheses(const QVector<QParenthesis>& parentheses);
Expand Down
1 change: 1 addition & 0 deletions src/qcodeedit/lib/document/qdocumentline_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class QCE_EXPORT QDocumentLineHandle

QVector<int> compose() const;
QVector<int> getFormats() const;
QVector<int> getCachedFormats() const;

void lockForRead() const {
mLock.lockForRead();
Expand Down
32 changes: 17 additions & 15 deletions src/qcodeedit/lib/document/qdocumentsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/

QDocumentSearch::QDocumentSearch(QEditor *e, const QString& f, Options opt, const QString& r)
: m_option(opt), m_string(f), m_replace(r), m_editor(e), m_replaced(0), m_replaceDeltaLength(0),m_filteredId(-1)
: m_option(opt), m_string(f), m_replace(r), m_editor(e), m_replaced(0), m_replaceDeltaLength(0)
{
connectToEditor();
}
Expand Down Expand Up @@ -171,12 +171,12 @@ void QDocumentSearch::searchMatches(const QDocumentCursor& subHighlightScope, bo
hc.setColumnNumber(column+1); //empty (e.g. a* regexp)
else {
// filter by format if desired
int fmt=l.getFormatAt(column);
int fmt=l.getCachedFormatAt(column);

hc.setColumnNumber(column);
hc.setColumnNumber(column + m_regexp.matchedLength(), QDocumentCursor::KeepAnchor);

if(m_filteredId<=0 || fmt==m_filteredId){
if(m_filteredIds.isEmpty() || m_filteredIds.contains(fmt&255)|| m_filteredIds.contains((fmt>>8)&255)|| m_filteredIds.contains((fmt>>16)&255)){
// add filtered or all
hc.line().addOverlay(QFormatRange(hc.anchorColumnNumber(), hc.columnNumber() - hc.anchorColumnNumber(), sid));
m_highlights.insert(l.handle());
Expand Down Expand Up @@ -382,21 +382,23 @@ void QDocumentSearch::setOptions(Options options){
for (int i=0;i<8;i++)
setOption(static_cast<Option>(1<<i), options & (1<<i));
}

void QDocumentSearch::setFilteredFormats(QList<int> ids){
m_filteredIds=ids;
// update search
if (m_option & QDocumentSearch::HighlightAll){
// matches may have become invalid : update them
searchMatches();
visibleLinesChanged();
}
}
void QDocumentSearch::setFilteredFormat(int id)
{
m_filteredId=id;
// update search
if (m_option & QDocumentSearch::HighlightAll){
// matches may have become invalid : update them
searchMatches();
visibleLinesChanged();
}
setFilteredFormats({id});
}

int QDocumentSearch::getFilteredFormat() const
QList<int> QDocumentSearch::getFilteredFormats() const
{
return m_filteredId;
return m_filteredIds;
}


Expand Down Expand Up @@ -706,8 +708,8 @@ int QDocumentSearch::next(bool backward, bool all, bool again, bool allowWrapAro
// filter out matches that don't fulfill fomarting i.e. math-env
bool filtered=false;
if(column != -1 && (backward || column >= m_cursor.columnNumber() ) ){
int fmt=l.getFormatAt(column);
if(m_filteredId>0 && fmt!=m_filteredId){
int fmt=l.getCachedFormatAt(column);
if(!m_filteredIds.isEmpty() && !m_filteredIds.contains(fmt&255) && !m_filteredIds.contains((fmt>>8)&255) && !m_filteredIds.contains((fmt>>16)&255)){
// filter non-math
m_cursor.setColumnNumber(column+1);
column=-1;
Expand Down
5 changes: 3 additions & 2 deletions src/qcodeedit/lib/document/qdocumentsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class QCE_EXPORT QDocumentSearch: public QObject
void setOptions(Options options);

void setFilteredFormat(int id);
int getFilteredFormat() const;
void setFilteredFormats(QList<int> ids);
QList<int> getFilteredFormats() const;

QString replaceText() const;
void setReplaceText(const QString& r);
Expand Down Expand Up @@ -112,7 +113,7 @@ class QCE_EXPORT QDocumentSearch: public QObject

int m_replaced,m_replaceDeltaLength,m_replaceDeltaLines;

int m_filteredId;
QList<int> m_filteredIds;
private slots:
void documentContentChanged(int line, int n);
void visibleLinesChanged();
Expand Down
12 changes: 11 additions & 1 deletion src/qcodeedit/lib/widgets/qsearchreplacepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ QSearchReplacePanel::QSearchReplacePanel(QWidget *p)
menu->addAction(getRealIcon("verbatim"),"verbatim",this,SLOT(filterChanged()));
menu->addAction(getRealIcon("comment"),"comment",this,SLOT(filterChanged()));
menu->addAction(getRealIcon("command"),"keyword",this,SLOT(filterChanged()));
menu->addAction(getRealIcon("label"),"label",this,SLOT(filterChanged()));
menu->addAction(getRealIcon("cite"),"citation",this,SLOT(filterChanged()));
cbFilter->setMenu(menu);
cbFilter->setPopupMode(QToolButton::InstantPopup);
cbFilter->setIcon(getRealIconCached("all"));
Expand Down Expand Up @@ -926,7 +928,7 @@ void QSearchReplacePanel::filterChanged()
QString text=act->text();
QDocument *doc=editor()->document();
if(text=="all") {
m_search->setFilteredFormat(-1);
m_search->setFilteredFormats(QList<int>());
cbFilter->setIcon(getRealIconCached("all"));
}
if(text=="math") {
Expand All @@ -945,6 +947,14 @@ void QSearchReplacePanel::filterChanged()
m_search->setFilteredFormat(doc->getFormatId("keyword"));
cbFilter->setIcon(getRealIconCached("command"));
}
if(text=="label") {
m_search->setFilteredFormats({doc->getFormatId("referencePresent"),doc->getFormatId("referenceMissing"),doc->getFormatId("referenceMultiple")});
cbFilter->setIcon(getRealIconCached("label"));
}
if(text=="citation") {
m_search->setFilteredFormats({doc->getFormatId("citationPresent"),doc->getFormatId("citationMissing")});
cbFilter->setIcon(getRealIconCached("cite"));
}
}

void QSearchReplacePanel::on_cbWords_toggled(bool on)
Expand Down

0 comments on commit 910eb26

Please sign in to comment.