1 Selected characters/rectangle statistics line feedback
3 Based on Arne Forlie's Selected character count patch
5 http://sourceforge.net/tracker/index.php?func=detail&aid=1043759&group_id=11005&atid=311005
6 [ 1043759 ] Selected character count
8 This patch implements a continuously updated count of
9 selected characters in the status line.
10 It only works for normal selections (not for
11 rectangular selections) and it doesn't work when
12 quadruple clicking to select the whole file.
14 It is a response to feature request 1040294, which
15 asked for something similar.
17 Augmented to show rectangle dimensions when a rectangular selection is
22 source/window.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
23 1 file changed, 50 insertions(+), 2 deletions(-)
25 diff --quilt old/source/window.c new/source/window.c
26 --- old/source/window.c
27 +++ new/source/window.c
28 @@ -2695,11 +2695,11 @@ static int updateLineNumDisp(WindowInfo*
29 ** Update the optional statistics line.
31 void UpdateStatsLine(WindowInfo *window)
33 int line, pos, colNum;
34 - char *string, *format, slinecol[32];
35 + char *string, *format, slinecol[64];
36 Widget statW = window->statsLine;
39 char *sleft, *smid, *sright;
41 @@ -2720,11 +2720,59 @@ void UpdateStatsLine(WindowInfo *window)
42 if (!TextPosToLineAndCol(window->lastFocus, pos, &line, &colNum)) {
43 sprintf(string, "%s%s%s %d bytes", window->path, window->filename,
44 format, window->buffer->length);
45 sprintf(slinecol, "L: --- C: ---");
47 - sprintf(slinecol, "L: %d C: %d", line, colNum);
48 + int start, end, isRect, rectStart, rectEnd, bytesSelected = 0;
49 + if (BufGetSelectionPos(window->buffer, &start, &end, &isRect, &rectStart, &rectEnd)) {
50 + bytesSelected = isRect ? 0 : end - start;
56 + if (bytesSelected > 0) {
57 + sprintf(slinecol, "[%d] L: %d C: %d", bytesSelected, line, colNum);
58 + } else if (isRect) {
59 + /* count lines in the rectangle from start to end */
61 + const textBuffer *buffer = window->buffer;
62 + const char *buf = buffer->buf;
63 + const char *txtbeg, *txtend;
64 + int len = end - start;
65 + if (start < buffer->gapStart) {
66 + /* rectangle is before or spans the buffer gap */
67 + txtbeg = buf + start;
68 + if (start + len <= buffer->gapStart) {
69 + /* all before the gap - nothing to count after the gap */
70 + txtend = txtbeg + len;
74 + /* bridges the gap - count upto the gap */
75 + txtend = buf + buffer->gapStart;
76 + /* and adjust settings for post-gap count */
77 + len -= buffer->gapStart - start;
78 + start = buffer->gapStart;
80 + for (; txtbeg < txtend; txtbeg++)
81 + if (*txtbeg == '\n')
82 + nlines++; /* count newlines before the gap */
85 + /* stuff to count after the gap */
86 + txtbeg = buf + start + buffer->gapEnd - buffer->gapStart;
87 + txtend = txtbeg + len;
88 + for (; txtbeg < txtend; txtbeg++)
89 + if (*txtbeg == '\n')
92 + sprintf(slinecol, "[%dx%d] L: %d C: %d",
93 + rectEnd-rectStart, nlines, line, colNum);
95 + sprintf(slinecol, "L: %d C: %d", line, colNum);
97 if (window->showLineNumbers)
98 sprintf(string, "%s%s%s byte %d of %d", window->path,
99 window->filename, format, pos,
100 window->buffer->length);