| 4873 | } |
| 4874 | |
| 4875 | String UICodeEditor::checkMouseOverLink( const Vector2i& position, bool checkModifiers ) { |
| 4876 | if ( !mInteractiveLinks || ( checkModifiers && !getInput()->isKeyModPressed() ) ) |
| 4877 | return resetLinkOver( position ); |
| 4878 | |
| 4879 | TextPosition pos( resolveScreenPosition( position.asFloat() ) ); |
| 4880 | if ( pos.line() >= (Int64)mDoc->linesCount() ) |
| 4881 | return resetLinkOver( position ); |
| 4882 | |
| 4883 | const String& line = mDoc->line( pos.line() ).getText(); |
| 4884 | if ( pos.column() >= (Int64)line.size() - 1 ) |
| 4885 | return resetLinkOver( position ); |
| 4886 | |
| 4887 | if ( mDoc->getChar( pos ) == '\n' ) |
| 4888 | return resetLinkOver( position ); |
| 4889 | |
| 4890 | TextPosition startB( mDoc->previousSpaceBoundaryInLine( pos, 1024, true ) ); |
| 4891 | TextPosition endB( mDoc->nextSpaceBoundaryInLine( pos, 1024, true ) ); |
| 4892 | |
| 4893 | if ( !startB.isValid() || !endB.isValid() ) |
| 4894 | return resetLinkOver( position ); |
| 4895 | |
| 4896 | if ( startB.column() >= (Int64)line.size() || endB.column() >= (Int64)line.size() ) |
| 4897 | return resetLinkOver( position ); |
| 4898 | |
| 4899 | if ( pos.column() <= startB.column() || pos.column() >= endB.column() ) |
| 4900 | return resetLinkOver( position ); |
| 4901 | |
| 4902 | String partialLine( line.substr( startB.column(), endB.column() ) ); |
| 4903 | |
| 4904 | LuaPattern words( LuaPattern::getURIPattern() ); |
| 4905 | int start, end = 0; |
| 4906 | std::string linkStr( partialLine.toUtf8() ); |
| 4907 | |
| 4908 | int offset = 0; |
| 4909 | std::vector<std::pair<int, int>> links; |
| 4910 | do { |
| 4911 | if ( words.find( linkStr, start, end, offset ) ) { |
| 4912 | links.emplace_back( std::make_pair( start, end ) ); |
| 4913 | offset = end; |
| 4914 | } |
| 4915 | } while ( start != end ); |
| 4916 | |
| 4917 | if ( !links.empty() ) { |
| 4918 | for ( const auto& link : links ) { |
| 4919 | if ( pos.column() >= startB.column() + link.first && |
| 4920 | pos.column() <= startB.column() + link.second ) { |
| 4921 | if ( checkModifiers ) { |
| 4922 | getUISceneNode()->setCursor( Cursor::Hand ); |
| 4923 | mHandShown = true; |
| 4924 | } |
| 4925 | mLinkPosition = { { startB.line(), startB.column() + link.first }, |
| 4926 | { startB.line(), startB.column() + link.second } }; |
| 4927 | mLink = String( linkStr.substr( link.first, link.second - link.first ) ); |
| 4928 | invalidateDraw(); |
| 4929 | return mLink; |
| 4930 | } |
| 4931 | } |
| 4932 | } |
nothing calls this directly
no test coverage detected