Author Topic: Length of selected text  (Read 11064 times)

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 39
Length of selected text
« on: May 10, 2019, 08:27:25 am »
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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Length of selected text
« Reply #1 on: May 11, 2019, 03:40:45 pm »
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!]

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Length of selected text
« Reply #2 on: May 11, 2019, 05:12:54 pm »
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...

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Length of selected text
« Reply #3 on: May 11, 2019, 06:37:54 pm »
@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

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Length of selected text
« Reply #4 on: May 12, 2019, 12:49:22 am »
This would be a quite easy fix:
Code
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Length of selected text
« Reply #5 on: May 12, 2019, 10:42:25 am »
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!]

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Length of selected text
« Reply #6 on: May 12, 2019, 11:08:23 am »
@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

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Length of selected text
« Reply #7 on: August 28, 2019, 12:05:13 pm »
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
Code
%1$03d
is the current line
Code
%2$03d
is the current column
Code
%3$03d
is the current selection

so he can write
Code
 Line: %1$03d Col:%2$03d Sel:%3$03d
or
Code
 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
Code
 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Length of selected text
« Reply #8 on: August 29, 2019, 08:03:00 am »
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!]

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Length of selected text
« Reply #9 on: August 29, 2019, 11:32:57 am »
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

Offline Krice

  • Almost regular
  • **
  • Posts: 152
Re: Length of selected text
« Reply #10 on: August 29, 2019, 12:28:18 pm »
It 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.

Offline zdena

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Length of selected text
« Reply #11 on: August 29, 2019, 08:49:44 pm »
@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

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Length of selected text
« Reply #12 on: August 29, 2019, 11:51:27 pm »

Offline ZsoltKant

  • Single posting newcomer
  • *
  • Posts: 6
Re: Length of selected text
« Reply #13 on: October 07, 2024, 07:43:52 pm »
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?