From 60e6cf29521f3fa4bbb41b96e68b54f9502d7b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 13 Jun 2017 15:26:13 +0200 Subject: sam: simplify print command implementation --- sam.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/sam.c b/sam.c index 6d6da1c..82463eb 100644 --- a/sam.c +++ b/sam.c @@ -1494,23 +1494,18 @@ static bool cmd_print(Vis *vis, Win *win, Command *cmd, const char *argv[], Sele if (!win || !text_range_valid(range)) return false; View *view = win->view; - Text *txt = win->file->text; - size_t pos = range->end; - if (range->start != range->end) - pos = text_char_prev(txt, pos); - if (sel) - view_cursors_to(sel, pos); - else - sel = view_selections_new_force(view, pos); - if (sel) { - if (range->start != range->end) { - view_selections_set(sel, range); - view_selections_anchor(sel); - } else { - view_selection_clear(sel); - } + if (!sel) + sel = view_selections_new_force(view, range->start); + if (!sel) + return false; + if (range->start != range->end) { + view_selections_set(sel, range); + view_selections_anchor(sel); + } else { + view_cursors_to(sel, range->start); + view_selection_clear(sel); } - return sel != NULL; + return true; } static bool cmd_files(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) { -- cgit v1.2.3