QTextEdit - Finding text within selection
Hello,
I am creating a "find" dialog for my text editor. I have the basic functionality working but I'm not having any luck with limiting the search to a selection only (this is a great feature in many code editors).
Here's where I am so far (This is the slot):
Code:
void MainWindow
::findString(const QString str,
int flags,
bool selectionOnly
) {
if(selectionOnly)
<Code for finding within selection goes here>
else
currentEditor->find(str,ff); // currentEditor is a QTextEdit
}
What would be the most efficient way to limit the search to only the selected text?
Any help is appreciated.
Re: QTextEdit - Finding text within selection
<warning type="top of head" />
How about something like this:
- Grab the QTextEdit::textCursor()
- If no selection then return?
- Position newcursor at start of selection
- Execute newcursor = find(str, newcursor, opts)
- If newcursor still inside selection then report match and repeat find(). You have operator<() to compare cursors, or you can use the start or end positions manually.