| 160 | } |
| 161 | |
| 162 | void PatchHighlighter::markClicked( KTextEditor::Document* doc, const KTextEditor::Mark& mark, bool& handled ) { |
| 163 | if( handled || !(mark.type & m_allmarks) ) |
| 164 | return; |
| 165 | |
| 166 | auto range_diff = rangeForMark(mark); |
| 167 | m_applying = true; |
| 168 | |
| 169 | if (range_diff.first) { |
| 170 | handled = true; |
| 171 | |
| 172 | KTextEditor::MovingRange *&range = range_diff.first; |
| 173 | auto* const diff = range_diff.second; |
| 174 | |
| 175 | QString currentText = doc->text( range->toRange() ); |
| 176 | |
| 177 | removeLineMarker( range ); |
| 178 | |
| 179 | QString sourceText; |
| 180 | QString targetText; |
| 181 | |
| 182 | for( int a = 0; a < diff->sourceLineCount(); ++a ) { |
| 183 | sourceText += diff->sourceLineAt( a )->string(); |
| 184 | if (!sourceText.endsWith(QLatin1Char('\n'))) |
| 185 | sourceText += QLatin1Char('\n'); |
| 186 | } |
| 187 | |
| 188 | for( int a = 0; a < diff->destinationLineCount(); ++a ) { |
| 189 | targetText += diff->destinationLineAt( a )->string(); |
| 190 | if (!targetText.endsWith(QLatin1Char('\n'))) |
| 191 | targetText += QLatin1Char('\n'); |
| 192 | } |
| 193 | |
| 194 | bool applied = diff->applied(); |
| 195 | QString &replace(applied ? targetText : sourceText); |
| 196 | QString &replaceWith(applied ? sourceText : targetText); |
| 197 | |
| 198 | if( currentText.simplified() != replace.simplified() ) { |
| 199 | const QString messageText = i18n("Could not apply the change: Text should be \"%1\", but is \"%2\".", replace, currentText); |
| 200 | auto* message = new Sublime::Message(messageText, Sublime::Message::Error); |
| 201 | ICore::self()->uiController()->postMessage(message); |
| 202 | |
| 203 | m_applying = false; |
| 204 | return; |
| 205 | } |
| 206 | |
| 207 | diff->apply(!applied); |
| 208 | |
| 209 | KTextEditor::Cursor start = range->start().toCursor(); |
| 210 | range->document()->replaceText( range->toRange(), replaceWith ); |
| 211 | const uint replaceWithLines = replaceWith.count(QLatin1Char('\n')); |
| 212 | KTextEditor::Range newRange( start, KTextEditor::Cursor(start.line() + replaceWithLines, start.column()) ); |
| 213 | |
| 214 | range->setRange( newRange ); |
| 215 | |
| 216 | addLineMarker( range, diff ); |
| 217 | |
| 218 | { |
| 219 | // After applying the change, show the tooltip again, mainly to update an old tooltip |
nothing calls this directly
no test coverage detected