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: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd »

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?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by doublemax »

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: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd »

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?
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by Kvaz1r »

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: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd »

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?
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: Restore wxStyledTextCtrl Multicursor after replace

Post by evstevemd »

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?
Post Reply