aboutsummaryrefslogtreecommitdiff
path: root/vis-modes.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-01-28 14:16:04 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-01-28 14:18:45 +0100
commit007ff80b477880e820d08391b96ca2a00889082e (patch)
treeff564565cd377a0966beb913d2f86bf7a6a80ece /vis-modes.c
parent043a183d1465f578775e2a28bdc0a5c44afccd40 (diff)
downloadvis-007ff80b477880e820d08391b96ca2a00889082e.tar.gz
vis-007ff80b477880e820d08391b96ca2a00889082e.tar.xz
vis: deindent blank autoindented lines when leaving insert mode
Does not work for the current implementation of `O` because the "lookbehind" i.e. second to last processed key is `<Up>` and not `<Enter>`. Fix #383
Diffstat (limited to 'vis-modes.c')
-rw-r--r--vis-modes.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/vis-modes.c b/vis-modes.c
index 4739c34..05cdc01 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -1,6 +1,7 @@
#include <string.h>
#include <strings.h>
#include "vis-core.h"
+#include "text-motions.h"
#include "util.h"
KeyAction *vis_action_new(Vis *vis, const char *name, const char *help, KeyActionFunction *func, Arg arg) {
@@ -138,6 +139,21 @@ bool vis_window_mode_map(Win *win, enum VisMode id, bool force, const char *key,
static void vis_mode_normal_enter(Vis *vis, Mode *old) {
if (old != mode_get(vis, VIS_MODE_INSERT) && old != mode_get(vis, VIS_MODE_REPLACE))
return;
+ if (vis->autoindent && strcmp(vis->key_prev, "<Enter>") == 0) {
+ Text *txt = vis->win->file->text;
+ for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
+ size_t pos = view_cursors_pos(c);
+ size_t start = text_line_start(txt, pos);
+ if (start == pos) {
+ size_t begin = text_line_begin(txt, pos);
+ size_t len = start - begin;
+ if (len) {
+ text_delete(txt, begin, len);
+ view_cursors_to(c, pos-len);
+ }
+ }
+ }
+ }
macro_operator_stop(vis);
if (!vis->win->parent && vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH] &&
vis->action_prev.count > 1) {