diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-06-30 11:37:00 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-06-30 11:37:00 +0200 |
| commit | 4af9fe66851a42c20c550f2c59aa64d7a327c9ff (patch) | |
| tree | 5bc43ab92be87d8749ad258beb57271785ec6d24 | |
| parent | 60fe132d6c59d54021091af8e5aa09fcd4704562 (diff) | |
| download | vis-4af9fe66851a42c20c550f2c59aa64d7a327c9ff.tar.gz vis-4af9fe66851a42c20c550f2c59aa64d7a327c9ff.tar.xz | |
Perform character prev/next movements based on Text not View
While it is slower, it allows to move to characters which are
currently not visible. This will be handy when experimenting
with multiple cursors.
| -rw-r--r-- | view.c | 40 | ||||
| -rw-r--r-- | view.h | 2 | ||||
| -rw-r--r-- | vis.c | 4 |
3 files changed, 2 insertions, 44 deletions
@@ -519,46 +519,6 @@ View *view_new(Text *text, ViewEvent *events) { void view_ui(View *view, UiWin* ui) { view->ui = ui; } -size_t view_char_prev(View *view) { - Cursor *cursor = &view->cursor; - Line *line = cursor->line; - - do { - if (cursor->col == 0) { - if (!line->prev) - return cursor->pos; - cursor->line = line = line->prev; - cursor->col = MIN(line->width, view->width - 1); - cursor->row--; - } else { - cursor->col--; - } - } while (line->cells[cursor->col].len == 0); - - cursor->pos -= line->cells[cursor->col].len; - return view_cursor_update(view); -} - -size_t view_char_next(View *view) { - Cursor *cursor = &view->cursor; - Line *line = cursor->line; - - do { - cursor->pos += line->cells[cursor->col].len; - if ((line->width == view->width && cursor->col == view->width - 1) || - cursor->col == line->width) { - if (!line->next) - return cursor->pos; - cursor->line = line = line->next; - cursor->row++; - cursor->col = 0; - } else { - cursor->col++; - } - } while (line->cells[cursor->col].len == 0); - - return view_cursor_update(view); -} static size_t view_cursor_set(View *view, Line *line, int col) { int row = 0; @@ -54,8 +54,6 @@ void view_tabwidth_set(View*, int tabwidth); /* cursor movements which also update selection if one is active. * they return new cursor postion */ -size_t view_char_next(View*); -size_t view_char_prev(View*); size_t view_line_down(View*); size_t view_line_up(View*); size_t view_screenline_down(View*); @@ -184,8 +184,8 @@ static Movement moves[] = { [MOVE_LINE_NEXT] = { .txt = text_line_next, .type = LINEWISE }, [MOVE_LINE] = { .txt = line, .type = LINEWISE|IDEMPOTENT|JUMP}, [MOVE_COLUMN] = { .txt = column, .type = CHARWISE|IDEMPOTENT}, - [MOVE_CHAR_PREV] = { .view = view_char_prev }, - [MOVE_CHAR_NEXT] = { .view = view_char_next }, + [MOVE_CHAR_PREV] = { .txt = text_char_prev }, + [MOVE_CHAR_NEXT] = { .txt = text_char_next }, [MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE }, [MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE }, [MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE }, |
