Commit 9e745ea5 authored by Carlos Alves's avatar Carlos Alves Committed by Kurt Hindenburg
Browse files

Reflow unlimited scroll lines

Reflow the unlimited scroll lines with no limits.
parent e4a0c208
......@@ -55,6 +55,7 @@ public:
virtual void setCellsAt(int position, const Character a[], int count) = 0;
virtual void setCellsVectorAt(int position, const QVector<Character> &cells) = 0;
virtual void setLineAt(int position, bool previousWrapped) = 0;
virtual int reflowLines(int columns) = 0;
//
// FIXME: Passing around constant references to HistoryType instances
......
......@@ -35,7 +35,7 @@ int HistoryScrollFile::getLines()
int HistoryScrollFile::getMaxLines()
{
return 0;
return getLines();
}
int HistoryScrollFile::getLineLen(int lineno)
......@@ -123,6 +123,63 @@ void HistoryScrollFile::setCellsVectorAt(int, const QVector<Character> &)
{
}
int HistoryScrollFile::reflowLines(int columns)
{
HistoryFile *reflowFile = new HistoryFile;
reflowData newLine;
auto reflowLineLen = [] (qint64 start, qint64 end) {
return (int)((end - start) / sizeof(Character));
};
auto setNewLine = [] (reflowData &change, qint64 index, bool lineflag) {
change.index = index;
change.lineFlag = lineflag;
};
// First all changes are saved on an auxiliary file, no real index is changed
int currentPos = 0;
while (currentPos < getLines()) {
qint64 startLine = startOfLine(currentPos);
qint64 endLine = startOfLine(currentPos + 1);
// Join the lines if they are wrapped
while (isWrappedLine(currentPos)) {
currentPos++;
endLine = startOfLine(currentPos + 1);
}
// Now reflow the lines
while (reflowLineLen(startLine, endLine) > columns) {
startLine += (qint64)columns * sizeof(Character);
setNewLine(newLine, startLine, true);
reflowFile->add(reinterpret_cast<const char *>(&newLine), sizeof(reflowData));
}
setNewLine(newLine, endLine, false);
reflowFile->add(reinterpret_cast<const char *>(&newLine), sizeof(reflowData));
currentPos++;
}
// Erase data from index and flag data
_index.removeLast(0);
_lineflags.removeLast(0);
// Now save the new indexes and properties to proper files
int totalLines = reflowFile->len() / sizeof(reflowData);
currentPos = 0;
while (currentPos < totalLines) {
reflowFile->get(reinterpret_cast<char *>(&newLine), sizeof(reflowData), currentPos * sizeof(reflowData));
_index.add(reinterpret_cast<char *>(&newLine.index), sizeof(qint64));
unsigned char flags = newLine.lineFlag ? 0x01 : 0x00;
_lineflags.add(reinterpret_cast<char *>(&flags), sizeof(char));
currentPos++;
}
delete reflowFile;
return 0;
}
void HistoryScrollFile::setLineAt(int, bool previousWrapped)
{
qint64 locn = qMax(0, getLines() - 1);
......
......@@ -35,12 +35,14 @@ public:
void addCells(const Character text[], int count) override;
void addLine(bool previousWrapped = false) override;
// Modify history
void insertCellsVector(int position, const QVector<Character> &cells) override;
void insertCells(int position, const Character a[], int count) override;
void removeCells(int position) override;
void setCellsAt(int position, const Character a[], int count) override;
void setCellsVectorAt(int position, const QVector<Character> &cells) override;
void setLineAt(int position, bool previousWrapped) override;
int reflowLines(int columns) override;
private:
qint64 startOfLine(int lineno);
......@@ -48,6 +50,11 @@ private:
HistoryFile _index; // lines Row(qint64)
HistoryFile _cells; // text Row(Character)
HistoryFile _lineflags; // flags Row(unsigned char)
struct reflowData { // data to reflow lines
qint64 index;
bool lineFlag;
};
};
}
......
......@@ -77,6 +77,11 @@ void HistoryScrollNone::setCellsVectorAt(int , const QVector<Character> &)
{
}
int HistoryScrollNone::reflowLines(int)
{
return 0;
}
void HistoryScrollNone::setLineAt(int , bool)
{
}
\ No newline at end of file
}
......@@ -34,12 +34,14 @@ public:
void addCells(const Character a[], int count) override;
void addLine(bool previousWrapped = false) override;
// Modify history (do nothing here)
void insertCellsVector(int position, const QVector<Character> &cells) override;
void insertCells(int position, const Character a[], int count) override;
void removeCells(int position) override;
void setCellsAt(int position, const Character a[], int count) override;
void setCellsVectorAt(int position, const QVector<Character> &cells) override;
void setLineAt(int position, bool previousWrapped) override;
int reflowLines(int) override;
};
}
......
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