diff --git a/src/plugins/bazaar/annotationhighlighter.cpp b/src/plugins/bazaar/annotationhighlighter.cpp index 6ea7fd7108d..ed1d7b09801 100644 --- a/src/plugins/bazaar/annotationhighlighter.cpp +++ b/src/plugins/bazaar/annotationhighlighter.cpp @@ -40,7 +40,7 @@ BazaarAnnotationHighlighter::BazaarAnnotationHighlighter(const ChangeNumbers &ch const QColor &bg, QTextDocument *document) : VcsBase::BaseAnnotationHighlighter(changeNumbers, bg, document), - m_changeset(QLatin1String(Constants::CHANGESET_ID)) + m_changeset(QLatin1String(Constants::ANNOTATE_CHANGESET_ID)) { } diff --git a/src/plugins/bazaar/bazaareditor.cpp b/src/plugins/bazaar/bazaareditor.cpp index b1221522442..2a52248c826 100644 --- a/src/plugins/bazaar/bazaareditor.cpp +++ b/src/plugins/bazaar/bazaareditor.cpp @@ -55,6 +55,7 @@ using namespace Bazaar; BazaarEditor::BazaarEditor(const VcsBase::VcsBaseEditorParameters *type, QWidget *parent) : VcsBase::VcsBaseEditorWidget(type, parent), + m_changesetId(QLatin1String(Constants::CHANGESET_ID)), m_exactChangesetId(QLatin1String(Constants::CHANGESET_ID_EXACT)), m_diffFileId(QLatin1String("^=== [a-z]+ [a-z]+ '(.*)'\\s*")) { @@ -86,12 +87,30 @@ QSet BazaarEditor::annotationChanges() const QString BazaarEditor::changeUnderCursor(const QTextCursor &cursorIn) const { + // The test is done in two steps: first we check if the line contains a + // changesetId. Then we check if the cursor is over the changesetId itself + // and not over "revno" or another part of the line. + // The two steps are necessary because matching only for the changesetId + // leads to many false-positives (a regex like "[0-9]+" matches a lot of text). + const int cursorCol = cursorIn.columnNumber(); QTextCursor cursor = cursorIn; - cursor.select(QTextCursor::WordUnderCursor); + cursor.select(QTextCursor::LineUnderCursor); if (cursor.hasSelection()) { - const QString change = cursor.selectedText(); - if (m_exactChangesetId.exactMatch(change)) - return change; + const QString line = cursor.selectedText(); + const int start = m_changesetId.indexIn(line); + if (start > -1) { + const QString match = m_changesetId.cap(0); + const int stop = start + match.length(); + if (start <= cursorCol && cursorCol <= stop) { + cursor = cursorIn; + cursor.select(QTextCursor::WordUnderCursor); + if (cursor.hasSelection()) { + const QString change = cursor.selectedText(); + if (m_exactChangesetId.exactMatch(change)) + return change; + } + } + } } return QString(); } diff --git a/src/plugins/bazaar/bazaareditor.h b/src/plugins/bazaar/bazaareditor.h index 0c9198509fa..4538c70043e 100644 --- a/src/plugins/bazaar/bazaareditor.h +++ b/src/plugins/bazaar/bazaareditor.h @@ -54,6 +54,7 @@ private: virtual VcsBase::BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet &changes, const QColor &bg) const; virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const; + const QRegExp m_changesetId; const QRegExp m_exactChangesetId; const QRegExp m_diffFileId; }; diff --git a/src/plugins/bazaar/constants.h b/src/plugins/bazaar/constants.h index ccccc2e1fe6..12560b17778 100644 --- a/src/plugins/bazaar/constants.h +++ b/src/plugins/bazaar/constants.h @@ -41,8 +41,13 @@ const char BAZAARREPO[] = ".bzr"; const char BAZAARDEFAULT[] = "bzr"; // Changeset identifiers -const char CHANGESET_ID[] = "([0-9]+)"; // match and capture -const char CHANGESET_ID_EXACT[] = "[0-9]+"; // match +const char CHANGESET_ID[] = "^(" + "revno: [.0-9]+" // detailed + "| +[.0-9]+" // short + "|[.0-9]+: " // line + ")"; +const char CHANGESET_ID_EXACT[] = "([.0-9]+)"; +const char ANNOTATE_CHANGESET_ID[] = "([.0-9]+)"; // Base editor parameters const char COMMANDLOG_ID[] = "Bazaar Command Log Editor";