From 910eb2620963f6a2849b901a398ead2c44aa9da6 Mon Sep 17 00:00:00 2001 From: Jan Sundermeyer Date: Tue, 20 Aug 2019 22:08:16 +0200 Subject: [PATCH] extend search restrictions to label/citations --- images-ng/cite.svg | 95 +++++++++++++++++++ images-ng/label.svg | 95 +++++++++++++++++++ images.qrc | 2 + src/qcodeedit/lib/document/qdocument.cpp | 6 ++ src/qcodeedit/lib/document/qdocumentline.cpp | 8 ++ src/qcodeedit/lib/document/qdocumentline.h | 1 + src/qcodeedit/lib/document/qdocumentline_p.h | 1 + .../lib/document/qdocumentsearch.cpp | 32 ++++--- src/qcodeedit/lib/document/qdocumentsearch.h | 5 +- .../lib/widgets/qsearchreplacepanel.cpp | 12 ++- 10 files changed, 239 insertions(+), 18 deletions(-) create mode 100644 images-ng/cite.svg create mode 100644 images-ng/label.svg diff --git a/images-ng/cite.svg b/images-ng/cite.svg new file mode 100644 index 0000000000..4d380e4695 --- /dev/null +++ b/images-ng/cite.svg @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + cite + + + + diff --git a/images-ng/label.svg b/images-ng/label.svg new file mode 100644 index 0000000000..51e9fe760a --- /dev/null +++ b/images-ng/label.svg @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + label  + + + + diff --git a/images.qrc b/images.qrc index 492ffa6fb7..6d705f7c3a 100644 --- a/images.qrc +++ b/images.qrc @@ -210,5 +210,7 @@ images-ng/command.svg images-ng/all.svg images-ng/verbatim.svg + images-ng/cite.svg + images-ng/label.svg diff --git a/src/qcodeedit/lib/document/qdocument.cpp b/src/qcodeedit/lib/document/qdocument.cpp index be3dfc0f65..fa3cc6f914 100644 --- a/src/qcodeedit/lib/document/qdocument.cpp +++ b/src/qcodeedit/lib/document/qdocument.cpp @@ -3192,6 +3192,12 @@ QVector QDocumentLineHandle::getFormats() const return m_formats; } +QVector QDocumentLineHandle::getCachedFormats() const +{ + QReadLocker locker(&mLock); + return m_cache; +} + bool QDocumentLineHandle::isRTLByLayout() const{ if (!m_layout) return false; else { diff --git a/src/qcodeedit/lib/document/qdocumentline.cpp b/src/qcodeedit/lib/document/qdocumentline.cpp index e00e1ccb73..5d54cda03a 100644 --- a/src/qcodeedit/lib/document/qdocumentline.cpp +++ b/src/qcodeedit/lib/document/qdocumentline.cpp @@ -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& 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(); diff --git a/src/qcodeedit/lib/document/qdocumentline.h b/src/qcodeedit/lib/document/qdocumentline.h index 557211a202..30c40605bf 100644 --- a/src/qcodeedit/lib/document/qdocumentline.h +++ b/src/qcodeedit/lib/document/qdocumentline.h @@ -184,6 +184,7 @@ class QCE_EXPORT QDocumentLine QVector compose(); QVector getFormats(); int getFormatAt(int pos) const; + int getCachedFormatAt(int pos) const; const QVector& parentheses() const; void setParentheses(const QVector& parentheses); diff --git a/src/qcodeedit/lib/document/qdocumentline_p.h b/src/qcodeedit/lib/document/qdocumentline_p.h index 872f35d390..0f4d571081 100644 --- a/src/qcodeedit/lib/document/qdocumentline_p.h +++ b/src/qcodeedit/lib/document/qdocumentline_p.h @@ -143,6 +143,7 @@ class QCE_EXPORT QDocumentLineHandle QVector compose() const; QVector getFormats() const; + QVector getCachedFormats() const; void lockForRead() const { mLock.lockForRead(); diff --git a/src/qcodeedit/lib/document/qdocumentsearch.cpp b/src/qcodeedit/lib/document/qdocumentsearch.cpp index e3726a36e4..3bb55bf78d 100644 --- a/src/qcodeedit/lib/document/qdocumentsearch.cpp +++ b/src/qcodeedit/lib/document/qdocumentsearch.cpp @@ -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(); } @@ -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()); @@ -382,21 +382,23 @@ void QDocumentSearch::setOptions(Options options){ for (int i=0;i<8;i++) setOption(static_cast