forked from qt-creator/qt-creator
Fix wrapping of commit messages
Remove trimmedDescription(), always trim. Extract trimmed text using the text cursor Reviewed-by: Thorbjorn Lindeijer <thorbjorn.lindeijer@nokia.com>
This commit is contained in:
@@ -230,17 +230,34 @@ void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction *
|
||||
}
|
||||
}
|
||||
|
||||
QString SubmitEditorWidget::trimmedDescriptionText() const
|
||||
{
|
||||
// Make sure we have one terminating NL
|
||||
QString text = descriptionText().trimmed();
|
||||
text += QLatin1Char('\n');
|
||||
return text;
|
||||
static inline QString trimMessageText(const QString &t)
|
||||
{
|
||||
QString rc = t.trimmed();
|
||||
rc += QLatin1Char('\n');
|
||||
return rc;
|
||||
}
|
||||
|
||||
// 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 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
|
||||
foreach(const SubmitEditorWidgetPrivate::FieldEntry &fe, m_d->m_fieldEntries) {
|
||||
const QString fieldText = fe.second->text().trimmed();
|
||||
|
||||
@@ -87,8 +87,6 @@ public:
|
||||
|
||||
QString descriptionText() const;
|
||||
void setDescriptionText(const QString &text);
|
||||
// Should be used to normalize newlines.
|
||||
QString trimmedDescriptionText() const;
|
||||
|
||||
int fileNameColumn() const;
|
||||
void setFileNameColumn(int c);
|
||||
|
||||
@@ -152,7 +152,7 @@ void PerforceSubmitEditor::updateEntries()
|
||||
const QString newLine = QString(QLatin1Char('\n'));
|
||||
const QString tab = QString(QLatin1Char('\t'));
|
||||
|
||||
QStringList lines = submitEditorWidget()->trimmedDescriptionText().split(newLine);
|
||||
QStringList lines = submitEditorWidget()->descriptionText().split(newLine);
|
||||
while (lines.last().isEmpty())
|
||||
lines.removeLast();
|
||||
// Description
|
||||
|
||||
@@ -391,7 +391,7 @@ bool VCSBaseSubmitEditor::save(const QString &fileName)
|
||||
|
||||
QString VCSBaseSubmitEditor::fileContents() const
|
||||
{
|
||||
return m_d->m_widget->trimmedDescriptionText();
|
||||
return m_d->m_widget->descriptionText();
|
||||
}
|
||||
|
||||
bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
|
||||
|
||||
Reference in New Issue
Block a user