31 start = startSelectionPos;
32 end = endSelectionPos;
34 expression = text.mid( startSelectionPos, endSelectionPos - startSelectionPos ).replace( QChar( 0x2029 ), QChar(
'\n' ) );
38 if ( startSelectionPos != endSelectionPos )
44 const QRegularExpression regex( pattern.isEmpty() ? EXPRESSION_PATTERN : pattern );
45 QRegularExpressionMatchIterator result = regex.globalMatch( text );
47 while ( result.hasNext() )
49 const QRegularExpressionMatch match = result.next();
52 if ( match.capturedStart() < startSelectionPos && match.capturedEnd() > endSelectionPos )
54 start = match.capturedStart();
55 end = match.capturedEnd();
57 expression = match.captured( 1 );
59 expression = expression.replace( QChar( 0x2029 ), QChar(
'\n' ) );
86 int startPosition = editor->textCursor().selectionStart();
87 int endPosition = editor->textCursor().selectionEnd();
90 int newSelectionStart, newSelectionEnd;
91 findExpressionAtPos( editor->toPlainText(), startPosition, endPosition, newSelectionStart, newSelectionEnd, res, pattern );
93 QTextCursor cursor = editor->textCursor();
94 cursor.setPosition( newSelectionStart, QTextCursor::MoveAnchor );
95 cursor.setPosition( newSelectionEnd, QTextCursor::KeepAnchor );
96 editor->setTextCursor( cursor );
105 int startPosition = editor->textCursor().selectionStart();
106 int endPosition = editor->textCursor().selectionEnd();
109 int newSelectionStart, newSelectionEnd;
110 findExpressionAtPos( editor->toPlainText(), startPosition, endPosition, newSelectionStart, newSelectionEnd, res, pattern );
112 QTextCursor cursor = editor->textCursor();
113 cursor.setPosition( newSelectionStart, QTextCursor::MoveAnchor );
114 cursor.setPosition( newSelectionEnd, QTextCursor::KeepAnchor );
115 editor->setTextCursor( cursor );
static void findExpressionAtPos(const QString &text, int startSelectionPos, int endSelectionPos, int &start, int &end, QString &expression, const QString &pattern=QString())
Find an expression at the given position in the given text.