Okay after playing some more, whatever you highlight in BV, the code runs a javascript to get the selected text:
QString javascript = "window.getSelection().toString();";
EvaluateJavascript(javascript).toString();
And then runs the case changing code on the text. And then pastes it back over your highlighted selection:
In your test case the font color and underline code are to make the text appear the way it did when it was a link.
But everything you highlight, gets replaced with the case changed text:
Code:
void BookViewEditor::ApplyCaseChangeToSelection(const Utility::Casing &casing)
{
// This is going to lose any styles that may have been applied within
// that selected text.
QString selected_text = GetSelectedText();
qDebug() << "In BookViewEditor" << selected_text;
QString new_text = Utility::ChangeCase(selected_text, casing);
if (new_text == selected_text) {
return;
}
// The "proper" way to do a replacement of the text (and allow undo) will
// undoubtedly involve reams of javascript. However there is a quick and
// dirty alternative, of putting the text on the clipboard and pasting it.
// However since this will muck around the with clipboard history we need
// to do a little extra work to disconnect and restore things afterwards.
emit ClipboardSaveRequest();
QApplication::clipboard()->setText(new_text);
paste();
emit ClipboardRestoreRequest();
// We will have lost our selection from the paste operation.
for (int i = 0; i < new_text.length(); i++) {
page()->triggerAction(QWebPage::SelectPreviousChar);
}
}
The debug print shows exactly what Sigil was provided by the javascript
:
Debug: In BookViewEditor "First Chapter
Second Chapter"
So there isn't even an easy way for me to tell that a user has highlighted more than just a piece of text.
I will have to think about how to get the selection in some other way that will let me see if it passes over tag boundaries or not. This one won't be an easy fix or even fixed in the next release.
KevinH