News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Length of selected text

Started by zdena, May 10, 2019, 08:27:25 AM

Previous topic - Next topic

zdena

Hello,
if I make a selection of text in the code, can I get somehow the length (number of selected characters) of the selection?

Windows 10 64b
Arduino 1.8.11 with (modified) Arduino Builder 1.5.1z through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

oBFusCATed

At the moment I don't think it is possible.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

BlueHazzard

What would you like to do with it?
How would you like to get it?
I think it would not be to difficult to add a script binding...

zdena

@oBFusCATed: Thank you.

@BlueHazzard:

  • It could help me with counting characters in a (long) string if it could fit in a char array.
  • I don't know how. But for example Programmer's Notepad can count it.
  • I am not so good to write scripts.
Windows 10 64b
Arduino 1.8.11 with (modified) Arduino Builder 1.5.1z through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

BlueHazzard

This would be a quite easy fix:
diff --git a/src/src/main.cpp b/src/src/main.cpp
index 87e5c5e5c..df2ff0655 100644
--- a/src/src/main.cpp
+++ b/src/src/main.cpp
@@ -2055,7 +2055,7 @@ void MainFrame::DoCreateStatusBar()
     dc.GetTextExtent(_(" Highlight Button "),                &widths[num++], &h);
     dc.GetTextExtent(_(" Windows (CR+LF) "),                 &widths[num++], &h);
     dc.GetTextExtent(_(" WINDOWS-1252 "),                    &widths[num++], &h);
-    dc.GetTextExtent(_(" Line 12345, Col 123, Pos 123456 "), &widths[num++], &h);
+    dc.GetTextExtent(_(" Line 12345, Col 123, Pos 123456, Sel 123456 "), &widths[num++], &h);
     dc.GetTextExtent(_(" Overwrite "),                       &widths[num++], &h);
     dc.GetTextExtent(_(" Modified "),                        &widths[num++], &h);
     dc.GetTextExtent(_(" Read/Write "),                      &widths[num++], &h);
@@ -2127,7 +2127,7 @@ void MainFrame::DoUpdateStatusBar()
         }
         SetStatusText(msg, panel++);
         SetStatusText(ed->GetEncodingName(), panel++);
-        msg.Printf(_("Line %d, Col %d, Pos %d"), control->GetCurrentLine() + 1, control->GetColumn(pos) + 1, pos);
+        msg.Printf(_("Line %d, Col %d, Pos %d, Sel %d"), control->GetCurrentLine() + 1, control->GetColumn(pos) + 1, pos, control->GetSelectionEnd() - control->GetSelectionStart());
         SetStatusText(msg, panel++);
         SetStatusText(control->GetOvertype() ? _("Overwrite") : _("Insert"), panel++);
#if wxCHECK_VERSION(3, 0, 0)


Does something speaks against this?

oBFusCATed

Yes, it is getting too long and it doesn't convey that it is length.

After the previous change in this area there was a discussion to make this thing configurable with some kind of a formatting string.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zdena

@BlueHazzard: It was whole morning fight. I lost the battle with automatic patching :( , but I solved it manually :) . Next the C::B sources compiling was hard - especially battle with libexchndl.
But the result: Yes, your solution works pretty good  ;) Thank you
Windows 10 64b
Arduino 1.8.11 with (modified) Arduino Builder 1.5.1z through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

BlueHazzard

To come back to this. The easiest way to make it configirable would be to expose a printf formatter string and give the user the information that
%1$03d
is the current line
%2$03d
is the current column
%3$03d
is the current selection

so he can write
Line: %1$03d Col:%2$03d Sel:%3$03d
or
Sel: %3$03d | Line:%1$3d
or whatever by himself... Of course here he has some way to screw up, probably some sanity checking can be introduced, but i think this is the fastest and most flexible way.

A other possibility would be to give him some macros like
Sel: {sel} | Line:{line}
where {sel} and {line} would be replaced by the actual numbers, but here he can not say how many numbers he wants ecc...

Anyway this should not be to hard to implement...
Open for suggestions.

oBFusCATed

I'd prefer the second option. The first one is to unreadable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zdena

May I have a probably stupid question?

Where the user (will) can write the formatters or the macros?
Windows 10 64b
Arduino 1.8.11 with (modified) Arduino Builder 1.5.1z through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

Krice

Quote from: zdena on May 11, 2019, 06:37:54 PMIt could help me with counting characters in a (long) string if it could fit in a char array.

You don't want to do it that way. First get a piece of text and then in the program code determine the size of that string and what to do with it later. If you are using C++ the obvious thing to use is std::string.

zdena

@krice: Firstly I decide the length of char array. It depends on display size (16, 20, 40,... characters) for example. Then I create text messages and I would like to know that they are not longer than the array size.
Yes, Arduino is C++ but std::string is usually not used there.
Windows 10 64b
Arduino 1.8.11 with (modified) Arduino Builder 1.5.1z through (modified) C::B 17.12 32b
Occasional C(C++) hobbyist almost only for Arduino.
Czechia - please pardon my English

BlueHazzard


ZsoltKant

A long time has not been posted here. I also checked the latest nightly build, but the character counting functionality has not been implemented yet. The ticket status is open also and last updated in 2019.
Will this feature be implemented in the next release, or in a future?