Skip to content

Commit ce7abcd

Browse files
Improve line overflow
linedit_stringdisplaycoordinates now measures lines longer than the terminal width correctly.
1 parent 70eb727 commit ce7abcd

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

src/linedit.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ void linedit_stringdisplaycoordinates(lineditor *edit, linedit_string *string, i
664664
int x=0, y=0, n=0;
665665
size_t count;
666666
for (int i=0; i<string->length; n+=count) {
667-
if (n>=posn) break;
667+
if (posn>=0 && n>=posn) break;
668668

669669
char *c=string->string+i;
670670
size_t len = linedit_graphemelength(edit, c, string->string+string->length);
@@ -675,7 +675,9 @@ void linedit_stringdisplaycoordinates(lineditor *edit, linedit_string *string, i
675675
} else {
676676
int w=1;
677677
linedit_graphemedisplaywidth(edit, string->string+i, len, &w);
678-
x+=w;
678+
if (x+w>edit->ncols) { // Lines that are too long wrap over
679+
x=w; y++;
680+
} else x+=w;
679681
}
680682

681683
i+=len;
@@ -1277,28 +1279,18 @@ void linedit_redraw(lineditor *edit) {
12771279
sugglength=(int) strlen(suggestion);
12781280
}
12791281

1280-
// Reser default text
1282+
// Reset default text
12811283
linedit_stringdefaulttext(&output);
12821284

1283-
// Retrieve the current editing position
1285+
// Retrieve the display coordinates of the current editing position
12841286
int xpos, ypos, nlines;
12851287
linedit_stringdisplaycoordinates(edit, &edit->current, edit->posn, &xpos, &ypos);
1286-
linedit_stringcoordinates(&edit->current, -1, NULL, &nlines);
1288+
linedit_stringdisplaycoordinates(edit, &edit->current, -1, NULL, &nlines);
12871289

1288-
/* Determine the left and right hand boundaries */
12891290
int promptwidth=linedit_stringdisplaywidth(edit, &edit->prompt);
12901291
int stringwidth=linedit_stringlength(&edit->current);
12911292

12921293
int start=0, end=promptwidth+stringwidth+sugglength;
1293-
/*if (end>=edit->ncols) {
1294-
// Are we near the start?
1295-
if (promptwidth+edit->posn<edit->ncols) {
1296-
start = 0;
1297-
} else {
1298-
start = promptwidth+edit->posn-edit->ncols+1;
1299-
}
1300-
end=start+edit->ncols-1;
1301-
}*/
13021294

13031295
linedit_hidecursor();
13041296
linedit_moveup(ypos); // Move to the starting line

0 commit comments

Comments
 (0)