Restore wxStyledTextCtrl Multicursor after replace

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2255
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd » Tue Aug 13, 2019 6:14 am

I do replacement of text using WriteText and since it removes multi cursors, I need to store their positions in the std::vector<int> as shown below. Then after write text is done I want to restore multi cursors but It does not work

Code: Select all

//saving
std::vector<int> carets;
for(int i = 0; i < editor->GetSelections(); ++i) {
    int caret = editor->GetSelectionNCaret(i);
    carets.push_back(caret);
}

//restoring
for(int i = 0; i < carets.size(); i++) {
    if(i == 0)
        editor->SetSelection(carets[i], carets[i]);
    else
        editor->AddSelection(carets[i], carets[i]);
}
I have tried so many things that I cannot remember. This is my latest trial that failed also!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
doublemax
Moderator
Moderator
Posts: 13993
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by doublemax » Tue Aug 13, 2019 3:56 pm

Code: Select all

editor->SetSelection(carets[i], carets[i]);
I don't know anything about wxSTC, but shouldn't that be:

Code: Select all

editor->SetSelection(i, carets[i]);
Use the source, Luke!

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2255
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd » Thu Aug 15, 2019 6:43 am

Hi,
doublemax wrote:
Tue Aug 13, 2019 3:56 pm

Code: Select all

editor->SetSelection(carets[i], carets[i]);
I don't know anything about wxSTC, but shouldn't that be:

Code: Select all

editor->SetSelection(i, carets[i]);
I have tested many combination and I don't remember anymore if that was one of those. Let me try that out and see
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

Kvaz1r
Earned some good credits
Earned some good credits
Posts: 125
Joined: Tue Jun 07, 2016 1:07 pm

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by Kvaz1r » Thu Aug 15, 2019 7:06 am

How exactly it didn't work? Carets are not restored or they restored on wrong positions?

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2255
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd » Mon Aug 19, 2019 11:52 am

Kvaz1r wrote:
Thu Aug 15, 2019 7:06 am
How exactly it didn't work? Carets are not restored or they restored on wrong positions?
Only last caret was restored. Others were lost. Am yet to apply DM solution!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2255
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd » Tue Aug 20, 2019 8:47 pm

doublemax wrote:
Tue Aug 13, 2019 3:56 pm

Code: Select all

editor->SetSelection(carets[i], carets[i]);
I don't know anything about wxSTC, but shouldn't that be:

Code: Select all

editor->SetSelection(i, carets[i]);
I tried it does not work. I can't figure out what I am doing wrong
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

Post Reply