3 source/window.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
4 1 files changed, 53 insertions(+), 3 deletions(-)
6 diff --quilt old/source/window.c new/source/window.c
7 --- old/source/window.c
8 +++ new/source/window.c
9 @@ -2759,11 +2759,11 @@ static int updateLineNumDisp(WindowInfo*
10 ** Update the optional statistics line.
12 void UpdateStatsLine(WindowInfo *window)
14 int line, pos, colNum;
15 - char *string, *format, slinecol[32];
16 + char *string, *format, slinecol[64];
17 Widget statW = window->statsLine;
20 char *sleft, *smid, *sright;
22 @@ -2785,17 +2785,67 @@ void UpdateStatsLine(WindowInfo *window)
23 sprintf(string, "%s%s%s %d bytes", window->path, window->filename,
24 format, window->buffer->length);
25 sprintf(slinecol, "L: --- C: ---");
27 int start, end, isRect, rectStart, rectEnd, bytesSelected = 0;
29 if (BufGetSelectionPos(window->buffer, &start, &end, &isRect, &rectStart, &rectEnd)) {
30 bytesSelected = isRect ? 0 : end - start;
35 if (bytesSelected > 0) {
36 - sprintf(slinecol, "[%d] L: %d C: %2d", bytesSelected, line, colNum);
37 + snprintf(slinecol, sizeof(slinecol), "[%d] L: %d C: %2d",
38 + bytesSelected, line, colNum);
39 + } else if (isRect) {
40 + /* count lines in the rectangle from start to end */
42 + const textBuffer *buffer = window->buffer;
43 + const char *buf = buffer->buf;
44 + const char *txtbeg, *txtend;
45 + int len = end - start;
47 + if (start < buffer->gapStart) {
48 + /* rectangle is before or spans the buffer gap */
49 + txtbeg = buf + start;
51 + if (start + len <= buffer->gapStart) {
52 + /* all before the gap - nothing to count after the gap */
53 + txtend = txtbeg + len;
56 + /* bridges the gap - count upto the gap */
57 + txtend = buf + buffer->gapStart;
58 + /* and adjust settings for post-gap count */
59 + len -= buffer->gapStart - start;
60 + start = buffer->gapStart;
63 + for (; txtbeg < txtend; txtbeg++) {
64 + if (*txtbeg == '\n') {
65 + nlines++; /* count newlines before the gap */
71 + /* stuff to count after the gap */
72 + txtbeg = buf + start + buffer->gapEnd - buffer->gapStart;
73 + txtend = txtbeg + len;
75 + for (; txtbeg < txtend; txtbeg++) {
76 + if (*txtbeg == '\n') {
82 + snprintf(slinecol, sizeof(slinecol), "[%dx%d] L: %d C: %d",
83 + rectEnd - rectStart, nlines, line, colNum);
85 - sprintf(slinecol, "L: %d C: %2d", line, colNum);
86 + snprintf(slinecol, sizeof(slinecol), "L: %d C: %2d", line, colNum);
88 if (window->showLineNumbers)
89 sprintf(string, "%s%s%s byte %d of %d", window->path,
90 window->filename, format, pos,
91 window->buffer->length);