Commit 48aef6ab authored by Carlos Alves's avatar Carlos Alves
Browse files

Added profile option to enable/disable reflow

As pointed in bug report 196998, some people don't want to use it.
It is in scroolling group.
parent bc2b89c2
......@@ -55,6 +55,7 @@ Screen::Screen(int lines, int columns):
_droppedLines(0),
_oldTotalLines(0),
_isResize(false),
_enableReflowLines(false),
_lineProperties(QVarLengthArray<LineProperty, 64>()),
_history(new HistoryScrollNone()),
_cuX(0),
......@@ -383,6 +384,11 @@ bool Screen::isResize()
return _isResize;
}
void Screen::setReflowLines(bool enable)
{
_enableReflowLines = enable;
}
// Not to production auxiliar functions to show what is written in screen or history
void toDebug(const Character s[], int count, bool wrapped = false) {
QString out;
......@@ -428,7 +434,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
int currentPos;
// Check if _history need to change
if (new_columns != _columns && _history->getLines() && _history->getMaxLines()) {
if (_enableReflowLines && new_columns != _columns && _history->getLines() && _history->getMaxLines()) {
// Join next line from _screenLine to _history
while (_history->isWrappedLine(_history->getLines() - 1)) {
fastAddHistLine();
......@@ -436,7 +442,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
// Join everything in _history
currentPos = 0;
while (currentPos < _history->getLines() - 1 && currentPos < _history->getMaxLines()) {
while (currentPos < _history->getLines() - 1) {
// if it's true, join the line with next line
if (_history->isWrappedLine(currentPos)) {
int curr_linelen = _history->getLineLen(currentPos);
......@@ -458,7 +464,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
// Now move data to next line if needed
currentPos = 0;
while (currentPos < _history->getLines() && currentPos < _history->getMaxLines()) {
while (currentPos < _history->getLines()) {
int curr_linelen = _history->getLineLen(currentPos);
// if the current line > new_columns it will need a new line
......@@ -487,67 +493,70 @@ void Screen::resizeImage(int new_lines, int new_columns)
}
}
// Join everything in screenLines.
currentPos = 0;
while (currentPos < cursorLine && currentPos < _screenLines.count() - 1) {
// if the line have the 'LINE_WRAPPED' property, concat with the next line and remove it.
if ((_lineProperties[currentPos] & LINE_WRAPPED) != 0) {
_screenLines[currentPos].append(_screenLines[currentPos + 1]);
_screenLines.remove(currentPos + 1);
_lineProperties.remove(currentPos);
cursorLine--;
continue;
}
currentPos++;
}
// Then move the data to lines below.
currentPos = 0;
while (currentPos < cursorLine && currentPos < _screenLines.count()) {
// Ignore whitespaces at the end of the line
int lineSize = _screenLines[currentPos].size();
while (lineSize > 0 && QChar(_screenLines[currentPos][lineSize - 1].character).isSpace()) {
lineSize--;
if (_enableReflowLines) {
// Join everything in screenLines.
currentPos = 0;
while (currentPos < cursorLine && currentPos < _screenLines.count() - 1) {
// if the line have the 'LINE_WRAPPED' property, concat with the next line and remove it.
if ((_lineProperties[currentPos] & LINE_WRAPPED) != 0) {
_screenLines[currentPos].append(_screenLines[currentPos + 1]);
_screenLines.remove(currentPos + 1);
_lineProperties.remove(currentPos);
cursorLine--;
continue;
}
currentPos++;
}
const bool shouldCopy = lineSize > new_columns;
// Copy from the current line, to the next one.
if (shouldCopy) {
auto values = _screenLines[currentPos].mid(new_columns);
_screenLines[currentPos].remove(new_columns, values.size());
_lineProperties.insert(currentPos + 1, _lineProperties[currentPos]);
_screenLines.insert(currentPos + 1, values);
_lineProperties[currentPos] |= LINE_WRAPPED;
cursorLine++;
// Then move the data to lines below.
currentPos = 0;
while (currentPos < cursorLine && currentPos < _screenLines.count()) {
// Ignore whitespaces at the end of the line
int lineSize = _screenLines[currentPos].size();
while (lineSize > 0 && QChar(_screenLines[currentPos][lineSize - 1].character).isSpace()) {
lineSize--;
}
const bool shouldCopy = lineSize > new_columns;
// Copy from the current line, to the next one.
if (shouldCopy) {
auto values = _screenLines[currentPos].mid(new_columns);
_screenLines[currentPos].remove(new_columns, values.size());
_lineProperties.insert(currentPos + 1, _lineProperties[currentPos]);
_screenLines.insert(currentPos + 1, values);
_lineProperties[currentPos] |= LINE_WRAPPED;
cursorLine++;
}
currentPos += 1;
}
currentPos += 1;
}
// Check if it need to move from _screenLine to _history
while (cursorLine > new_lines - 1) {
cursorLine--;
if (!_history->getMaxLines()) {
if (!_enableReflowLines || !_history->getMaxLines()) {
addHistLine();
// _lastPos = loc(_cuX, cursorLine);
// scrollUp(0, 1);
_screenLines.pop_front();
_lineProperties.remove(0);
} else {
fastAddHistLine();
}
}
// Check cursor position and send from _history to _screenLines
ImageLine histLine;
histLine.reserve(1024);
while (cursorLine < oldCursorLine && _history->getLines()) {
int histPos = _history->getLines() - 1;
int histLineLen = _history->getLineLen(histPos);
int isWrapped = _history->isWrappedLine(histPos) ? LINE_WRAPPED : LINE_DEFAULT;
histLine.resize(histLineLen);
_history->getCells(histPos, 0, histLineLen, histLine.data());
_screenLines.insert(0, histLine);
_lineProperties.insert(0, isWrapped);
_history->removeCells(histPos);
cursorLine++;
if (_enableReflowLines) {
// Check cursor position and send from _history to _screenLines
ImageLine histLine;
histLine.reserve(1024);
while (cursorLine < oldCursorLine && _history->getLines()) {
int histPos = _history->getLines() - 1;
int histLineLen = _history->getLineLen(histPos);
int isWrapped = _history->isWrappedLine(histPos) ? LINE_WRAPPED : LINE_DEFAULT;
histLine.resize(histLineLen);
_history->getCells(histPos, 0, histLineLen, histLine.data());
_screenLines.insert(0, histLine);
_lineProperties.insert(0, isWrapped);
_history->removeCells(histPos);
cursorLine++;
}
}
_lineProperties.resize(new_lines + 1);
......@@ -1651,7 +1660,7 @@ void Screen::addHistLine()
hist_linelen += _screenLines[0].count();
// After join, check if it needs new line in history to show it on scroll
if (_history->getMaxLines() && hist_linelen > _columns) {
if (_enableReflowLines && _history->getMaxLines() && hist_linelen > _columns) {
_history->setCellsAt(oldHistLines - 1, hist_line, _columns);
_history->setLineAt(oldHistLines - 1, true);
_history->addCells(hist_line + _columns, hist_linelen - _columns);
......
......@@ -593,6 +593,8 @@ public:
int getOldTotalLines();
// Return if it was a resize signal (fix scroll glitch)
bool isResize();
// Set reflow condition
void setReflowLines(bool enable);
private:
//copies a line of text from the screen or history into a stream using a
......@@ -676,6 +678,7 @@ private:
int _oldTotalLines;
bool _isResize;
bool _enableReflowLines;
QVarLengthArray<LineProperty, 64> _lineProperties;
......
......@@ -83,6 +83,7 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = {
, { ScrollBarPosition , "ScrollBarPosition" , SCROLLING_GROUP , QVariant::Int }
, { ScrollFullPage , "ScrollFullPage" , SCROLLING_GROUP , QVariant::Bool }
, { HighlightScrolledLines , "HighlightScrolledLines" , SCROLLING_GROUP , QVariant::Bool }
, { ReflowLines , "ReflowLines" , SCROLLING_GROUP , QVariant::Bool }
// Terminal Features
, { UrlHintsModifiers , "UrlHintsModifiers" , TERMINAL_GROUP , QVariant::Int }
......@@ -187,6 +188,7 @@ void Profile::useFallback()
setProperty(ScrollBarPosition, Enum::ScrollBarRight);
setProperty(ScrollFullPage, false);
setProperty(HighlightScrolledLines, true);
setProperty(ReflowLines, true);
setProperty(FlowControlEnabled, true);
setProperty(UrlHintsModifiers, 0);
......
......@@ -147,6 +147,10 @@ public:
/** (bool) Specifies whether the terminal will enable Bidirectional
* text display
*/
ReflowLines,
/** (bool) Specifies whether the terminal will enable Reflow of
* lines when terminal resizes.
*/
BidiRenderingEnabled,
/** (bool) Specifies whether text in terminal displays is allowed
* to blink.
......
......@@ -290,6 +290,7 @@ void SessionManager::applyProfile(Session *session, const Profile::Ptr &profile,
for (TerminalDisplay *view : session->views()) {
view->screenWindow()->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
view->screenWindow()->screen()->setReflowLines(profile->property<bool>(Profile::ReflowLines));
}
}
......
......@@ -139,6 +139,7 @@ void TerminalDisplay::setScreenWindow(ScreenWindow* window)
auto profile = SessionManager::instance()->sessionProfile(_sessionController->session());
_screenWindow->screen()->urlExtractor()->setAllowedLinkSchema(profile->escapedLinksSchema());
_screenWindow->screen()->setReflowLines(profile->property<bool>(Profile::ReflowLines));
}
}
......@@ -2860,6 +2861,9 @@ void TerminalDisplay::applyProfile(const Profile::Ptr &profile)
// highlight lines scrolled into view (must be applied before margin/center)
_scrollBar->setHighlightScrolledLines(profile->property<bool>(Profile::HighlightScrolledLines));
// reflow lines when terminal resizes
//_screenWindow->screen()->setReflow(profile->property<bool>(Profile::ReflowLines));
// margin/center
setMargin(profile->property<int>(Profile::TerminalMargin));
setCenterContents(profile->property<bool>(Profile::TerminalCenter));
......
......@@ -1627,6 +1627,9 @@ void EditProfileDialog::setupScrollingPage(const Profile::Ptr &profile)
_scrollingUi->highlightScrolledLinesButton->setChecked(profile->property<bool>(Profile::HighlightScrolledLines));
connect(_scrollingUi->highlightScrolledLinesButton, &QPushButton::clicked, this, &EditProfileDialog::toggleHighlightScrolledLines);
_scrollingUi->reflowLinesButton->setChecked(profile->property<bool>(Profile::ReflowLines));
connect(_scrollingUi->reflowLinesButton, &QPushButton::clicked, this, &EditProfileDialog::toggleReflowLines);
// signals and slots
connect(_scrollingUi->historySizeWidget, &Konsole::HistorySizeWidget::historySizeChanged, this,
&Konsole::EditProfileDialog::historySizeChanged);
......@@ -1657,6 +1660,11 @@ void EditProfileDialog::toggleHighlightScrolledLines(bool enable)
updateTempProfileProperty(Profile::HighlightScrolledLines, enable);
}
void EditProfileDialog::toggleReflowLines(bool enable)
{
updateTempProfileProperty(Profile::ReflowLines, enable);
}
void EditProfileDialog::setupMousePage(const Profile::Ptr &profile)
{
_mouseUi->underlineLinksButton->setChecked(profile->property<bool>(Profile::UnderlineLinksEnabled));
......
......@@ -164,6 +164,7 @@ private Q_SLOTS:
void scrollFullPage();
void scrollHalfPage();
void toggleHighlightScrolledLines(bool enable);
void toggleReflowLines(bool enable);
// keyboard page
void editKeyBinding();
......
......@@ -228,6 +228,29 @@
</property>
</widget>
</item>
<item row="10" column="0" alignment="Qt::AlignRight|Qt::AlignVCenter">
<widget class="QLabel" name="labelReflowLines">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Reflow Lines:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="reflowLinesButton">
<property name="text">
<string>Reflow lines when terminal resizes</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
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