Browse Source

[quickfix] scroll issue (indent)

isundil 9 năm trước cách đây
mục cha
commit
869efde666
3 tập tin đã thay đổi với 83 bổ sung31 xóa
  1. 43 31
      src/curseOutput.cpp
  2. 20 0
      test/bigarray.json
  3. 20 0
      test/bigobj.json

+ 43 - 31
src/curseOutput.cpp

@@ -125,7 +125,6 @@ bool CurseOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<un
     else
         memcpy(childDelimiter, "[]", sizeof(*childDelimiter) * 2);
 
-    cursor.first += INDENT_LEVEL /2;
     if (collapsed.find((const JSonContainer *)item) != collapsed.end())
     {
         std::string ss;
@@ -134,14 +133,13 @@ bool CurseOutput::writeContainer(std::pair<int, int> &cursor, const std::pair<un
     }
     else
     {
-        cursor.second += write(cursor.first, cursor.second, childDelimiter[0], maxSize.first, selection == item);
+        cursor.second += write(cursor.first, cursor.second, childDelimiter[0], maxSize.first, getFlag(item));
         if (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1)
                 return false;
         if (!writeContent(cursor, maxSize, (const std::list<JSonElement *> *)item))
             return false;
-        cursor.second += write(cursor.first, cursor.second, childDelimiter[1], maxSize.first, selection == item);
+        cursor.second += write(cursor.first, cursor.second, childDelimiter[1], maxSize.first, getFlag(item));
     }
-    cursor.first -= INDENT_LEVEL /2;
     return (cursor.second - topleft < 0 || (unsigned)(cursor.second - topleft) <= maxSize.second -1);
 }
 
@@ -149,9 +147,12 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
 {
     const JSonContainer *item = (const JSonContainer *)_item;
     bool containerIsObject = (dynamic_cast<const JSonObject *>(item) != nullptr);
-    cursor.first += INDENT_LEVEL /2;
+    bool result = true;
+    cursor.first += INDENT_LEVEL;
+
     for (std::list<JSonElement *>::const_iterator i = item->cbegin(); i != item->cend(); ++i)
     {
+        result = false;
         if (containerIsObject)
         {
             JSonObjectEntry *ent = (JSonObjectEntry*) *i;
@@ -161,38 +162,40 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
             if (isContainer && collapsed.find((const JSonContainer*)(**ent)) != collapsed.cend())
             {
                 if (dynamic_cast<const JSonObject *>(**ent))
-                    writeKey(key, "{ ... }", cursor, maxSize, getFlag(ent));
-                else
-                    writeKey(key, "[ ... ]", cursor, maxSize, getFlag(ent));
-                if (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1)
-                        return false;
+                {
+                    if (!writeKey(key, "{ ... }", cursor, maxSize, getFlag(ent)))
+                        break;
+                }
+                else if (!writeKey(key, "[ ... ]", cursor, maxSize, getFlag(ent)) || (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1))
+                    break;
             }
             else if (!isContainer)
             {
-                writeKey(key, ((**ent)->stringify()), cursor, maxSize, getFlag(ent));
-                if (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1)
-                        return false;
+                if (!writeKey(key, ((**ent)->stringify()), cursor, maxSize, getFlag(ent)) || (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1))
+                    break;
             }
             else if (((JSonContainer*)(**ent))->size() == 0)
             {
                 if (dynamic_cast<const JSonObject *>(**ent) )
-                    writeKey(key, "{ }", cursor, maxSize, getFlag(ent));
-                else
-                    writeKey(key, "[ ]", cursor, maxSize, getFlag(ent));
-                if (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1)
-                        return false;
+                {
+                    if (!writeKey(key, "{ }", cursor, maxSize, getFlag(ent)))
+                        break;
+                }
+                else if (!writeKey(key, "[ ]", cursor, maxSize, getFlag(ent)) || (cursor.second - topleft > 0 && (unsigned)(cursor.second - topleft) > maxSize.second -1))
+                    break;
             }
             else
             {
                 if (!writeKey(key, cursor, maxSize, selection == ent))
-                    return false;
-                cursor.first -= INDENT_LEVEL /2;
+                    break;
                 const JSonElement *saveSelection = selection;
                 if (selection == ent)
                     selection = **ent;
+                cursor.first += INDENT_LEVEL /2;
                 if (!redraw(cursor, maxSize, **ent, (const JSonContainer *)item))
                 {
                     selection = saveSelection;
+                    cursor.first -= INDENT_LEVEL /2;
                     return false;
                 }
                 selection = saveSelection;
@@ -202,35 +205,44 @@ bool CurseOutput::writeContent(std::pair<int, int> &cursor, const std::pair<unsi
         else
         {
             if (!redraw(cursor, maxSize, *i, (const JSonContainer *)item))
-                return false;
+                break;
         }
+        result = true;
     }
-    cursor.first -= INDENT_LEVEL /2;
-    return true;
+    cursor.first -= INDENT_LEVEL;
+    //result will be false if for loop break'd at some time, true otherwise
+    return result;
 }
 
 bool CurseOutput::writeKey(const std::string &key, const std::string &after, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags)
 {
     if (cursor.second - topleft < 0)
-        return 1;
-    writeKey(key, cursor, maxSize, flags, after.size());
+    {
+        cursor.second++;
+        return true;
+    }
+    if (!writeKey(key, cursor, maxSize, flags, after.size()))
+        return false;
+    //TODO check result if write goes to new line
     write(after.c_str(), maxSize.first, flags);
-    cursor.first -= INDENT_LEVEL;
-    return (cursor.second - topleft < 0 || (unsigned)(cursor.second - topleft) <= maxSize.second -1);
+    return true;
 }
 
 bool CurseOutput::writeKey(const std::string &key, std::pair<int, int> &cursor, const std::pair<unsigned int, unsigned int> &maxSize, OutputFlag flags, unsigned int extraLen)
 {
     if (cursor.second - topleft < 0)
-        return 1;
+    {
+        cursor.second++;
+        return true;
+    }
     char oldType = flags.type();
     flags.type(OutputFlag::TYPE_OBJKEY);
-    cursor.second += write(cursor.first, cursor.second, key, maxSize.first -extraLen -2, flags);
+    write(cursor.first, cursor.second, key, maxSize.first -extraLen -2, flags);
+    cursor.second ++;
     flags.type(OutputFlag::TYPE_OBJ);
     write(": ", maxSize.first, flags);
     flags.type(oldType);
-    cursor.first += INDENT_LEVEL;
-    return (cursor.second - topleft < 0 || (unsigned)(cursor.second - topleft) <= maxSize.second -1);
+    return (cursor.second - topleft < 0 || (unsigned)(cursor.second - topleft) <= maxSize.second);
 }
 
 unsigned int CurseOutput::write(const int &x, const int &y, const JSonElement *item, unsigned int maxWidth, OutputFlag flags)

+ 20 - 0
test/bigarray.json

@@ -0,0 +1,20 @@
+[
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c",
+    "a", "b", "c"
+]

+ 20 - 0
test/bigobj.json

@@ -0,0 +1,20 @@
+[[[{
+    "a2":42, "b2":43, "c2":[true,false,true,"coucou"],
+    "a3":[true,false,true,"coucou"], "b3":[true,false,true,"coucou"], "c3":[true,false,true,"coucou"],
+    "a4":[true,false,true,"coucou"], "b4":[true,false,true,"coucou"], "c4":[true,false,true,"coucou"],
+    "a5":[true,false,true,"coucou"], "b5":[true,false,true,"coucou"], "c5":[true,false,true,"coucou"],
+    "a6":[true,false,true,"coucou"], "b6":[true,false,true,"coucou"], "c6":[true,false,true,"coucou"],
+    "a7":[true,false,true,"coucou"], "b7":[true,false,true,"coucou"], "c7":[true,false,true,"coucou"],
+    "a8":[true,false,true,"coucou"], "b8":[true,false,true,"coucou"], "c8":[true,false,true,"coucou"],
+    "a9":[true,false,true,"coucou"], "b9":[true,false,true,"coucou"], "c9":[true,false,true,"coucou"],
+    "a10":[true,false,true,"coucou"], "b10":[true,false,true,"coucou"], "c10":[true,false,true,"coucou"],
+    "a11":[true,false,true,"coucou"], "b11":[true,false,true,"coucou"], "c11":[true,false,true,"coucou"],
+    "a12":[true,false,true,"coucou"], "b12":[true,false,true,"coucou"], "c12":false,
+    "a13":[true,false,true,"coucou"], "b13":[true,false,true,"coucou"], "c13":[true,false,true,"coucou"],
+    "a14":[true,false,true,"coucou"], "b14":[true,false,true,"coucou"], "c14":[true,false,true,"coucou"],
+    "a15":[true,false,true,"coucou"], "b15":[true,false,true,"coucou"], "c15":[true,false,true,"coucou"],
+    "a16":[true,false,true,"coucou"], "b16":[true,false,true,"coucou"], "c16":[true,false,true,"coucou"],
+    "a17":[true,false,true,"coucou"], "b17":[true,false,true,"coucou"], "c17":[true,false,true,"coucou"],
+    "a18":[true,false,true,"coucou"], "b18":[true,false,true,"coucou"], "c18":[true,false,true,"coucou"],
+    "a19":[true,false,true,"coucou"], "b19":[true,false,true,"coucou"], "c19":[true,false,true,"coucou"]
+}]]]