Przeglądaj źródła

[add] page up/down hotkey
[add] synchonized collapse / expand

B Thibault 9 lat temu
rodzic
commit
70ef7dbe7c
3 zmienionych plików z 54 dodań i 22 usunięć
  1. 2 0
      include/curseSplitOutput.hh
  2. 38 22
      src/curseSplitOutput.cpp
  3. 14 0
      test/testDiffSubAdd.6.json

+ 2 - 0
include/curseSplitOutput.hh

@@ -84,6 +84,8 @@ class CurseSplitOutput: public CurseOutput
         inputResult nextResult();
         inputResult changeWindow(char, bool);
 
+        void setSelection(const JSonElement *);
+
         void computeDiff();
         std::deque<t_subWindow> subWindows;
 

+ 38 - 22
src/curseSplitOutput.cpp

@@ -83,12 +83,21 @@ void CurseSplitOutput::computeDiff()
 
 inputResult CurseSplitOutput::selectUp()
 {
-    size_t i =0;
-    const JSonElement *newSelection = subWindows.at(selectedWin).select_up;
+    setSelection(subWindows.at(selectedWin).select_up);
+    return inputResult::redraw;
+}
+
+inputResult CurseSplitOutput::selectDown()
+{
+    const JSonElement *newSelection = subWindows.at(selectedWin).select_down;
+    size_t i = 0;
 
-    for (t_subWindow &w : subWindows) {
+    for (t_subWindow &w : subWindows)
+    {
+        if (w.selectIsLast)
+            w.scrollTop += 2;
         if (i == selectedWin)
-            w.selection = w.lastSelection = w.select_up;
+            w.selection = w.lastSelection = newSelection;
         else
         {
             w.selection = diffMatrice->getEquivalence(newSelection);
@@ -100,47 +109,43 @@ inputResult CurseSplitOutput::selectUp()
     return inputResult::redraw;
 }
 
-inputResult CurseSplitOutput::selectDown()
+void CurseSplitOutput::setSelection(const JSonElement *selection)
 {
-    const JSonElement *newSelection = subWindows.at(selectedWin).select_down;
-    size_t i = 0;
+    size_t i =0;
 
     for (t_subWindow &w : subWindows)
     {
-        if (w.selectIsLast)
-            w.scrollTop += 2;
         if (i == selectedWin)
-            w.selection = w.lastSelection = newSelection;
+            w.selection = w.lastSelection = selection;
         else
         {
-            w.selection = diffMatrice->getEquivalence(newSelection);
+            w.selection = diffMatrice->getEquivalence(selection);
             if (w.selection)
                 w.lastSelection = w.selection;
         }
         ++i;
     }
-    return inputResult::redraw;
 }
 
 inputResult CurseSplitOutput::selectPUp()
 {
     const JSonElement *_selection = subWindows.at(selectedWin).selection;
-    const JSonElement *brother = _selection->findPrev();
+    const JSonElement *nextSelection = _selection->findPrev();
 
-    if (brother == nullptr)
+    if (nextSelection == nullptr)
     {
         const JSonElement *parent = _selection->getParent();
+
         if (parent && dynamic_cast<const JSonContainer*>(parent))
         {
-            subWindows.at(selectedWin).selection = _selection = parent;
+            nextSelection = _selection = parent;
             if (_selection->getParent() && dynamic_cast<const JSonObjectEntry*> (_selection->getParent()))
-                subWindows.at(selectedWin).selection = _selection->getParent();
+                nextSelection = _selection->getParent();
         }
         else
             return inputResult::nextInput;
     }
-    else
-        subWindows.at(selectedWin).selection = brother;
+    setSelection(nextSelection);
     return inputResult::redraw;
 }
 
@@ -150,7 +155,7 @@ inputResult CurseSplitOutput::selectPDown()
 
     if (brother)
     {
-        subWindows.at(selectedWin).selection = brother;
+        setSelection(brother);
         return inputResult::redraw;
     }
     return inputResult::nextInput;
@@ -166,10 +171,14 @@ inputResult CurseSplitOutput::expandSelection()
         return inputResult::nextInput;
 
     if (collapsed.erase((const JSonContainer *)_selection))
+    {
+        _selection = diffMatrice->getEquivalence(_selection);
+        collapsed.erase((const JSonContainer *)_selection);
         return inputResult::redraw;
+    }
     if (!((const JSonContainer*)_selection)->size())
         return inputResult::nextInput;
-    subWindows.at(selectedWin).selection = subWindows.at(selectedWin).select_down;
+    selectDown();
     return inputResult::redraw;
 }
 
@@ -183,12 +192,19 @@ inputResult CurseSplitOutput::collapseSelection()
             || collapsed.find((const JSonContainer *)_selection) != collapsed.end()
             || (dynamic_cast<const JSonContainer*>(_selection) && ((const JSonContainer*)_selection)->size() == 0)))
     {
-        subWindows.at(selectedWin).selection = _selection = subWindows.at(selectedWin).selection->getParent();
+        _selection = subWindows.at(selectedWin).selection->getParent();
         if (_selection->getParent() && dynamic_cast<const JSonObjectEntry*>(_selection->getParent()))
-            subWindows.at(selectedWin).selection = _selection->getParent();
+            setSelection(_selection->getParent());
+        else
+            setSelection(_selection);
     }
     else
+    {
         collapsed.insert((const JSonContainer *)_selection);
+        _selection = diffMatrice->getEquivalence(_selection);
+        if (_selection)
+            collapsed.insert((const JSonContainer *)_selection);
+    }
     return inputResult::redraw;
 }
 

+ 14 - 0
test/testDiffSubAdd.6.json

@@ -0,0 +1,14 @@
+[
+    1,
+    [
+        1,
+        6,
+        3
+    ],
+    [
+        1,
+        6,
+        3
+    ],
+    3
+]