Page 1 of 1

Restore wxStyledTextCtrl Multicursor after replace

Posted: Tue Aug 13, 2019 6:14 am
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!

Re: Restore wxStyledTextCtrl Multicursor after replace

Posted: Tue Aug 13, 2019 3:56 pm
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]);

Re: Restore wxStyledTextCtrl Multicursor after replace

Posted: Thu Aug 15, 2019 6:43 am
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

Re: Restore wxStyledTextCtrl Multicursor after replace

Posted: Thu Aug 15, 2019 7:06 am
by Kvaz1r
How exactly it didn't work? Carets are not restored or they restored on wrong positions?

Re: Restore wxStyledTextCtrl Multicursor after replace

Posted: Mon Aug 19, 2019 11:52 am
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!

Re: Restore wxStyledTextCtrl Multicursor after replace

Posted: Tue Aug 20, 2019 8:47 pm
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