diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-04 10:10:22 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-04 10:10:22 +0200 |
| commit | 749099c3f828a6289cb9b7a673be14f3938ab10d (patch) | |
| tree | a87f87309270130828df00d16cce3654a8e764d8 /sam.c | |
| parent | 56977c546f8809ab354ffb036264fa02e29c152b (diff) | |
| download | vis-749099c3f828a6289cb9b7a673be14f3938ab10d.tar.gz vis-749099c3f828a6289cb9b7a673be14f3938ab10d.tar.xz | |
sam: fix special handling of single line numbers
If only line numbers are given (either in absolute or relative form)
we treat it as motion instead of a range specifier. That is :nn moves
to line nn, but does not select it.
This should however not affect other range specifiers such as :n,m
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -355,8 +355,6 @@ static Address *address_parse_simple(Vis *vis, const char **s, enum SamError *er case '5': case '6': case '7': case '8': case '9': addr.type = 'l'; addr.number = parse_number(s); - if (!**s && !vis->mode->visual) - addr.type = 'g'; break; case '/': /* regexp forwards */ case '?': /* regexp backwards */ @@ -914,14 +912,27 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur for (Cursor *c = view_cursors(view), *next; c; c = next) { next = view_cursors_next(c); Filerange sel; + size_t pos = view_cursors_pos(c); if (vis->mode->visual) { sel = view_cursors_selection_get(c); } else if (cmd->cmd->address) { - size_t start = view_cursors_pos(c); - size_t end = text_char_next(txt, start); - sel = text_range_new(start, end); + /* convert a single line range to a goto line motion */ + if (!multiple_cursors && cmd->cmd->cmddef->func == cmd_print) { + Address *addr = cmd->cmd->address; + switch (addr->type) { + case '+': + case '-': + addr = addr->right; + /* fall through */ + case 'l': + if (addr && addr->type == 'l' && !addr->right) + addr->type = 'g'; + break; + } + } + sel = text_range_new(pos, text_char_next(txt, pos)); } else if (multiple_cursors) { - sel = text_object_line(txt, view_cursors_pos(c)); + sel = text_object_line(txt, pos); } else { sel = text_range_new(0, text_size(txt)); } |
