aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-04-15 12:01:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-04-15 13:09:12 +0200
commitd9d19896a9be5b5cf35d00cae61c9d5621044ccf (patch)
treeb819d2c9a741577bb60be19c9ffca4b724aa7126
parent9b2a3895eedb3c46179b1ed923b0f1214da04c5b (diff)
downloadbusybox-w32-d9d19896a9be5b5cf35d00cae61c9d5621044ccf.tar.gz
busybox-w32-d9d19896a9be5b5cf35d00cae61c9d5621044ccf.tar.bz2
busybox-w32-d9d19896a9be5b5cf35d00cae61c9d5621044ccf.zip
vi: position cursor on last column of tab
Vi places the cursor on the last column of a tab character whereas BusyBox vi puts it on the first. This is disconcerting for experienced vi users and makes it impossible to distinguish visually between an empty line and one containing just a tab. It wasn't always this way. Prior to commit e3cbfb91d (vi: introduce FEATURE_VI_8BIT) BusyBox vi also put the cursor on the last column. However there were problems with cursor positioning when text was inserted before a tab. Commit eaabf0675 (vi: multiple fixes by Natanael Copa) includes a partial attempt to fix this. (The code is still present but it's never executed. Clever compilers optimise it away.) Revert the changes of commit e3cbfb91d and fix the insert problem for all tabs, not just the first. To quote Natanael: "Costs a few bytes but its worth it imho". function old new delta refresh 974 1000 +26 move_to_col 81 83 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 28/0) Total: 28 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/editors/vi.c b/editors/vi.c
index fef328117..f71897253 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -826,21 +826,20 @@ static void sync_cursor(char *d, int *row, int *col)
826 826
827 // find out what col "d" is on 827 // find out what col "d" is on
828 co = 0; 828 co = 0;
829 while (tp < d) { // drive "co" to correct column 829 do { // drive "co" to correct column
830 if (*tp == '\n') //vda || *tp == '\0') 830 if (*tp == '\n') //vda || *tp == '\0')
831 break; 831 break;
832 if (*tp == '\t') { 832 if (*tp == '\t') {
833 // handle tabs like real vi
834 if (d == tp && cmd_mode) {
835 break;
836 }
837 co = next_tabstop(co); 833 co = next_tabstop(co);
838 } else if ((unsigned char)*tp < ' ' || *tp == 0x7f) { 834 } else if ((unsigned char)*tp < ' ' || *tp == 0x7f) {
839 co++; // display as ^X, use 2 columns 835 co++; // display as ^X, use 2 columns
840 } 836 }
841 co++; 837 // inserting text before a tab, don't include its position
842 tp++; 838 if (cmd_mode && tp == d - 1 && *d == '\t') {
843 } 839 co++;
840 break;
841 }
842 } while (tp++ < d && ++co);
844 843
845 // "co" is the column where "dot" is. 844 // "co" is the column where "dot" is.
846 // The screen has "columns" columns. 845 // The screen has "columns" columns.
@@ -1801,7 +1800,7 @@ static char *move_to_col(char *p, int l)
1801 1800
1802 p = begin_line(p); 1801 p = begin_line(p);
1803 co = 0; 1802 co = 0;
1804 while (co < l && p < end) { 1803 do {
1805 if (*p == '\n') //vda || *p == '\0') 1804 if (*p == '\n') //vda || *p == '\0')
1806 break; 1805 break;
1807 if (*p == '\t') { 1806 if (*p == '\t') {
@@ -1809,9 +1808,7 @@ static char *move_to_col(char *p, int l)
1809 } else if (*p < ' ' || *p == 127) { 1808 } else if (*p < ' ' || *p == 127) {
1810 co++; // display as ^X, use 2 columns 1809 co++; // display as ^X, use 2 columns
1811 } 1810 }
1812 co++; 1811 } while (++co <= l && p++ < end);
1813 p++;
1814 }
1815 return p; 1812 return p;
1816} 1813}
1817 1814