diff --git a/src/latexdocument.cpp b/src/latexdocument.cpp index 4f6774b74..6ee49f01e 100644 --- a/src/latexdocument.cpp +++ b/src/latexdocument.cpp @@ -3046,6 +3046,16 @@ void LatexDocument::gatherCompletionFiles(QStringList &files, QStringList &loade } } +void LatexDocument::setHideNonTextGrammarErrors(bool hide) +{ + m_hideNonTextGrammarErrors=hide; +} + +void LatexDocument::setGrammarFormats(const QList &formats) +{ + m_grammarFormats = formats; +} + QString LatexDocument::getMagicComment(const QString &name) const { QString seName; @@ -3335,6 +3345,8 @@ void LatexDocument::updateSettings() fmtList.insert(elem.first,getFormatId(elem.second)); } synChecker.setFormats(fmtList); + synChecker.setHideNonTextGrammarErrors(m_hideNonTextGrammarErrors); + synChecker.setNonTextGrammarFormats(m_grammarFormats); } void LatexDocument::checkNextLine(QDocumentLineHandle *dlh, bool clearOverlay, int ticket, int hint) diff --git a/src/latexdocument.h b/src/latexdocument.h index b4960c89e..611bc181a 100644 --- a/src/latexdocument.h +++ b/src/latexdocument.h @@ -233,6 +233,9 @@ class LatexDocument: public QDocument std::list docStructure; + void setHideNonTextGrammarErrors(bool hide); + void setGrammarFormats(const QList &formats); + private: QString fileName; //absolute QString temporaryFileName; //absolute, temporary @@ -283,6 +286,9 @@ class LatexDocument: public QDocument bool m_cachedDataOnly=false; + bool m_hideNonTextGrammarErrors=true; + QList m_grammarFormats; + #ifndef QT_NO_DEBUG public: QSet StructureContent; diff --git a/src/latexeditorview.cpp b/src/latexeditorview.cpp index c9353cc2c..08293a465 100644 --- a/src/latexeditorview.cpp +++ b/src/latexeditorview.cpp @@ -1173,6 +1173,8 @@ void LatexEditorView::removeTemporaryHighlight() void LatexEditorView::displayLineGrammarErrorsInternal(int lineNr, const QList &errors) { + const QList nonTextFormats = {numbersFormat, verbatimFormat, pictureFormat, pweaveDelimiterFormat, pweaveBlockFormat, + sweaveDelimiterFormat, sweaveBlockFormat, math_DelimiterFormat, asymptoteBlockFormat}; QDocumentLine line = document->line(lineNr); foreach (const int f, grammarFormats) line.clearOverlays(f); @@ -1185,8 +1187,11 @@ void LatexEditorView::displayLineGrammarErrorsInternal(int lineNr, const QListhideNonTextGrammarErrors && (isNonTextFormat(line.getFormatAt(error.offset)) || isNonTextFormat(line.getFormatAt(error.offset + error.length - 1)))) - continue; + if (config->hideNonTextGrammarErrors){ + QFormatRange overlays=line.getOverlayAt(error.offset,nonTextFormats); + if(overlays.length>0) + continue; + } line.addOverlay(QFormatRange(error.offset, error.length, f)); } //todo: check for width changing like if (changed && ff->format(wordRepetitionFormat).widthChanging()) line.handle()->updateWrapAndNotifyDocument(i); @@ -1827,6 +1832,8 @@ void LatexEditorView::updateSettings() QDocument::setWorkAround(QDocument::ForceSingleCharacterDrawing, config->hackRenderingMode == 2); LatexDocument::syntaxErrorFormat = syntaxErrorFormat; if (document){ + document->setHideNonTextGrammarErrors(config->hideNonTextGrammarErrors); + document->setGrammarFormats(grammarFormats); document->updateSettings(); document->setCenterDocumentInEditor(config->centerDocumentInEditor); } diff --git a/src/qcodeedit/lib/document/qdocument.cpp b/src/qcodeedit/lib/document/qdocument.cpp index d1a1ae3cf..9a38bc6ee 100644 --- a/src/qcodeedit/lib/document/qdocument.cpp +++ b/src/qcodeedit/lib/document/qdocument.cpp @@ -2961,10 +2961,19 @@ void QDocumentLineHandle::addOverlayNoLock(const QFormatRange& over) void QDocumentLineHandle::removeOverlay(const QFormatRange& over) { QWriteLocker locker(&mLock); - int i = m_overlays.removeAll(over); + removeOverlayNoLock(over); +} +/*! + * \brief remove overlay with extra write locking + * Lock needs to be held by calling function + * \param over + */ +void QDocumentLineHandle::removeOverlayNoLock(const QFormatRange &over) +{ + int i = m_overlays.removeAll(over); - if ( i ) - setFlag(QDocumentLine::FormatsApplied, false); + if ( i ) + setFlag(QDocumentLine::FormatsApplied, false); } bool QDocumentLineHandle::hasOverlay(int id){ @@ -2979,15 +2988,37 @@ bool QDocumentLineHandle::hasOverlay(int id){ QList QDocumentLineHandle::getOverlays(int preferredFormat) const { QReadLocker locker(&mLock); - QList result; - if (preferredFormat==-1) { - return m_overlays; - } + return getOverlaysNoLock(preferredFormat); +} - for (int i=0;i QDocumentLineHandle::getOverlaysNoLock(int preferredFormat) const +{ + QList result; + if (preferredFormat==-1) { + return m_overlays; + } - return result; + for (int i=0;i QDocumentLineHandle::getOverlaysNoLock(QList preferredFormats) const +{ + QList result; + if (preferredFormats.isEmpty()) { + return m_overlays; + } + + for (int i=0;i preferredFormats) const +{ + QReadLocker locker(&mLock); + + QFormatRange best; + foreach (QFormatRange fr, m_overlays) + if (fr.offset<=index && fr.offset+fr.length>=index && (preferredFormats.contains(fr.format) || preferredFormats.isEmpty())) + if (best.lengthgetOverlayAt(index,preferredFormat); } +QFormatRange QDocumentLine::getOverlayAt(int index, QList preferredFormats) const +{ + if ( !m_handle ) + return QFormatRange(); + + return m_handle->getOverlayAt(index,preferredFormats); +} + /*! * \brief Returns the first QFormatRange between columns \a start and \a end for the given \a preferredFormat. * Any format will match for \a preferredFormat == -1. diff --git a/src/qcodeedit/lib/document/qdocumentline.h b/src/qcodeedit/lib/document/qdocumentline.h index ecd729d29..90ee6a079 100644 --- a/src/qcodeedit/lib/document/qdocumentline.h +++ b/src/qcodeedit/lib/document/qdocumentline.h @@ -182,6 +182,7 @@ class QCE_EXPORT QDocumentLine bool hasOverlay(int id); QList getOverlays(int preferredFormat = -1) const; QFormatRange getOverlayAt(int index, int preferredFormat = -1) const; + QFormatRange getOverlayAt(int index, QList preferredFormats) const; QFormatRange getFirstOverlay(int start = 0, int end = -1, int preferredFormat = -1) const; QFormatRange getLastOverlay(int start = 0, int end = -1, int preferredFormat = -1) const; diff --git a/src/qcodeedit/lib/document/qdocumentline_p.h b/src/qcodeedit/lib/document/qdocumentline_p.h index a1768b6a9..259fec34a 100644 --- a/src/qcodeedit/lib/document/qdocumentline_p.h +++ b/src/qcodeedit/lib/document/qdocumentline_p.h @@ -103,9 +103,13 @@ class QCE_EXPORT QDocumentLineHandle void addOverlay(const QFormatRange& over); void addOverlayNoLock(const QFormatRange& over); void removeOverlay(const QFormatRange& over); + void removeOverlayNoLock(const QFormatRange& over); bool hasOverlay(int id); QList getOverlays(int preferredFormat) const; + QList getOverlaysNoLock(int preferredFormat) const; + QList getOverlaysNoLock(QList preferredFormats) const; QFormatRange getOverlayAt(int index, int preferredFormat) const; + QFormatRange getOverlayAt(int index, QList preferredFormats) const; QFormatRange getFirstOverlay(int start = 0, int end = -1, int preferredFormat = -1) const; QFormatRange getLastOverlay(int start = 0, int end = -1, int preferredFormat = -1) const; diff --git a/src/syntaxcheck.cpp b/src/syntaxcheck.cpp index 63bf11347..31ac1af5a 100644 --- a/src/syntaxcheck.cpp +++ b/src/syntaxcheck.cpp @@ -113,6 +113,7 @@ void SyntaxCheck::run() speller=newSpeller; mReplacementList=newReplacementList; mFormatList=newFormatList; + m_nonTextGrammarFormats=m_newNonTextGrammarFormats; } mLtxCommandLock.unlock(); } @@ -151,14 +152,26 @@ void SyntaxCheck::run() newLine.dlh->lockForWrite(); if (newLine.ticket == newLine.dlh->getCurrentTicket()) { // discard results if text has been changed meanwhile newLine.dlh->setCookie(QDocumentLine::LEXER_COOKIE,QVariant::fromValue(tl)); + QListgrammarOverlays=newLine.dlh->getOverlaysNoLock(m_nonTextGrammarFormats); foreach (const Error &elem, newRanges){ if(!mSyntaxChecking && (elem.type!=ERR_spelling) && (elem.type!=ERR_highlight) ){ // skip all syntax errors continue; } - int fmt= elem.type == ERR_spelling ? SpellerUtility::spellcheckErrorFormat : syntaxErrorFormat; - fmt= elem.type == ERR_highlight ? elem.format : fmt; + int fmt= (elem.type == ERR_spelling) ? SpellerUtility::spellcheckErrorFormat : syntaxErrorFormat; + fmt= (elem.type == ERR_highlight) ? elem.format : fmt; newLine.dlh->addOverlayNoLock(QFormatRange(elem.range.first, elem.range.second, fmt)); + // for ERR_highlight, remove grammarErrors + if(m_hideNonTextGrammarErrors && elem.type==ERR_highlight){ + for(int i = 0; i=elem.range.first && range.offset<=elem.range.second){ + newLine.dlh->removeOverlayNoLock(range); + grammarOverlays.removeAt(i); + --i; + } + } + } } // add comment hightlight if present if(commentStart.first>=0){ @@ -291,6 +304,25 @@ void SyntaxCheck::enableSyntaxCheck(const bool enable){ if (stopped) return; mSyntaxChecking=enable; } +/*! \brief hide non text spelling errors + * \param hide + */ +void SyntaxCheck::setHideNonTextGrammarErrors(const bool hide) +{ + m_hideNonTextGrammarErrors=hide; +} +/*! + * \brief SyntaxCheck::setNonTextGrammarFormats + * \param formats + */ +void SyntaxCheck::setNonTextGrammarFormats(const QList formats) +{ + if (stopped) return; + mLtxCommandLock.lock(); + newLtxCommandsAvailable = true; + m_newNonTextGrammarFormats=formats; + mLtxCommandLock.unlock(); +} /*! * \brief set character/text replacementList for spell checking * \param replacementList Map for characater/text replacement prior to spellchecking words. E.g. "u -> ΓΌ when german is activated diff --git a/src/syntaxcheck.h b/src/syntaxcheck.h index c12a135b2..764e42588 100644 --- a/src/syntaxcheck.h +++ b/src/syntaxcheck.h @@ -117,6 +117,8 @@ class SyntaxCheck : public SafeThread void setReplacementList(QMap replacementList); void setFormats(QMap formatList); void enableSyntaxCheck(const bool enable); + void setHideNonTextGrammarErrors(const bool hide); + void setNonTextGrammarFormats(const QList formats); void markUnclosedEnv(Environment env); @@ -135,6 +137,8 @@ class SyntaxCheck : public SafeThread bool stopped; bool mSyntaxChecking; //! show/hide syntax errors int syntaxErrorFormat; + bool m_hideNonTextGrammarErrors=true; + QList m_nonTextGrammarFormats,m_newNonTextGrammarFormats; QSharedPointer ltxCommands; QSharedPointer newLtxCommands;