aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-02-03 10:13:17 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2019-02-08 12:57:58 +0100
commitbb983f30e7ea69604212793f228270f21e8a5b06 (patch)
tree6514127fdcfe5b03a33270320d6856267cc24029
parente6503f2f0982378cd753be152fa19f8336c357bc (diff)
downloadbusybox-w32-bb983f30e7ea69604212793f228270f21e8a5b06.tar.gz
busybox-w32-bb983f30e7ea69604212793f228270f21e8a5b06.tar.bz2
busybox-w32-bb983f30e7ea69604212793f228270f21e8a5b06.zip
vi: fix faulty undo after autoinsert
Enable autoinsert and enter the following with an indent of three spaces: line 1 line 2 Using 'u' to undo the last insert results in: line1e 2 The insertion of the indent hasn't been properly recorded. Since recording insertions is a common operation add a convenience function, undo_push_insert(), to handle this and use it to record the autoindent correctly. function old new delta undo_push_insert - 36 +36 string_insert 133 129 -4 char_insert 518 473 -45 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 36/-49) Total: -13 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c57
1 files changed, 22 insertions, 35 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 32144abaa..c6adeb311 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -598,6 +598,7 @@ static void check_context(char); // remember context for '' command
598#if ENABLE_FEATURE_VI_UNDO 598#if ENABLE_FEATURE_VI_UNDO
599static void flush_undo_data(void); 599static void flush_undo_data(void);
600static void undo_push(char *, unsigned int, unsigned char); // Push an operation on the undo stack 600static void undo_push(char *, unsigned int, unsigned char); // Push an operation on the undo stack
601static void undo_push_insert(char *, int, int); // convenience function
601static void undo_pop(void); // Undo the last operation 602static void undo_pop(void); // Undo the last operation
602# if ENABLE_FEATURE_VI_UNDO_QUEUE 603# if ENABLE_FEATURE_VI_UNDO_QUEUE
603static void undo_queue_commit(void); // Flush any queued objects to the undo stack 604static void undo_queue_commit(void); // Flush any queued objects to the undo stack
@@ -2011,19 +2012,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2011 c = get_one_char(); 2012 c = get_one_char();
2012 *p = c; 2013 *p = c;
2013#if ENABLE_FEATURE_VI_UNDO 2014#if ENABLE_FEATURE_VI_UNDO
2014 switch (undo) { 2015 undo_push_insert(p, 1, undo);
2015 case ALLOW_UNDO:
2016 undo_push(p, 1, UNDO_INS);
2017 break;
2018 case ALLOW_UNDO_CHAIN:
2019 undo_push(p, 1, UNDO_INS_CHAIN);
2020 break;
2021# if ENABLE_FEATURE_VI_UNDO_QUEUE
2022 case ALLOW_UNDO_QUEUED:
2023 undo_push(p, 1, UNDO_INS_QUEUED);
2024 break;
2025# endif
2026 }
2027#else 2016#else
2028 modified_count++; 2017 modified_count++;
2029#endif /* ENABLE_FEATURE_VI_UNDO */ 2018#endif /* ENABLE_FEATURE_VI_UNDO */
@@ -2051,19 +2040,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2051 if (c == '\n') 2040 if (c == '\n')
2052 undo_queue_commit(); 2041 undo_queue_commit();
2053# endif 2042# endif
2054 switch (undo) { 2043 undo_push_insert(p, 1, undo);
2055 case ALLOW_UNDO:
2056 undo_push(p, 1, UNDO_INS);
2057 break;
2058 case ALLOW_UNDO_CHAIN:
2059 undo_push(p, 1, UNDO_INS_CHAIN);
2060 break;
2061# if ENABLE_FEATURE_VI_UNDO_QUEUE
2062 case ALLOW_UNDO_QUEUED:
2063 undo_push(p, 1, UNDO_INS_QUEUED);
2064 break;
2065# endif
2066 }
2067#else 2044#else
2068 modified_count++; 2045 modified_count++;
2069#endif /* ENABLE_FEATURE_VI_UNDO */ 2046#endif /* ENABLE_FEATURE_VI_UNDO */
@@ -2083,7 +2060,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p'
2083 p += bias; 2060 p += bias;
2084 q += bias; 2061 q += bias;
2085#if ENABLE_FEATURE_VI_UNDO 2062#if ENABLE_FEATURE_VI_UNDO
2086 undo_push(p, len, UNDO_INS); 2063 undo_push_insert(p, len, undo);
2087#endif 2064#endif
2088 memcpy(p, q, len); 2065 memcpy(p, q, len);
2089 p += len; 2066 p += len;
@@ -2392,6 +2369,23 @@ static void undo_push(char *src, unsigned int length, uint8_t u_type) // Add to
2392 modified_count++; 2369 modified_count++;
2393} 2370}
2394 2371
2372static void undo_push_insert(char *p, int len, int undo)
2373{
2374 switch (undo) {
2375 case ALLOW_UNDO:
2376 undo_push(p, len, UNDO_INS);
2377 break;
2378 case ALLOW_UNDO_CHAIN:
2379 undo_push(p, len, UNDO_INS_CHAIN);
2380 break;
2381# if ENABLE_FEATURE_VI_UNDO_QUEUE
2382 case ALLOW_UNDO_QUEUED:
2383 undo_push(p, len, UNDO_INS_QUEUED);
2384 break;
2385# endif
2386 }
2387}
2388
2395static void undo_pop(void) // Undo the last operation 2389static void undo_pop(void) // Undo the last operation
2396{ 2390{
2397 int repeat; 2391 int repeat;
@@ -2665,14 +2659,7 @@ static uintptr_t string_insert(char *p, const char *s, int undo) // insert the s
2665 2659
2666 i = strlen(s); 2660 i = strlen(s);
2667#if ENABLE_FEATURE_VI_UNDO 2661#if ENABLE_FEATURE_VI_UNDO
2668 switch (undo) { 2662 undo_push_insert(p, i, undo);
2669 case ALLOW_UNDO:
2670 undo_push(p, i, UNDO_INS);
2671 break;
2672 case ALLOW_UNDO_CHAIN:
2673 undo_push(p, i, UNDO_INS_CHAIN);
2674 break;
2675 }
2676#endif 2663#endif
2677 bias = text_hole_make(p, i); 2664 bias = text_hole_make(p, i);
2678 p += bias; 2665 p += bias;