MCPcopy Create free account
hub / github.com/WheretIB/nullc / TakeSnapshot

Method TakeSnapshot

GUI/RichTextarea.cpp:359–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357 }
358 }
359 void TakeSnapshot(AreaLine *start, ChangeFlag changeFlag, unsigned int linesAffected, bool redo = false, bool clearRedo = true)
360 {
361 Snapshot *&lastShot = redo ? lastShotR : lastShotU;
362 AddSnapshotToList(redo);
363 // If snapshot is taken for undo, remove all redo snapshots (unless undo is made during redo)
364 if(clearRedo)
365 {
366 while(firstShotR)
367 {
368 Snapshot *next = firstShotR->nextShot;
369 delete firstShotR;
370 firstShotR = next;
371 }
372 firstShotR = lastShotR = NULL;
373 }
374 lastShot->dirty = true;
375 // Type of edit and lines affected by it
376 lastShot->type = changeFlag;
377 lastShot->lines = linesAffected;
378 // Save cursor position
379 lastShot->cursorX = data->cursorCharX;
380 lastShot->cursorY = data->cursorCharY;
381 // Save selection state
382 lastShot->selectStartX = data->dragStartX;
383 lastShot->selectStartY = data->dragStartY;
384 lastShot->selectEndX = data->dragEndX;
385 lastShot->selectEndY = data->dragEndY;
386 lastShot->selectionOn = data->selectionOn;
387
388 lastShot->first = NULL;
389 // Find the number of a line, where edit starts
390 lastShot->startLine = 0;
391 AreaLine *src = data->firstLine;
392 while(src != start)
393 {
394 src = src->next;
395 lastShot->startLine++;
396 }
397 // Copy affected lines to snapshot line list.
398 // (unless the edit creates a number of new lines, in which case we have to save only one)
399 AreaLine *curr = NULL;
400 for(unsigned int i = 0; i < (changeFlag == LINES_ADDED ? 1 : linesAffected); i++)
401 {
402 // Copy line
403 curr = InsertLineAfter(curr);
404 ExtendLine(curr, src->length);
405 memcpy(curr->data, src->data, src->length * sizeof(AreaChar));
406 curr->length = src->length;
407 curr->lineStyle = src->lineStyle;
408 curr->lineExtra = src->lineExtra;
409
410 // Set the first line, if not set
411 if(!lastShot->first)
412 lastShot->first = curr;
413 // Move to the next
414 src = src->next;
415 }
416 }

Callers 4

DeleteSelectionMethod · 0.80
DeletePreviousCharMethod · 0.80
OnPasteMethod · 0.80
OnCharacterMethod · 0.80

Calls 2

InsertLineAfterFunction · 0.85
ExtendLineFunction · 0.85

Tested by

no test coverage detected