]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added logic to expand the tag view up to a maximum size based on contents.
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Nov 2016 01:45:45 +0000 (20:45 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Nov 2016 01:45:45 +0000 (20:45 -0500)
inc/edit.h
libedit/view.c
xedit.c

index 2e1cc5a38d59366bb5334feb9761a778dcbd1c58..0d6b3f3d6e0c106ac54848f4627b807337a904a4 100644 (file)
@@ -146,6 +146,7 @@ typedef struct {
 } View;
 
 void view_init(View* view, char* file);
+size_t view_limitrows(View* view, size_t maxrows, size_t ncols);
 void view_resize(View* view, size_t nrows, size_t ncols);
 void view_update(View* view, size_t* csrx, size_t* csry);
 Row* view_getrow(View* view, size_t row);
index e30fbf50bc40139e9423964c9a752f0354a70b26..d1f8eca0d38bbd3681f1923aa302ae1509287457 100644 (file)
@@ -159,6 +159,22 @@ void view_init(View* view, char* file) {
         buf_load(&(view->buffer), file);
 }
 
+size_t view_limitrows(View* view, size_t maxrows, size_t ncols) {
+    size_t nrows = 0;
+    size_t pos = 0;
+    while (nrows < maxrows && pos < buf_end(&(view->buffer))) {
+        for (size_t x = 0; x < ncols;) {
+            Rune r = buf_get(&(view->buffer), pos++);
+            x += runewidth(x, r);
+            if (buf_iseol(&(view->buffer), pos)) {
+                nrows++;
+                break;
+            }
+        }
+    }
+    return (!nrows ? 1 : nrows);
+}
+
 void view_resize(View* view, size_t nrows, size_t ncols) {
     size_t off = 0;
     if (view->nrows == nrows && view->ncols == ncols)  return;
diff --git a/xedit.c b/xedit.c
index 3fec61d5cb8542aaba1b3b3b669749f8d0872a40..5c75c7076b0fb58fb280b739782e5cca228ab216 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -377,11 +377,12 @@ static void layout(int width, int height) {
         Regions[i].height = fheight;
     }
     /* Place the tag region relative to status */
-    Regions[TAGS].y      = 5 + Regions[STATUS].y + Regions[STATUS].height;
-    size_t maxtagrows    = ((height - Regions[TAGS].y - 5) / 4) / fheight;
-    size_t tagrows       = (TagWinExpanded ? maxtagrows : 1);
+    Regions[TAGS].y = 5 + Regions[STATUS].y + Regions[STATUS].height;
+    size_t maxtagrows = ((height - Regions[TAGS].y - 5) / 4) / fheight;
+    size_t tagcols    = Regions[TAGS].width / fwidth;
+    size_t tagrows    = view_limitrows(getview(TAGS), maxtagrows, tagcols);
     Regions[TAGS].height = tagrows * fheight;
-    view_resize(getview(TAGS), tagrows, Regions[TAGS].width / fwidth);
+    view_resize(getview(TAGS), tagrows, tagcols);
     /* Place the edit region relative to status */
     Regions[EDIT].y      = 5 + Regions[TAGS].y + Regions[TAGS].height;
     Regions[EDIT].height = (height - Regions[EDIT].y - 5);