Skip to content

Commit

Permalink
Fix autowrap not setting effect properly
Browse files Browse the repository at this point in the history
  • Loading branch information
vadi2 committed Aug 6, 2022
1 parent 8098e73 commit 5bcc3fe
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/Host.cpp
Expand Up @@ -3991,3 +3991,12 @@ void Host::setCaretEnabled(bool enabled) {
mCaretEnabled = enabled;
mpConsole->setCaretMode(enabled);
}

bool Host::autoWrap() const {
return mAutoWrap;
}

void Host::setAutoWrap(bool enabled) {
mAutoWrap = enabled;
mpConsole->setAutoWrap(enabled);
}
9 changes: 6 additions & 3 deletions src/Host.h
Expand Up @@ -397,6 +397,8 @@ class Host : public QObject
void setEditorShowBidi(const bool);
bool caretEnabled() const;
void setCaretEnabled(bool enabled);
bool autoWrap() const;
void setAutoWrap(bool enabled);

cTelnet mTelnet;
QPointer<TMainConsole> mpConsole;
Expand Down Expand Up @@ -516,9 +518,7 @@ class Host : public QObject
bool mUSE_FORCE_LF_AFTER_PROMPT;
bool mUSE_IRE_DRIVER_BUGFIX;
bool mUSE_UNIX_EOL;
// automatically calculate wrapping?
bool mAutoWrap = true;
// or wrap at a specific amount of characters:
// wrap at a specific amount of characters if not autowrapping:
int mWrapAt;
// after wrapping a line, intent it by how many spaces:
int mWrapIndentCount;
Expand Down Expand Up @@ -719,6 +719,9 @@ private slots:
ActionUnit mActionUnit;
KeyUnit mKeyUnit;

// automatically calculate wrapping?
bool mAutoWrap = true;

QFile mErrorLogFile;

QMap<QString, TEvent*> mEventMap;
Expand Down
13 changes: 13 additions & 0 deletions src/TConsole.cpp
Expand Up @@ -2072,3 +2072,16 @@ void TConsole::setCaretMode(bool enabled)

mUpperPane->setFocus();
}

bool TConsole::autoWrap() const {
return mAutoWrap;
}

void TConsole::setAutoWrap(bool enabled) {
mAutoWrap = enabled;

if (enabled) {
mUpperPane->updateWrap();
mLowerPane->updateWrap();
}
}
3 changes: 3 additions & 0 deletions src/TConsole.h
Expand Up @@ -173,6 +173,8 @@ class TConsole : public QWidget
void hideEvent(QHideEvent* event) override;
void setConsoleBgColor(int, int, int, int);
QColor getConsoleBgColor() const { return mBgColor; }
bool autoWrap() const;
void setAutoWrap(bool enabled);

// Not used: void setConsoleFgColor(int, int, int);
std::list<int> getFgColor();
Expand Down Expand Up @@ -306,6 +308,7 @@ public slots:

ConsoleType mType = UnknownType;
QSize mOldSize;
bool mAutoWrap = true;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(TConsole::ConsoleType)
Expand Down
14 changes: 8 additions & 6 deletions src/TTextEdit.cpp
Expand Up @@ -129,9 +129,7 @@ TTextEdit::TTextEdit(TConsole* pC, QWidget* pW, TBuffer* pB, Host* pH, bool isLo

connect(mpHost, &Host::signal_changeIsAmbigousWidthGlyphsToBeWide, this, &TTextEdit::slot_changeIsAmbigousWidthGlyphsToBeWide, Qt::UniqueConnection);

if (mpHost->mAutoWrap) {
mpBuffer->setWrapAt(width() / mFontWidth);
}
updateWrap();
}

void TTextEdit::forceUpdate()
Expand Down Expand Up @@ -308,13 +306,17 @@ void TTextEdit::updateScreenView()
mScreenWidth = currentScreenWidth;
}

if (mpHost->mAutoWrap) {
mpBuffer->setWrapAt(mScreenWidth);
}
updateWrap();

mOldScrollPos = mpBuffer->getLastLineNumber();
}

void TTextEdit::updateWrap() {
if (mpConsole->autoWrap()) {
mpBuffer->setWrapAt(mScreenWidth);
}
}

void TTextEdit::showNewLines()
{
if (mIsLowerPane) {
Expand Down
1 change: 1 addition & 0 deletions src/TTextEdit.h
Expand Up @@ -97,6 +97,7 @@ class TTextEdit : public QWidget
void initializeCaret();
void setCaretPosition(int line, int column);
void updateCaret();
void updateWrap();

QColor mBgColor;
// position of cursor, in characters, across the entire buffer
Expand Down
2 changes: 1 addition & 1 deletion src/XMLexport.cpp
Expand Up @@ -426,7 +426,7 @@ void XMLexport::writeHost(Host* pHost, pugi::xml_node mudletPackage)
host.append_attribute("mHaveMapperScript") = pHost->mHaveMapperScript ? "yes" : "no";
host.append_attribute("mEditorAutoComplete") = pHost->mEditorAutoComplete ? "yes" : "no";
host.append_attribute("mEditorShowBidi") = pHost->getEditorShowBidi() ? "yes" : "no";
host.append_attribute("mAutoWrap") = pHost->mAutoWrap ? "yes" : "no";
host.append_attribute("mAutoWrap") = pHost->autoWrap() ? "yes" : "no";
host.append_attribute("mEditorTheme") = pHost->mEditorTheme.toUtf8().constData();
host.append_attribute("mEditorThemeFile") = pHost->mEditorThemeFile.toUtf8().constData();
host.append_attribute("mThemePreviewItemID") = QString::number(pHost->mThemePreviewItemID).toUtf8().constData();
Expand Down
5 changes: 4 additions & 1 deletion src/XMLimport.cpp
Expand Up @@ -883,7 +883,10 @@ void XMLimport::readHostPackage(Host* pHost)
pHost->setEditorShowBidi(true);
}
if (attributes().hasAttribute("mAutoWrap")) {
pHost->mAutoWrap = attributes().value(qsl("mAutoWrap")) == YES;
pHost->setAutoWrap(attributes().value(qsl("mAutoWrap")) == YES);
} else {
// keep existing behaviour of no autowrap for existing profiles
pHost->setAutoWrap(false);
}
if (attributes().hasAttribute("announceIncomingText")) {
pHost->mAnnounceIncomingText = attributes().value(qsl("announceIncomingText")) == YES;
Expand Down
4 changes: 2 additions & 2 deletions src/dlgProfilePreferences.cpp
Expand Up @@ -782,7 +782,7 @@ void dlgProfilePreferences::initWithHost(Host* pHost)
command_separator_lineedit->setText(pHost->mCommandSeparator);

checkBox_USE_IRE_DRIVER_BUGFIX->setChecked(pHost->mUSE_IRE_DRIVER_BUGFIX);
checkBox_autoWrap->setChecked(pHost->mAutoWrap);
checkBox_autoWrap->setChecked(pHost->autoWrap());
checkBox_enableTextAnalyzer->setChecked(pHost->mEnableTextAnalyzer);
checkBox_mUSE_FORCE_LF_AFTER_PROMPT->setChecked(pHost->mUSE_FORCE_LF_AFTER_PROMPT);
USE_UNIX_EOL->setChecked(pHost->mUSE_UNIX_EOL);
Expand Down Expand Up @@ -2626,7 +2626,7 @@ void dlgProfilePreferences::slot_save_and_exit()
pHost->mAcceptServerGUI = acceptServerGUI->isChecked();
pHost->mAcceptServerMedia = acceptServerMedia->isChecked();
pHost->set_USE_IRE_DRIVER_BUGFIX(checkBox_USE_IRE_DRIVER_BUGFIX->isChecked());
pHost->mAutoWrap = checkBox_autoWrap->isChecked();
pHost->setAutoWrap(checkBox_autoWrap->isChecked());
pHost->mEnableTextAnalyzer = checkBox_enableTextAnalyzer->isChecked();
pHost->mUSE_FORCE_LF_AFTER_PROMPT = checkBox_mUSE_FORCE_LF_AFTER_PROMPT->isChecked();
pHost->mUSE_UNIX_EOL = USE_UNIX_EOL->isChecked();
Expand Down

0 comments on commit 5bcc3fe

Please sign in to comment.