]> Sergey Matveev's repositories - lynx-patches.git/blob - edit-line.patch
ce956e28d012cbd1322a43bddcd2848b29bdae4a
[lynx-patches.git] / edit-line.patch
1 diff --git src/LYStrings.c src/LYStrings.c
2 index 67c0b2b..c34cf30 100644
3 --- src/LYStrings.c
4 +++ src/LYStrings.c
5 @@ -270,6 +270,40 @@ int fancy_mouse(WINDOW * win, int row,
6      return cmd;
7  }
8  
9 +// ------------------------ >8 ------------------------
10 +
11 +#include <assert.h>
12 +#include <ctype.h>
13 +#include <sys/stat.h>
14 +#define        typecalloc(cast)                (cast *)calloc((size_t)1, sizeof(cast))
15 +
16 +static char *readEditedFile(char *ed_temp)
17 +{
18 +    struct stat stat_info;
19 +    size_t size;
20 +    if ((stat(ed_temp, &stat_info) < 0) ||
21 +        !S_ISREG(stat_info.st_mode) ||
22 +        ((size = (size_t) stat_info.st_size) == 0)) {
23 +        return NULL;
24 +    }
25 +    char *ebuf = malloc(size + 1);
26 +    assert(ebuf != NULL);
27 +    FILE *fp = NULL;
28 +    if ((fp = fopen(ed_temp, "r")) != 0) {
29 +        size = fread(ebuf, (size_t) 1, size, fp);
30 +        LYCloseInput(fp);
31 +        ebuf[size] = '\0';
32 +    } else {
33 +        free(ebuf);
34 +        return NULL;
35 +    }
36 +    return ebuf;
37 +}
38 +
39 +#include <LYEdit.h>
40 +
41 +// ------------------------ >8 ------------------------
42 +
43  /*
44   * Manage the collection of edit-histories
45   */
46 @@ -3380,8 +3414,24 @@ int LYDoEdit(FieldEditor * edit, int ch,
47             EditAt++;
48         break;
49  
50 -    case LYE_ERASE:            /* erase the line */
51 -       Buffer[0] = '\0';
52 +    case LYE_ERASE: {
53 +        char *tmpPath = malloc(LY_MAXPATH);
54 +        FILE *fp = LYOpenTemp(tmpPath, "", "w");
55 +        assert(fp != 0);
56 +        fputs(Buffer, fp);
57 +        LYCloseTempFP(fp);
58 +        edit_temporary_file(tmpPath, "", NULL);
59 +        char *ebuf = readEditedFile(tmpPath);
60 +        free(tmpPath);
61 +        if (ebuf != NULL) {
62 +            FREE(Buffer);
63 +            Buffer = ebuf;
64 +            edit->efBufInUse = strlen(ebuf);
65 +            edit->efBufAlloc = edit->efBufInUse;
66 +            edit->efBufLimit = 0;
67 +        }
68 +    }
69 +
70  #ifdef ENHANCED_LINEEDIT
71         EditMark = -1;          /* Do not show the mark */
72  #endif