| 230 | } |
| 231 | |
| 232 | void DocSearchController::findPrevText( SearchState& search ) { |
| 233 | if ( search.text.empty() ) |
| 234 | search.text = mLastSearch; |
| 235 | if ( !search.editor || !mSplitter->editorExists( search.editor ) || search.text.empty() ) |
| 236 | return; |
| 237 | |
| 238 | search.editor->getDocument().setActiveClient( search.editor ); |
| 239 | mLastSearch = search.text; |
| 240 | |
| 241 | Uint64 tag = String::hash( "DocSearchController::findPrevText-" + |
| 242 | search.editor->getDocument().getHashHexString() ); |
| 243 | mApp->getThreadPool()->removeWithTag( tag ); |
| 244 | mApp->getThreadPool()->run( [this, search] { |
| 245 | ScopedOp op( [this] { mSearchingCount++; }, [this] { mSearchingCount--; } ); |
| 246 | TextDocument& doc = search.editor->getDocument(); |
| 247 | TextRange range = doc.getDocRange(); |
| 248 | TextPosition from = doc.getSelection( true ).start(); |
| 249 | if ( search.range.isValid() ) { |
| 250 | range = doc.sanitizeRange( search.range ).normalized(); |
| 251 | from = from < range.start() ? range.start() : from; |
| 252 | } |
| 253 | |
| 254 | String txt( search.text ); |
| 255 | if ( search.escapeSequences ) |
| 256 | txt.unescape(); |
| 257 | |
| 258 | TextRange found = doc.findLast( txt, from, search.caseSensitive, search.wholeWord, |
| 259 | search.type, search.range ) |
| 260 | .result; |
| 261 | if ( found.isValid() ) { |
| 262 | doc.setSelection( found ); |
| 263 | mFindInput->runOnMainThread( [this, search] { |
| 264 | mSplitter->addEditorPositionToNavigationHistory( search.editor ); |
| 265 | mFindInput->removeClass( "error" ); |
| 266 | } ); |
| 267 | return; |
| 268 | } else { |
| 269 | found = doc.findLast( txt, range.end(), search.caseSensitive, search.wholeWord, |
| 270 | search.type, range ) |
| 271 | .result; |
| 272 | if ( found.isValid() ) { |
| 273 | doc.setSelection( found ); |
| 274 | mFindInput->runOnMainThread( [this, search] { |
| 275 | mSplitter->addEditorPositionToNavigationHistory( search.editor ); |
| 276 | mFindInput->removeClass( "error" ); |
| 277 | } ); |
| 278 | return; |
| 279 | } |
| 280 | } |
| 281 | mFindInput->runOnMainThread( [this] { mFindInput->addClass( "error" ); } ); |
| 282 | } ); |
| 283 | } |
| 284 | |
| 285 | void DocSearchController::findNextText( SearchState& search, bool resetSelection ) { |
| 286 | if ( search.text.empty() ) |
no test coverage detected