remove currentDesktop from server request but allow -do macros on new Untitled
[nedit-bw.git] / selectionCountPatch3.diff
blob36b982cf42bb37c7dd2038387b1466dacaee88cf
1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Selected characters/rectangle statistics line feedback
4 Based on Arne Forlie's Selected character count patch
6 http://sourceforge.net/tracker/index.php?func=detail&aid=1043759&group_id=11005&atid=311005
7 [ 1043759 ] Selected character count
9 This patch implements a continuously updated count of selected characters in
10 the status line. It only works for normal selections (not for rectangular
11 selections) and it doesn't work when quadruple clicking to select the whole
12 file.
14 It is a response to feature request 1040294, which asked for something
15 similar.
17 Augmented to show rectangle dimensions when a rectangular selection is
18 active.
20 ---
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 @@ -2694,7 +2694,7 @@ static int updateLineNumDisp(WindowInfo*
29 void UpdateStatsLine(WindowInfo *window)
31 int line, pos, colNum;
32 - char *string, *format, slinecol[32];
33 + char *string, *format, slinecol[64];
34 Widget statW = window->statsLine;
35 XmString xmslinecol;
36 #ifdef SGI_CUSTOM
37 @@ -2719,7 +2719,55 @@ void UpdateStatsLine(WindowInfo *window)
38 format, window->buffer->length);
39 sprintf(slinecol, "L: --- C: ---");
40 } else {
41 - sprintf(slinecol, "L: %d C: %d", line, colNum);
42 + int start, end, isRect, rectStart, rectEnd, bytesSelected = 0;
43 + if (BufGetSelectionPos(window->buffer, &start, &end, &isRect, &rectStart, &rectEnd)) {
44 + bytesSelected = isRect ? 0 : end - start;
45 + }
46 + else {
47 + isRect = 0;
48 + }
50 + if (bytesSelected > 0) {
51 + sprintf(slinecol, "[%d] L: %d C: %d", bytesSelected, line, colNum);
52 + } else if (isRect) {
53 + /* count lines in the rectangle from start to end */
54 + int nlines = 1;
55 + const textBuffer *buffer = window->buffer;
56 + const char *buf = buffer->buf;
57 + const char *txtbeg, *txtend;
58 + int len = end - start;
59 + if (start < buffer->gapStart) {
60 + /* rectangle is before or spans the buffer gap */
61 + txtbeg = buf + start;
62 + if (start + len <= buffer->gapStart) {
63 + /* all before the gap - nothing to count after the gap */
64 + txtend = txtbeg + len;
65 + len = 0;
66 + }
67 + else {
68 + /* bridges the gap - count upto the gap */
69 + txtend = buf + buffer->gapStart;
70 + /* and adjust settings for post-gap count */
71 + len -= buffer->gapStart - start;
72 + start = buffer->gapStart;
73 + }
74 + for (; txtbeg < txtend; txtbeg++)
75 + if (*txtbeg == '\n')
76 + nlines++; /* count newlines before the gap */
77 + }
78 + if (len > 0) {
79 + /* stuff to count after the gap */
80 + txtbeg = buf + start + buffer->gapEnd - buffer->gapStart;
81 + txtend = txtbeg + len;
82 + for (; txtbeg < txtend; txtbeg++)
83 + if (*txtbeg == '\n')
84 + nlines++;
85 + }
86 + sprintf(slinecol, "[%dx%d] L: %d C: %d",
87 + rectEnd-rectStart, nlines, line, colNum);
88 + } else {
89 + sprintf(slinecol, "L: %d C: %d", line, colNum);
90 + }
91 if (window->showLineNumbers)
92 sprintf(string, "%s%s%s byte %d of %d", window->path,
93 window->filename, format, pos,