Skip to content

Commit

Permalink
Support transpose at end of line
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
jart committed Nov 8, 2021
1 parent 098505b commit 8ab535e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bestline.c
Original file line number Diff line number Diff line change
Expand Up @@ -2549,10 +2549,10 @@ static size_t BackwardWord(struct bestlineState *l, size_t pos) {
return pos;
}

static size_t EscapeWord(struct bestlineState *l) {
size_t i, j;
static size_t EscapeWord(struct bestlineState *l, size_t i) {
size_t j;
struct rune r;
for (i = l->pos; i && i < l->len; i += r.n) {
for (; i && i < l->len; i += r.n) {
if (i < l->len) {
r = GetUtf8(l->buf + i, l->len - i);
if (bestlineIsSeparator(r.c)) break;
Expand Down Expand Up @@ -2743,6 +2743,7 @@ static void bestlineEditTranspose(struct bestlineState *l) {
char *q, *p;
size_t a, b, c;
b = l->pos;
if (b == l->len) --b;
a = Backward(l, b);
c = Forward(l, b);
if (!(a < b && b < c)) return;
Expand All @@ -2758,8 +2759,13 @@ static void bestlineEditTranspose(struct bestlineState *l) {

static void bestlineEditTransposeWords(struct bestlineState *l) {
char *q, *p;
size_t pi, xi, xj, yi, yj;
pi = EscapeWord(l);
size_t i, pi, xi, xj, yi, yj;
i = l->pos;
if (i == l->len) {
i = Backwards(l, i, bestlineIsSeparator);
i = Backwards(l, i, bestlineNotSeparator);
}
pi = EscapeWord(l, i);
xj = Backwards(l, pi, bestlineIsSeparator);
xi = Backwards(l, xj, bestlineNotSeparator);
yi = Forwards(l, pi, bestlineIsSeparator);
Expand Down

0 comments on commit 8ab535e

Please sign in to comment.