Browse Source

judge if equal in VOutline when updating curHeader

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 years ago
parent
commit
810d2f02f4
3 changed files with 15 additions and 2 deletions
  1. 0 1
      src/vedittab.cpp
  2. 7 1
      src/voutline.cpp
  3. 8 0
      src/vtoc.h

+ 0 - 1
src/vedittab.cpp

@@ -241,7 +241,6 @@ void VEditTab::handleFocusChanged(QWidget *old, QWidget *now)
 
 void VEditTab::updateTocFromHtml(const QString &tocHtml)
 {
-    qDebug() << tocHtml;
     tableOfContent.type = VHeaderType::Anchor;
     QVector<VHeader> &headers = tableOfContent.headers;
     headers.clear();

+ 7 - 1
src/voutline.cpp

@@ -81,11 +81,17 @@ void VOutline::handleItemClicked(QTreeWidgetItem *item, int column)
     QString anchor = itemJson["anchor"].toString();
     int lineNumber = itemJson["line_number"].toInt();
     qDebug() << "click anchor" << anchor << lineNumber;
-    emit outlineItemActivated(VAnchor(outline.filePath, anchor, lineNumber));
+    curHeader.filePath = outline.filePath;
+    curHeader.anchor = anchor;
+    curHeader.lineNumber = lineNumber;
+    emit outlineItemActivated(curHeader);
 }
 
 void VOutline::updateCurHeader(const VAnchor &anchor)
 {
+    if (anchor == curHeader) {
+        return;
+    }
     curHeader = anchor;
     if (outline.type == VHeaderType::Anchor) {
         selectAnchor(anchor.anchor);

+ 8 - 0
src/vtoc.h

@@ -26,11 +26,19 @@ struct VAnchor
     VAnchor() : lineNumber(-1) {}
     VAnchor(const QString filePath, const QString &anchor, int lineNumber)
         : filePath(filePath), anchor(anchor), lineNumber(lineNumber) {}
+    inline bool operator ==(const VAnchor &p_anchor) const;
     QString filePath;
     QString anchor;
     int lineNumber;
 };
 
+inline bool VAnchor::operator ==(const VAnchor &p_anchor) const
+{
+    return p_anchor.filePath == filePath &&
+           p_anchor.anchor == anchor &&
+           p_anchor.lineNumber == lineNumber;
+}
+
 class VToc
 {
 public: