Take the given QML line and check if it's a line of the form foo.bar: value. Return ranges for the key and the value.
| 128 | // Take the given QML line and check if it's a line of the form foo.bar: value. |
| 129 | // Return ranges for the key and the value. |
| 130 | const QPair<KTextEditor::Range, KTextEditor::Range> parseProperty(const QString& line, const KTextEditor::Cursor& position) { |
| 131 | const QStringList items = line.split(QLatin1Char(';')); |
| 132 | QString matchingItem; |
| 133 | int col_offset = -1; |
| 134 | // This is to also support FooAnimation { foo: bar; baz: bang; duration: 200 } |
| 135 | // or similar |
| 136 | for (const QString& item : items) { |
| 137 | col_offset += item.size() + 1; |
| 138 | if ( position.column() < col_offset ) { |
| 139 | matchingItem = item; |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | QStringList split = matchingItem.split(QLatin1Char(':')); |
| 144 | if ( split.size() != 2 ) { |
| 145 | // The expression is not of the form foo:bar, thus invalid. |
| 146 | return qMakePair(KTextEditor::Range::invalid(), KTextEditor::Range::invalid()); |
| 147 | } |
| 148 | QString key = split.at(0); |
| 149 | QString value = split.at(1); |
| 150 | |
| 151 | // For animations or similar, remove the trailing '}' if there's no semicolon after the last entry |
| 152 | if (value.trimmed().endsWith(QLatin1Char('}'))) { |
| 153 | col_offset -= value.size() - value.lastIndexOf(QLatin1Char('}')) + 1; |
| 154 | value = value.left(value.lastIndexOf(QLatin1Char('}'))-1); |
| 155 | } |
| 156 | |
| 157 | return qMakePair( |
| 158 | KTextEditor::Range( |
| 159 | KTextEditor::Cursor(position.line(), col_offset - value.size() - key.size() + spacesAtCorner(key, +1) - 1), |
| 160 | KTextEditor::Cursor(position.line(), col_offset - value.size() - 1 + spacesAtCorner(key, -1)) |
| 161 | ), |
| 162 | KTextEditor::Range( |
| 163 | KTextEditor::Cursor(position.line(), col_offset - value.size() + spacesAtCorner(value, +1)), |
| 164 | KTextEditor::Cursor(position.line(), col_offset + spacesAtCorner(value, -1)) |
| 165 | )); |
| 166 | } |
| 167 | |
| 168 | QPair<QWidget*, KTextEditor::Range> KDevQmlJsPlugin::specialLanguageObjectNavigationWidget(const QUrl& url, const KTextEditor::Cursor& position) |
| 169 | { |