]> git.neil.brown.name Git - edlib.git/commitdiff
Move the authoritative 'point' out of the pane and into the doc_data.
authorNeilBrown <neil@brown.name>
Sun, 29 Nov 2015 21:50:58 +0000 (08:50 +1100)
committerNeilBrown <neil@brown.name>
Tue, 1 Dec 2015 06:20:11 +0000 (17:20 +1100)
This seems a more sensible location.
The point still exists in the pane as it is very useful, but this is
now just a 'borrowed' pointer.

This required changing doc_attr to only examine a single pane.
Probably makes sense for now.

Next patch will make changes to how points in panes are managed.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-keymap.c
core-pane.c
core.h
doc-text.c

index 85600fb64d36aaa9a6dc0d3b071f4957a4975d68..bd5a16ddf6de126d0ee3fd40fb3d61dadaa60098 100644 (file)
@@ -263,7 +263,7 @@ DEF_CMD(doc_file)
        int rpt = RPT_NUM(ci);
 
        if (ci->mark == NULL)
-               ci->mark = ci->home->point;
+               ci->mark = dd->point;
        while (rpt > 0 && ch != WEOF) {
                while ((ch = mark_next(d, ci->mark)) != WEOF)
                        ;
@@ -354,8 +354,10 @@ DEF_CMD(doc_handle)
        if (strcmp(ci->key, "Clone") == 0) {
                struct pane *p = doc_attach(ci->focus, dd->doc);
                struct pane *c = pane_child(ci->home);
+               struct doc_data *dd2 = p->data;
 
-               p->point = point_dup(ci->home->point);
+               dd2->point = point_dup(dd->point);
+               p->pointer = dd2->point;
                if (c)
                        pane_clone(c, p);
                return 1;
@@ -363,20 +365,19 @@ DEF_CMD(doc_handle)
 
        if (strcmp(ci->key, "Close") == 0) {
                doc_del_view(ci->home, &dd->notify);
-               if (ci->home->point)
-                       mark_free(ci->home->point);
-               ci->home->point = NULL;
+               if (dd->point)
+                       mark_free(dd->point);
                free(dd);
                ci->home->data = NULL;
                return 1;
        }
 
        if (strcmp(ci->key, "doc:dup-point") == 0) {
-               struct mark *pt = ci->home->point;
+               struct mark *pt = dd->point;
                if (ci->mark && ci->mark->viewnum == MARK_POINT)
                        pt = ci->mark;
                ci->mark = NULL;
-               if (ci->home->point) {
+               if (pt) {
                        if (ci->extra == MARK_POINT)
                                ci->mark = point_dup(pt);
                        else if (ci->extra == MARK_UNGROUPED)
@@ -389,7 +390,7 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "Move-to") == 0) {
-               point_to_mark(ci->home->point, ci->mark);
+               point_to_mark(dd->point, ci->mark);
                return 1;
        }
 
@@ -427,8 +428,8 @@ DEF_CMD(doc_handle)
        if (strcmp(ci->key, "doc:vmark-get") == 0) {
                ci->mark = do_vmark_first(dd->doc, ci->numeric);
                ci->mark2 = do_vmark_last(dd->doc, ci->numeric);
-               if (ci->extra && ci->home->point)
-                       ci->mark2 = do_vmark_at_point(dd->doc, ci->home->point,
+               if (ci->extra && dd->point)
+                       ci->mark2 = do_vmark_at_point(dd->doc, dd->point,
                                                      ci->numeric);
                return 1;
        }
@@ -482,6 +483,7 @@ struct pane *doc_attach(struct pane *parent, struct doc *d)
                dd->notify = doc_notify;
                doc_add_view(p, &dd->notify, 0);
        }
+       dd->point = NULL;
        dd->pane = p;
        d->ed = pane2ed(parent);
        doc_promote(d);
@@ -546,7 +548,9 @@ struct pane *doc_attach_view(struct pane *parent, struct pane *doc, char *render
        struct doc_data *dd = doc->data;
        p = doc_attach(parent, dd->doc);
        if (p) {
-               p->point = point_new(dd->doc);
+               dd = p->data;
+               dd->point = point_new(dd->doc);
+               p->pointer = dd->point;
                p = pane_attach(p, "view", doc, NULL);
        }
        if (p)
@@ -737,7 +741,8 @@ DEF_CMD(docs_get_attr)
 DEF_CMD(docs_open)
 {
        struct pane *p = ci->home;
-       struct pane *dp = p->point->ref.p;
+       struct doc_data *dd = p->data;
+       struct pane *dp = dd->point->ref.p;
        struct pane *par = p->parent;
        char *renderer = NULL;
 
index cab542386f8e0e335e54e3485ef9baedcf20496f..060325efb18d4737e47fd3cdf448741f79a1ad56 100644 (file)
@@ -331,8 +331,8 @@ static int __key_handle_focus(struct cmd_info *ci, int savepoint)
        ci->y = -1;
        while (p->focus) {
                p = p->focus;
-               if (savepoint && p->point)
-                       ci->mark = p->point;
+               if (savepoint && p->pointer)
+                       ci->mark = p->pointer;
        }
        ci->focus = p;
        ci->comm = NULL;
@@ -372,8 +372,8 @@ static int __key_handle_xy(struct cmd_info *ci, int savepoint)
                x -= chld->x;
                y -= chld->y;
                p = chld;
-               if (savepoint && p->point)
-                       ci->mark = p->point;
+               if (savepoint && p->pointer)
+                       ci->mark = p->pointer;
        }
        ci->x = x;
        ci->y = y;
index 7f3173586cc808371a1ad61d5f0e30f039ea2249..970d5d5fd1b68620a356777d52cb17f71e50d88c 100644 (file)
@@ -50,7 +50,7 @@ void pane_init(struct pane *p, struct pane *par, struct list_head *here)
        p->handle = NULL;
        p->data = NULL;
        p->damaged = 0;
-       p->point = NULL;
+       p->pointer = NULL;
        p->attrs = 0;
 }
 
@@ -107,8 +107,8 @@ static void __pane_refresh(struct cmd_info *ci)
        if (p->focus == NULL)
                p->focus = list_first_entry_or_null(
                        &p->children, struct pane, siblings);
-       if (p->point)
-               ci2.mark = p->point;
+       if (p->pointer)
+               ci2.mark = p->pointer;
 
        damage |= p->damaged;
        if (!damage)
@@ -168,8 +168,6 @@ void pane_close(struct pane *p)
        }
        pane_damaged(p->parent, DAMAGED_SIZE);
        attr_free(&p->attrs);
-/* FIXME who destroys 'point'*/
-       ASSERT(p->point == NULL);
        free(p);
 }
 
@@ -264,9 +262,9 @@ void pane_subsume(struct pane *p, struct pane *parent)
        parent->data = p->data;
        p->data = data;
 
-       point = parent->point;
-       parent->point = p->point;
-       p->point = point;
+       point = parent->pointer;
+       parent->pointer = p->pointer;
+       p->pointer = point;
 }
 
 int pane_masked(struct pane *p, int x, int y, int z, int *w, int *h)
@@ -506,11 +504,9 @@ char *pane_attr_get(struct pane *p, char *key)
                char *a = attr_get_str(p->attrs, key, -1);
                if (a)
                        return a;
-               if (p->point) {
-                       a = doc_attr(p, NULL, 0, key);
-                       if (a)
-                               return a;
-               }
+               a = doc_attr(p, NULL, 0, key);
+               if (a)
+                       return a;
                p = p->parent;
        }
        /* FIXME do I want editor-wide attributes too? */
diff --git a/core.h b/core.h
index 2ef78ee2534bafb73a45c6f95911a1b693ce52f8..d349e22f1d23dcf7f23ee17ebfe3ce7277e40432 100644 (file)
--- a/core.h
+++ b/core.h
@@ -56,7 +56,7 @@ struct pane {
 
        struct command          *handle;
        void                    *data;
-       struct mark             *point;
+       struct mark             *pointer;
        struct attrset          *attrs;
 };
 
@@ -71,6 +71,7 @@ struct doc_data {
        struct doc              *doc;
        struct command          notify;
        struct pane             *pane;
+       struct mark             *point;
 };
 
 struct display {
@@ -403,11 +404,12 @@ static inline char *doc_attr(struct pane *dp, struct mark *m, bool forward, char
        struct cmd_info ci = {0};
 
        ci.key = "doc:get-attr";
-       ci.focus = dp;
+       ci.home = ci.focus = dp;
        ci.mark = m;
        ci.numeric = forward ? 1 : 0;
        ci.str = attr;
-       if (key_handle_focus(&ci) == 0)
+       ci.comm = dp->handle;
+       if (!dp->handle || dp->handle->func(&ci) == 0)
                return NULL;
        return ci.str2;
 }
index 59ab212a01f82c8b8f0605a601934cc5d46226c5..7dece9b0b022352db85d4019f638d99750cedbbe 100644 (file)
@@ -780,7 +780,7 @@ static int text_redo(struct text *t, struct doc_ref *start, struct doc_ref *end)
 DEF_CMD(text_reundo)
 {
        struct doc_data *dd = ci->home->data;
-       struct mark *m = ci->home->point;
+       struct mark *m = dd->point;
        bool redo = ci->numeric != 0;
        struct doc_ref start, end;
        int did_do = 2;
@@ -852,7 +852,7 @@ DEF_CMD(text_reundo)
                if (early && !text_ref_same(t, &early->ref, &start))
                        early = NULL;
 
-               point_notify_change(&t->doc, ci->home->point, early);
+               point_notify_change(&t->doc, dd->point, early);
 
                text_check_consistent(t);
        }
@@ -1358,7 +1358,7 @@ DEF_CMD(text_replace)
 {
        struct doc_data *dd = ci->home->data;
        struct text *t = container_of(dd->doc, struct text, doc);
-       struct mark *pm = ci->home->point;
+       struct mark *pm = dd->point;
        struct mark *end = ci->mark;
        char *str = ci->str;
        bool first = ci->numeric;