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

Method HistoryStep

GUI/RichTextarea.cpp:428–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426 }
427
428 void HistoryStep(bool redo)
429 {
430 Snapshot *&firstShot = redo ? firstShotR : firstShotU;
431 Snapshot *&lastShot = redo ? lastShotR : lastShotU;
432 // If there are no snapshots, exit
433 if(!lastShot)
434 return;
435
436 // Set currLine to the old one
437 data->currLine = data->firstLine;
438 for(unsigned int i = 0; i < lastShot->startLine; i++)
439 data->currLine = data->currLine->next;
440
441 // Take a redo snapshot
442 TakeSnapshot(data->currLine, lastShot->type == LINES_ADDED ? LINES_DELETED : (lastShot->type == LINES_DELETED ? LINES_ADDED : LINES_CHANGED), lastShot->type == LINES_ADDED ? lastShot->lines + 1 : (lastShot->type == LINES_DELETED ? lastShot->lines - 1 : lastShot->lines), !redo, false);
443
444 // Disable selection
445 data->selectionOn = false;
446
447 // Restore cursor position
448 data->cursorCharX = lastShot->cursorX;
449 data->cursorCharY = lastShot->cursorY;
450 // Restore selection state
451 data->dragStartX = lastShot->selectStartX;
452 data->dragStartY = lastShot->selectStartY;
453 data->dragEndX = lastShot->selectEndX;
454 data->dragEndY = lastShot->selectEndY;
455 data->selectionOn = lastShot->selectionOn;
456
457 // Copy previous contents of current line
458 ExtendLine(data->currLine, lastShot->first->length);
459 memcpy(data->currLine->data, lastShot->first->data, lastShot->first->length * sizeof(AreaChar));
460 data->currLine->length = lastShot->first->length;
461 // If lines were added by edit, remove them
462 if(lastShot->type == LINES_ADDED)
463 {
464 data->lineCount -= lastShot->lines;
465 for(unsigned int i = 0; i < lastShot->lines; i++)
466 DeleteLine(data->currLine->next);
467 }else if(lastShot->type == LINES_DELETED){ // If lines were deleted by edit, restore them
468 AreaLine *curr = lastShot->first->next;
469 data->lineCount += lastShot->lines - 1;
470 for(unsigned int i = 0; i < lastShot->lines-1; i++)
471 {
472 data->currLine = InsertLineAfter(data->currLine);
473 ExtendLine(data->currLine, curr->length);
474 memcpy(data->currLine->data, curr->data, curr->length * sizeof(AreaChar));
475 data->currLine->length = curr->length;
476 data->currLine->lineStyle = curr->lineStyle;
477 data->currLine->lineExtra = curr->lineExtra;
478 curr = curr->next;
479 }
480 }
481
482 // Remove snapshot
483 if(lastShot->prevShot)
484 {
485 lastShot = lastShot->prevShot;

Callers

nothing calls this directly

Calls 3

ExtendLineFunction · 0.85
DeleteLineFunction · 0.85
InsertLineAfterFunction · 0.85

Tested by

no test coverage detected