Skip to content

Commit

Permalink
view: remove ViewEvent infrastructure
Browse files Browse the repository at this point in the history
The only used event handler was used to update the '< and '>
marks which is now taken care of by the leave handler of the
visual modes.
  • Loading branch information
martanne committed Nov 28, 2015
1 parent 30e9673 commit b1c462b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
7 changes: 1 addition & 6 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ struct Cursor { /* cursor position */
struct View {
Text *text; /* underlying text management */
UiWin *ui;
ViewEvent *events;
int width, height; /* size of display area */
Filepos start, end; /* currently displayed area [start, end] in bytes from the start of the file */
Filepos start_last; /* previously used start of visible area, used to update the mark */
Expand Down Expand Up @@ -580,9 +579,6 @@ void view_update(View *view) {
}
}
}

if (view->events && view->events->selection)
view->events->selection(view->events->data, &sel);
}
}

Expand Down Expand Up @@ -637,7 +633,7 @@ void view_reload(View *view, Text *text) {
view_cursor_to(view, 0);
}

View *view_new(Text *text, lua_State *lua, ViewEvent *events) {
View *view_new(Text *text, lua_State *lua) {
if (!text)
return NULL;
View *view = calloc(1, sizeof(View));
Expand All @@ -650,7 +646,6 @@ View *view_new(Text *text, lua_State *lua, ViewEvent *events) {

view->text = text;
view->lua = lua;
view->events = events;
view->tabwidth = 8;
view_options_set(view, 0);

Expand Down
7 changes: 1 addition & 6 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ typedef struct View View;
typedef struct Cursor Cursor;
typedef struct Selection Selection;

typedef struct {
void *data;
void (*selection)(void *data, Filerange*);
} ViewEvent;

typedef struct {
int width; /* display width i.e. number of columns ocupied by this character */
size_t len; /* number of bytes the character displayed in this cell uses, for
Expand Down Expand Up @@ -45,7 +40,7 @@ typedef struct {
size_t col;
} CursorPos;

View *view_new(Text*, lua_State*, ViewEvent*);
View *view_new(Text*, lua_State*);
void view_ui(View*, UiWin*);
/* change associated text displayed in this window */
void view_reload(View*, Text*);
Expand Down
2 changes: 1 addition & 1 deletion vis-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ static const char *file_open_dialog(Vis *vis, const char *pattern) {
Text *txt_orig = file->text;
View *view_orig = win->view;
Text *txt = text_load(NULL);
View *view = view_new(txt, NULL, NULL);
View *view = view_new(txt, NULL);
filename[0] = '\0';
snprintf(vis_open, sizeof(vis_open)-1, "vis-open %s", pattern ? pattern : "");

Expand Down
1 change: 0 additions & 1 deletion vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ struct Win {
UiWin *ui; /* ui object handling visual appearance of this window */
File *file; /* file being displayed in this window */
View *view; /* currently displayed part of underlying text */
ViewEvent events;
RingBuffer *jumplist; /* LRU jump management */
ChangeList changelist; /* state for iterating through least recently changes */
Win *prev, *next; /* neighbouring windows */
Expand Down
16 changes: 2 additions & 14 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ static void windows_invalidate(Vis *vis, size_t start, size_t end) {
view_draw(vis->win->view);
}

static void window_selection_changed(void *win, Filerange *sel) {
File *file = ((Win*)win)->file;
if (text_range_valid(sel)) {
file->marks[MARK_SELECTION_START] = text_mark_set(file->text, sel->start);
file->marks[MARK_SELECTION_END] = text_mark_set(file->text, sel->end);
}
}

static void window_free(Win *win) {
if (!win)
return;
Expand All @@ -183,12 +175,8 @@ static Win *window_new_file(Vis *vis, File *file) {
return NULL;
win->vis = vis;
win->file = file;
win->events = (ViewEvent) {
.data = win,
.selection = window_selection_changed,
};
win->jumplist = ringbuf_alloc(31);
win->view = view_new(file->text, vis->lua, &win->events);
win->view = view_new(file->text, vis->lua);
win->ui = vis->ui->window_new(vis->ui, win->view, file);
if (!win->jumplist || !win->view || !win->ui) {
window_free(win);
Expand Down Expand Up @@ -382,7 +370,7 @@ Vis *vis_new(Ui *ui) {
goto err;
if (!(vis->prompt->file->text = text_load(NULL)))
goto err;
if (!(vis->prompt->view = view_new(vis->prompt->file->text, NULL, NULL)))
if (!(vis->prompt->view = view_new(vis->prompt->file->text, NULL)))
goto err;
if (!(vis->prompt->ui = vis->ui->prompt_new(vis->ui, vis->prompt->view, vis->prompt->file)))
goto err;
Expand Down

0 comments on commit b1c462b

Please sign in to comment.