Commit 2fc4e900 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Fix wrapping of commit messages



Remove trimmedDescription(), always trim. Extract trimmed text using the
text cursor
Reviewed-by: default avatarThorbjorn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent b789ffa9
...@@ -230,17 +230,34 @@ void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction * ...@@ -230,17 +230,34 @@ void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction *
} }
} }
QString SubmitEditorWidget::trimmedDescriptionText() const // Make sure we have one terminating NL
static inline QString trimMessageText(const QString &t)
{ {
// Make sure we have one terminating NL QString rc = t.trimmed();
QString text = descriptionText().trimmed(); rc += QLatin1Char('\n');
text += QLatin1Char('\n'); return rc;
return text; }
// Extract the wrapped text from a text edit, which performs
// the wrapping only optically.
static QString wrappedText(const QTextEdit *e)
{
const QChar newLine = QLatin1Char('\n');
QString rc;
QTextCursor cursor(e->document());
cursor.movePosition(QTextCursor::Start);
while (!cursor.atEnd()) {
cursor.select(QTextCursor::LineUnderCursor);
rc += cursor.selectedText();
rc += newLine;
cursor.movePosition(QTextCursor::Right);
}
return rc;
} }
QString SubmitEditorWidget::descriptionText() const QString SubmitEditorWidget::descriptionText() const
{ {
QString rc = m_d->m_ui.description->toPlainText(); QString rc = trimMessageText(lineWrap() ? wrappedText(m_d->m_ui.description) : m_d->m_ui.description->toPlainText());
// append field entries // append field entries
foreach(const SubmitEditorWidgetPrivate::FieldEntry &fe, m_d->m_fieldEntries) { foreach(const SubmitEditorWidgetPrivate::FieldEntry &fe, m_d->m_fieldEntries) {
const QString fieldText = fe.second->text().trimmed(); const QString fieldText = fe.second->text().trimmed();
......
...@@ -87,8 +87,6 @@ public: ...@@ -87,8 +87,6 @@ public:
QString descriptionText() const; QString descriptionText() const;
void setDescriptionText(const QString &text); void setDescriptionText(const QString &text);
// Should be used to normalize newlines.
QString trimmedDescriptionText() const;
int fileNameColumn() const; int fileNameColumn() const;
void setFileNameColumn(int c); void setFileNameColumn(int c);
......
...@@ -152,7 +152,7 @@ void PerforceSubmitEditor::updateEntries() ...@@ -152,7 +152,7 @@ void PerforceSubmitEditor::updateEntries()
const QString newLine = QString(QLatin1Char('\n')); const QString newLine = QString(QLatin1Char('\n'));
const QString tab = QString(QLatin1Char('\t')); const QString tab = QString(QLatin1Char('\t'));
QStringList lines = submitEditorWidget()->trimmedDescriptionText().split(newLine); QStringList lines = submitEditorWidget()->descriptionText().split(newLine);
while (lines.last().isEmpty()) while (lines.last().isEmpty())
lines.removeLast(); lines.removeLast();
// Description // Description
......
...@@ -391,7 +391,7 @@ bool VCSBaseSubmitEditor::save(const QString &fileName) ...@@ -391,7 +391,7 @@ bool VCSBaseSubmitEditor::save(const QString &fileName)
QString VCSBaseSubmitEditor::fileContents() const QString VCSBaseSubmitEditor::fileContents() const
{ {
return m_d->m_widget->trimmedDescriptionText(); return m_d->m_widget->descriptionText();
} }
bool VCSBaseSubmitEditor::setFileContents(const QString &contents) bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
......
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