| 283 | } |
| 284 | |
| 285 | void DocSearchController::findNextText( SearchState& search, bool resetSelection ) { |
| 286 | if ( search.text.empty() ) |
| 287 | search.text = mLastSearch; |
| 288 | if ( !search.editor || !mSplitter->editorExists( search.editor ) || search.text.empty() ) |
| 289 | return; |
| 290 | |
| 291 | search.editor->getDocument().setActiveClient( search.editor ); |
| 292 | mLastSearch = search.text; |
| 293 | |
| 294 | Uint64 tag = String::hash( "DocSearchController::findNextText-" + |
| 295 | search.editor->getDocument().getHashHexString() ); |
| 296 | |
| 297 | mApp->getThreadPool()->removeWithTag( tag ); |
| 298 | mApp->getThreadPool()->run( |
| 299 | [this, search, resetSelection] { |
| 300 | ScopedOp op( [this] { mSearchingCount++; }, [this] { mSearchingCount--; } ); |
| 301 | TextDocument& doc = search.editor->getDocument(); |
| 302 | TextRange range = doc.getDocRange(); |
| 303 | TextPosition from = |
| 304 | resetSelection ? TextPosition( 0, 0 ) : doc.getSelection( true ).end(); |
| 305 | |
| 306 | if ( search.range.isValid() ) { |
| 307 | range = doc.sanitizeRange( search.range ).normalized(); |
| 308 | from = from < range.start() ? range.start() : from; |
| 309 | } |
| 310 | |
| 311 | String txt( search.text ); |
| 312 | if ( search.escapeSequences ) |
| 313 | txt.unescape(); |
| 314 | |
| 315 | TextRange found = |
| 316 | doc.find( txt, from, search.caseSensitive, search.wholeWord, search.type, range ) |
| 317 | .result; |
| 318 | |
| 319 | if ( found.isValid() ) { |
| 320 | doc.setSelection( found.reversed() ); |
| 321 | mFindInput->runOnMainThread( [this, search] { |
| 322 | mSplitter->addEditorPositionToNavigationHistory( search.editor ); |
| 323 | mFindInput->removeClass( "error" ); |
| 324 | } ); |
| 325 | return; |
| 326 | } else { |
| 327 | found = doc.find( txt, range.start(), search.caseSensitive, search.wholeWord, |
| 328 | search.type, range ) |
| 329 | .result; |
| 330 | if ( found.isValid() ) { |
| 331 | doc.setSelection( found.reversed() ); |
| 332 | mFindInput->runOnMainThread( [this, search] { |
| 333 | mSplitter->addEditorPositionToNavigationHistory( search.editor ); |
| 334 | mFindInput->removeClass( "error" ); |
| 335 | } ); |
| 336 | return; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | mFindInput->runOnMainThread( [this] { mFindInput->addClass( "error" ); } ); |
| 341 | }, |
| 342 | {}, tag ); |
no test coverage detected