Commit 51e58e6d authored by Carlos Alves's avatar Carlos Alves Committed by Kurt Hindenburg
Browse files

Converts HistoryScrollFile to CompactHistoryScroll

When using unlimited history and change to fixed history size, it will
move, limited by the fixed size, the history.
It will create a new CompactHistoryScroll, get the lines from the old
HistoryScrollFile, and delete the old HistoryScrollFile structure.
parent 079a73d7
......@@ -11,6 +11,9 @@
using namespace Konsole;
// Reasonable line size
static const int LINE_SIZE = 1024;
CompactHistoryType::CompactHistoryType(unsigned int nbLines) :
_maxLines(nbLines)
{
......@@ -29,12 +32,34 @@ int CompactHistoryType::maximumLineCount() const
HistoryScroll *CompactHistoryType::scroll(HistoryScroll *old) const
{
if (old != nullptr) {
auto *oldBuffer = dynamic_cast<CompactHistoryScroll *>(old);
if (oldBuffer != nullptr) {
oldBuffer->setMaxNbLines(_maxLines);
return oldBuffer;
auto *newBuffer = dynamic_cast<CompactHistoryScroll *>(old);
if (newBuffer != nullptr) {
newBuffer->setMaxNbLines(_maxLines);
return newBuffer;
}
newBuffer = new CompactHistoryScroll(_maxLines);
Character line[LINE_SIZE];
int lines = old->getLines();
int i = qMax((lines - (int)_maxLines - 1), 0);
for (; i < lines; i++) {
int size = old->getLineLen(i);
if (size > LINE_SIZE) {
auto tmp_line = new Character[size];
old->getCells(i, 0, size, tmp_line);
newBuffer->addCells(tmp_line, size);
newBuffer->addLine(old->isWrappedLine(i));
delete[] tmp_line;
} else {
old->getCells(i, 0, size, line);
newBuffer->addCells(line, size);
newBuffer->addLine(old->isWrappedLine(i));
}
}
delete old;
return newBuffer;
}
return new CompactHistoryScroll(_maxLines);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment