Prechádzať zdrojové kódy

[wip][add] Untested on all command synchronized selection

B Thibault 9 rokov pred
rodič
commit
6a53d745aa
3 zmenil súbory, kde vykonal 69 pridanie a 26 odobranie
  1. 1 1
      include/curseSplitOutput.hh
  2. 60 21
      src/curseSplitOutput.cpp
  3. 8 4
      src/levenshtein.cpp

+ 1 - 1
include/curseSplitOutput.hh

@@ -12,7 +12,7 @@ typedef struct
 {
     std::string fileName;
     JSonElement *root;
-    const JSonElement *selection, *select_up, *select_down;
+    const JSonElement *selection, *lastSelection, *select_up, *select_down;
     WINDOW *innerWin, *outerWin;
     std::list<const JSonElement*> searchResults;
     unsigned int scrollTop;

+ 60 - 21
src/curseSplitOutput.cpp

@@ -52,7 +52,7 @@ void CurseSplitOutput::run(const std::deque<std::string> &inputName, const std::
         t_subWindow subwin;
 
         subwin.fileName = inputName.at(i);
-        subwin.selection = subwin.root = roots.at(i);
+        subwin.selection = subwin.lastSelection = subwin.root = roots.at(i);
         subwin.select_up = subwin.select_down = nullptr;
         subwin.innerWin = subwin.outerWin = nullptr;
         subwin.scrollTop = 0;
@@ -83,20 +83,42 @@ void CurseSplitOutput::computeDiff()
 
 inputResult CurseSplitOutput::selectUp()
 {
-    subWindows.at(selectedWin).selection = subWindows.at(selectedWin).select_up;
+    size_t i =0;
+    const JSonElement *newSelection = subWindows.at(selectedWin).select_up;
+
+    for (t_subWindow &w : subWindows) {
+        if (i == selectedWin)
+            w.selection = w.lastSelection = w.select_up;
+        else
+        {
+            w.selection = diffMatrice->getEquivalence(newSelection);
+            if (w.selection)
+                w.lastSelection = w.selection;
+        }
+        ++i;
+    }
     return inputResult::redraw;
 }
 
 inputResult CurseSplitOutput::selectDown()
 {
-    t_subWindow &w = subWindows.at(selectedWin);
+    const JSonElement *newSelection = subWindows.at(selectedWin).select_down;
+    size_t i = 0;
 
-    if (w.selectIsLast)
-        w.scrollTop += 2;
-    else if (w.selection != w.select_down)
-        w.selection = w.select_down;
-    else
-        return inputResult::nextInput;
+    for (t_subWindow &w : subWindows)
+    {
+        if (w.selectIsLast)
+            w.scrollTop += 2;
+        if (i == selectedWin)
+            w.selection = w.lastSelection = newSelection;
+        else
+        {
+            w.selection = diffMatrice->getEquivalence(newSelection);
+            if (w.selection)
+                w.lastSelection = w.selection;
+        }
+        ++i;
+    }
     return inputResult::redraw;
 }
 
@@ -198,6 +220,23 @@ inputResult CurseSplitOutput::changeWindow(char d, bool c)
     if ((selectedWin +d < 0 || selectedWin +d >= nbInputs) && !c)
         return inputResult::nextInput;
     selectedWin = (selectedWin +d) % nbInputs;
+    t_subWindow &w = subWindows.at(selectedWin);
+    if (!w.selection)
+    {
+        size_t i =0;
+        for (t_subWindow &it : subWindows)
+        {
+            if (i == selectedWin)
+                it.selection = it.lastSelection;
+            else
+            {
+                it.selection = diffMatrice->getEquivalence(w.lastSelection);
+                if (it.selection)
+                    it.lastSelection = it.selection;
+            }
+            ++i;
+        }
+    }
     return inputResult::redrawAll;
 }
 
@@ -207,7 +246,7 @@ void CurseSplitOutput::checkSelection(const JSonElement *item)
 
     if (!w.selectFound)
     {
-        if (w.selection == item)
+        if (w.lastSelection == item)
         {
             if (w.cursor.second < w.scrollTop) //Selection is above vp, move scroll pos to selection and start drawing
                 w.scrollTop = w.cursor.second;
@@ -221,7 +260,7 @@ void CurseSplitOutput::checkSelection(const JSonElement *item)
         const JSonElement *parent = item->getParent();
         if (!dynamic_cast<const JSonContainer*>(item) &&
                 parent &&
-                w.selection != parent &&
+                w.lastSelection != parent &&
                 dynamic_cast<const JSonObjectEntry*>(parent))
             item = parent;
         if (!parent || !dynamic_cast<const JSonObjectEntry*>(parent))
@@ -234,7 +273,7 @@ bool CurseSplitOutput::jumpToNextSearch(const JSonElement *current, bool &select
     const JSonContainer *container = dynamic_cast<const JSonContainer *> (current);
     const JSonObjectEntry *objEntry = dynamic_cast<const JSonObjectEntry *> (current);
 
-    if (subWindows.at(selectedWin).selection == current)
+    if (subWindows.at(selectedWin).lastSelection == current)
         selectFound = true;
     if (container)
     {
@@ -252,7 +291,7 @@ bool CurseSplitOutput::jumpToNextSearch(const JSonElement *current, bool &select
                 current != subWindows.at(selectedWin).selection &&
                 selectFound)
         {
-            subWindows.at(selectedWin).selection = current;
+            subWindows.at(selectedWin).lastSelection = current;
             return true;
         }
         if (objEntry)
@@ -304,7 +343,7 @@ bool CurseSplitOutput::jumpToNextSearch()
 
     if (!res)
     {
-        subWindows.at(selectedWin).selection = *(subWindows.at(selectedWin).searchResults.cbegin());
+        subWindows.at(selectedWin).lastSelection = *(subWindows.at(selectedWin).searchResults.cbegin());
         unfold(subWindows.at(selectedWin).selection);
         CurseOutput::redraw("Search hit BOTTOM, continuing at TOP");
         return false;
@@ -373,12 +412,12 @@ bool CurseSplitOutput::redraw()
                             w.select_down = *(pselect->cbegin());
                         else
                         {
-                            const JSonElement *next = w.selection->findNext();
-                            w.select_down = next ? next : w.selection;
+                            const JSonElement *next = w.lastSelection->findNext();
+                            w.select_down = next ? next : w.lastSelection;
                         }
                     }
                     if (!w.select_up)
-                        w.select_up = subWindows.at(workingWin).selection;
+                        w.select_up = subWindows.at(workingWin).lastSelection;
                     writingDone &= ~(1 << workingWin);
                 }
             }
@@ -476,17 +515,17 @@ bool CurseSplitOutput::writeContent(const t_Cursor &maxSize, std::list<JSonEleme
             {
                 if (!writeKey(key, ent->lazystrlen(), maxSize, getFlag(ent)))
                     break;
-                const JSonElement *saveSelection = w.selection;
+                const JSonElement *saveSelection = w.lastSelection;
                 if (saveSelection == ent)
-                    w.selection = **ent;
+                    w.selection = w.lastSelection = **ent;
                 w.cursor.first += INDENT_LEVEL /2;
                 if (!redraw(maxSize, **ent))
                 {
-                    w.selection = saveSelection;
+                    w.selection = w.lastSelection = saveSelection;
                     w.cursor.first -= INDENT_LEVEL /2;
                     return false;
                 }
-                w.selection = saveSelection;
+                w.selection = w.lastSelection = saveSelection;
                 w.cursor.first -= INDENT_LEVEL /2;
             }
         }

+ 8 - 4
src/levenshtein.cpp

@@ -124,10 +124,14 @@ bool LevenshteinMatrice::areSimilar() const
 
 const JSonElement *LevenshteinMatrice::getEquivalence(const JSonElement *e) const
 {
-    std::map<const JSonElement *, const JSonElement *>::const_iterator it = equivalences.find(e);
-    if (it == equivalences.cend())
-        return nullptr;
-    return (*it).second;
+    for (std::pair<const JSonElement *, const JSonElement *> it : equivalences)
+    {
+        if (it.first == e)
+            return it.second;
+        if (it.second == e)
+            return it.first;
+    }
+    return nullptr;
 }
 
 std::map<const JSonElement*, const JSonElement *> LevenshteinMatrice::getEquivalences() const