MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / replaceRange

Method replaceRange

src/plugins/codeeditor/gui/tabwidget.cpp:290–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290void TabWidgetPrivate::replaceRange(const QString &fileName, const newlsp::Range &range, const QString &text)
291{
292 auto editor = findEditor(fileName);
293 if (editor) {
294 editor->replaceRange(range.start.line, range.start.character,
295 range.end.line, range.end.character, text);
296 return;
297 }
298
299 // Modify the file directly
300 if (range.start.line != range.end.line) {
301 qWarning() << "Failed, The start line is inconsistent with the end line";
302 return;
303 }
304
305 QFile changeFile(fileName);
306 QString cacheData;
307 if (changeFile.open(QFile::ReadOnly)) {
308 int i = 0;
309 while (i != range.start.line) {
310 cacheData += changeFile.readLine();
311 i++;
312 }
313 QString changeLine = changeFile.readLine();
314 int removeLength = range.end.character - range.start.character;
315 changeLine = changeLine.replace(range.start.character, removeLength, text);
316 cacheData += changeLine;
317 QByteArray array = changeFile.readLine();
318 while (!array.isEmpty()) {
319 cacheData += array;
320 array = changeFile.readLine();
321 }
322 changeFile.close();
323 }
324
325 if (changeFile.open(QFile::WriteOnly | QFile::Truncate)) {
326 auto writeCount = changeFile.write(cacheData.toLatin1());
327 if (writeCount != cacheData.size()) {
328 qWarning() << "Failed, Write size does not match expectations."
329 << "Expectation: " << cacheData
330 << "Actual: " << writeCount;
331 }
332 changeFile.close();
333 }
334}
335
336void TabWidgetPrivate::doSave()
337{

Callers 8

handleAcceptMethod · 0.45
handleRejectMethod · 0.45
processGeneratedDataMethod · 0.45
applyWorkspaceEditMethod · 0.45
replaceTextMethod · 0.45
executeWithTextEditMethod · 0.45

Calls 15

findEditorMethod · 0.80
endsWithMethod · 0.80
beginUndoActionMethod · 0.80
endUndoActionMethod · 0.80
openMethod · 0.45
readLineMethod · 0.45
replaceMethod · 0.45
isEmptyMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45
sizeMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected