Changeset View
Changeset View
Standalone View
Standalone View
util/texteditorhelpers.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 47 | { | |||
---|---|---|---|---|---|
48 | QPoint startPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.start())); | 48 | QPoint startPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.start())); | ||
49 | QPoint endPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.end())); | 49 | QPoint endPoint = view->mapToGlobal(view->cursorToCoordinate(itemRange.end())); | ||
50 | endPoint.ry() += getLineHeight(view, itemRange.start().line()); | 50 | endPoint.ry() += getLineHeight(view, itemRange.start().line()); | ||
51 | return QRect(startPoint, endPoint); | 51 | return QRect(startPoint, endPoint); | ||
52 | } | 52 | } | ||
53 | 53 | | |||
54 | KTextEditor::Cursor KTextEditorHelpers::extractCursor(const QString& input, int* pathLength) | 54 | KTextEditor::Cursor KTextEditorHelpers::extractCursor(const QString& input, int* pathLength) | ||
55 | { | 55 | { | ||
56 | // ":ll:cc", ":ll" | ||||
56 | static const QRegularExpression pattern(QStringLiteral(":(\\d+)(?::(\\d+))?$")); | 57 | static const QRegularExpression pattern(QStringLiteral(":(\\d+)(?::(\\d+))?$")); | ||
57 | const auto match = pattern.match(input); | 58 | // "#Lll", "#nll", "#ll" as e.g. seen with repo web links | ||
59 | static const QRegularExpression pattern2(QStringLiteral("#(?:n|L|)(\\d+)$")); | ||||
60 | | ||||
61 | auto match = pattern.match(input); | ||||
62 | | ||||
63 | if (!match.hasMatch()) { | ||||
64 | match = pattern2.match(input); | ||||
65 | } | ||||
66 | | ||||
kfunk: Code looks a bit too branchy.
Maybe it'd make more sense if you'd just use on instance of… | |||||
kfunk: Meant `match = pattern2.match(input);` in line 3 of course... | |||||
58 | if (!match.hasMatch()) { | 67 | if (!match.hasMatch()) { | ||
59 | if (pathLength) | 68 | if (pathLength) | ||
60 | *pathLength = input.length(); | 69 | *pathLength = input.length(); | ||
61 | return KTextEditor::Cursor::invalid(); | 70 | return KTextEditor::Cursor::invalid(); | ||
62 | } | 71 | } | ||
63 | 72 | | |||
64 | int line = match.capturedRef(1).toInt() - 1; | 73 | int line = match.capturedRef(1).toInt() - 1; | ||
74 | // captured(2) for pattern2 will yield null QString, toInt() thus 0, so no need for if-else | ||||
65 | // don't use an invalid column when the line is valid | 75 | // don't use an invalid column when the line is valid | ||
66 | int column = qMax(0, match.captured(2).toInt() - 1); | 76 | int column = qMax(0, match.captured(2).toInt() - 1); | ||
67 | 77 | | |||
68 | if (pathLength) | 78 | if (pathLength) | ||
69 | *pathLength = match.capturedStart(0); | 79 | *pathLength = match.capturedStart(0); | ||
70 | return {line, column}; | 80 | return {line, column}; | ||
71 | } | 81 | } | ||
72 | 82 | | |||
73 | } | 83 | } |
Code looks a bit too branchy.
Maybe it'd make more sense if you'd just use on instance of QRegularExpressionMatch?
For pattern2 match.captured(2).toInt() will always return 0, which should be handled fine by the original code.