| 6757 | } |
| 6758 | |
| 6759 | void ShaderViewer::find(bool down) |
| 6760 | { |
| 6761 | ScintillaEdit *cur = currentScintilla(); |
| 6762 | |
| 6763 | if(!cur) |
| 6764 | return; |
| 6765 | |
| 6766 | QString find = m_FindReplace->findText(); |
| 6767 | |
| 6768 | sptr_t flags = 0; |
| 6769 | |
| 6770 | if(m_FindReplace->matchCase()) |
| 6771 | flags |= SCFIND_MATCHCASE; |
| 6772 | if(m_FindReplace->matchWord()) |
| 6773 | flags |= SCFIND_WHOLEWORD; |
| 6774 | if(m_FindReplace->regexp()) |
| 6775 | flags |= SCFIND_REGEXP | SCFIND_POSIX; |
| 6776 | |
| 6777 | FindReplace::SearchContext context = m_FindReplace->context(); |
| 6778 | |
| 6779 | QString findHash = QFormatStr("%1%2%3%4").arg(find).arg(flags).arg((int)context).arg(down); |
| 6780 | |
| 6781 | if(findHash != m_FindState.hash) |
| 6782 | { |
| 6783 | m_FindState.hash = findHash; |
| 6784 | m_FindState.start = 0; |
| 6785 | m_FindState.end = cur->length(); |
| 6786 | m_FindState.offset = cur->currentPos(); |
| 6787 | if(down && cur->selectionStart() == m_FindState.offset && |
| 6788 | cur->selectionEnd() - m_FindState.offset == find.length()) |
| 6789 | m_FindState.offset += find.length(); |
| 6790 | } |
| 6791 | |
| 6792 | int start = m_FindState.start + m_FindState.offset; |
| 6793 | int end = m_FindState.end; |
| 6794 | |
| 6795 | if(!down) |
| 6796 | end = m_FindState.start; |
| 6797 | |
| 6798 | QPair<int, int> result = cur->findText(flags, find.toUtf8().data(), start, end); |
| 6799 | |
| 6800 | m_FindState.prevResult = result; |
| 6801 | |
| 6802 | if(result.first == -1) |
| 6803 | { |
| 6804 | sptr_t maxOffset = down ? 0 : m_FindState.end; |
| 6805 | |
| 6806 | // if we're at offset 0 searching down, there are no results. Same for offset max and |
| 6807 | // searching up |
| 6808 | if(m_FindState.offset == maxOffset) |
| 6809 | return; |
| 6810 | |
| 6811 | // otherwise, we can wrap the search around |
| 6812 | |
| 6813 | if(context == FindReplace::AllFiles) |
| 6814 | { |
| 6815 | cur = nextScintilla(cur); |
| 6816 | ToolWindowManager::raiseToolWindow(cur); |
no test coverage detected