From 52780b336a46654163e0d34204a0aad0da5fdf33 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 30 Nov 2015 08:50:58 +1100 Subject: [PATCH] Move the authoritative 'point' out of the pane and into the doc_data. 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 --- core-doc.c | 29 +++++++++++++++++------------ core-keymap.c | 8 ++++---- core-pane.c | 22 +++++++++------------- core.h | 8 +++++--- doc-text.c | 6 +++--- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/core-doc.c b/core-doc.c index 85600fb6..bd5a16dd 100644 --- a/core-doc.c +++ b/core-doc.c @@ -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; diff --git a/core-keymap.c b/core-keymap.c index cab54238..060325ef 100644 --- a/core-keymap.c +++ b/core-keymap.c @@ -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; diff --git a/core-pane.c b/core-pane.c index 7f317358..970d5d5f 100644 --- a/core-pane.c +++ b/core-pane.c @@ -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 2ef78ee2..d349e22f 100644 --- 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; } diff --git a/doc-text.c b/doc-text.c index 59ab212a..7dece9b0 100644 --- a/doc-text.c +++ b/doc-text.c @@ -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; -- 2.39.5