summaryrefslogtreecommitdiff
path: root/system/ksh/patches/0007-ksh-vi-compensate-for-cursor-move-on-command-mode.diff
blob: 8db9a55c558add4c8a22e8376ee0129f31b76d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From fc2058b4b6a64d66fe1ee318bccea42b4569d31f Mon Sep 17 00:00:00 2001
From: Alexander Polakov <polachok@gmail.com>
Date: Sun, 29 May 2011 19:23:17 +0400
Subject: [PATCH 7/8] ksh/vi: compensate for cursor move on command mode

 * move completion cursor one position right if the
   character is space
 * when we enter command mode, cursor is moved one
   position left, and the space on the end is "lost".
   So we are trying to complete "ls" instead of file
   while having "ls " and "file.c" when having "file.c ".
---
 vi.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/vi.c b/vi.c
index 95d192c..0bac6be 100644
--- a/vi.c
+++ b/vi.c
@@ -1956,6 +1956,7 @@ complete_word(int command, int count, int flags)
 	int match_len;
 	int is_unique;
 	int is_command;
+	int pos;
 
 	/* Undo previous completion */
 	if (command == 0 && expanded == COMPLETE && buf) {
@@ -1974,11 +1975,23 @@ complete_word(int command, int count, int flags)
 		buf = 0;
 	}
 
+	/* XXX: hack. When we enter command mode, the cursor is moved
+	 * one position left. This means that the space at the end is
+	 * eaten and file completion becomes command completion.
+	 * (see x_locate_word() for more on this)
+	 */
+	pos = es->cursor;
+	if (command) {
+		pos += (isspace(es->cbuf[es->cursor]) ? 1 : 0);
+		if (pos > es->linelen)
+			pos = es->linelen;
+	}
+
 	/* XCF_FULLPATH for count 'cause the menu printed by print_expansions()
 	 * was done this way.
 	 */
 	nwords = x_cf_glob(XCF_COMMAND_FILE | (count ? XCF_FULLPATH : 0) | flags,
-	    es->cbuf, es->linelen, es->cursor,
+	    es->cbuf, es->linelen, pos,
 	    &start, &end, &words, &is_command);
 	if (nwords == 0) {
 		vi_error();
-- 
1.7.5