Skip to content

Commit

Permalink
fix: draft modify codec.
Browse files Browse the repository at this point in the history
Change-Id: Ic19dafabeed5c08e9dffb25035be0ee317c0b6a6
  • Loading branch information
rekols committed Dec 5, 2018

Verified

This commit was signed with the committer’s verified signature.
tevincent Vincent TE
1 parent 53e7453 commit 182cb4e
Showing 2 changed files with 26 additions and 6 deletions.
31 changes: 26 additions & 5 deletions src/editwrapper.cpp
Original file line number Diff line number Diff line change
@@ -148,14 +148,10 @@ void EditWrapper::updatePath(const QString &file)

void EditWrapper::refresh()
{
if (filePath().isEmpty()) {
if (filePath().isEmpty() || Utils::isDraftFile(filePath())) {
return;
}

if (Utils::isDraftFile(filePath())) {
saveFile();
}

QFile file(filePath());
int curPos = m_textEdit->textCursor().position();
int yoffset = m_textEdit->verticalScrollBar()->value();
@@ -199,6 +195,31 @@ void EditWrapper::setTextCodec(QTextCodec *codec)
{
m_textCodec = codec;

QFile file(filePath());
int curPos = m_textEdit->textCursor().position();
int yoffset = m_textEdit->verticalScrollBar()->value();
int xoffset = m_textEdit->horizontalScrollBar()->value();
m_textEdit->setPlainText(QString());

if (file.open(QIODevice::ReadOnly)) {
QTextStream out(&file);
out.setCodec(codec);
QString content = out.readAll();

m_textEdit->setUpdatesEnabled(false);
m_textEdit->setPlainText(content);
m_textEdit->setModified(false);

QTextCursor textcur = m_textEdit->textCursor();
textcur.setPosition(curPos);
m_textEdit->setTextCursor(textcur);
m_textEdit->verticalScrollBar()->setValue(yoffset);
m_textEdit->horizontalScrollBar()->setValue(xoffset);
m_textEdit->setUpdatesEnabled(true);

file.close();
}

// TODO: enforce bom for some encodings
}

1 change: 0 additions & 1 deletion src/widgets/bottombar.cpp
Original file line number Diff line number Diff line change
@@ -78,7 +78,6 @@ void BottomBar::handleEncodeChanged(const QString &name)
QFontMetrics fm(m_encodeComboBox->font());
m_encodeComboBox->setFixedWidth(fm.width(name) + 30);
m_wrapper->setTextCodec(QTextCodec::codecForName(name.toUtf8()));
m_wrapper->refresh();
}

void BottomBar::paintEvent(QPaintEvent *e)

0 comments on commit 182cb4e

Please sign in to comment.