forked from qt-creator/qt-creator
VCS: Make text wrapping independent of actual editor
Narrowing the submit editor down corrupts the commit message Also fixes the following cases: # comment that is wrapped to next line <-- this line currently appears comment in the middle of # wrapped line <-- this line currently disappears Change-Id: I7a35058569f002479c646ef6cfd1fdb1ada401c9 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6158a4ca58
commit
850276d9f9
@@ -279,38 +279,46 @@ void SubmitEditorWidget::unregisterActions(QAction *editorUndoAction, QAction *
|
|||||||
|
|
||||||
// Make sure we have one terminating NL. Do not trim front as leading space might be
|
// Make sure we have one terminating NL. Do not trim front as leading space might be
|
||||||
// required for some formattings.
|
// required for some formattings.
|
||||||
static inline QString trimMessageText(QString t)
|
void SubmitEditorWidget::trimDescription()
|
||||||
{
|
{
|
||||||
if (t.isEmpty())
|
if (d->m_description.isEmpty())
|
||||||
return t;
|
return;
|
||||||
// Trim back of string.
|
// Trim back of string.
|
||||||
const int last = t.size() - 1;
|
const int last = d->m_description.size() - 1;
|
||||||
int lastWordCharacter = last;
|
int lastWordCharacter = last;
|
||||||
for ( ; lastWordCharacter >= 0 && t.at(lastWordCharacter).isSpace() ; lastWordCharacter--) ;
|
for ( ; lastWordCharacter >= 0 && d->m_description.at(lastWordCharacter).isSpace() ; lastWordCharacter--) ;
|
||||||
if (lastWordCharacter != last)
|
if (lastWordCharacter != last)
|
||||||
t.truncate(lastWordCharacter + 1);
|
d->m_description.truncate(lastWordCharacter + 1);
|
||||||
t += QLatin1Char('\n');
|
d->m_description += QLatin1Char('\n');
|
||||||
return t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the wrapped text from a text edit, which performs
|
// Extract the wrapped text from a text edit, which performs
|
||||||
// the wrapping only optically.
|
// the wrapping only optically.
|
||||||
static QString wrappedText(const QTextEdit *e)
|
void SubmitEditorWidget::wrapDescription()
|
||||||
{
|
{
|
||||||
|
if (!lineWrap())
|
||||||
|
return;
|
||||||
const QChar newLine = QLatin1Char('\n');
|
const QChar newLine = QLatin1Char('\n');
|
||||||
QString rc;
|
QTextEdit e;
|
||||||
QTextCursor cursor(e->document());
|
e.setVisible(false);
|
||||||
|
e.setMinimumWidth(1000);
|
||||||
|
e.setFontPointSize(1.0);
|
||||||
|
e.setLineWrapColumnOrWidth(d->m_ui.description->lineWrapColumnOrWidth());
|
||||||
|
e.setLineWrapMode(d->m_ui.description->lineWrapMode());
|
||||||
|
e.setPlainText(d->m_description);
|
||||||
|
d->m_description.clear();
|
||||||
|
QTextCursor cursor(e.document());
|
||||||
cursor.movePosition(QTextCursor::Start);
|
cursor.movePosition(QTextCursor::Start);
|
||||||
while (!cursor.atEnd()) {
|
while (!cursor.atEnd()) {
|
||||||
const QString block = cursor.block().text();
|
const QString block = cursor.block().text();
|
||||||
if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap
|
if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap
|
||||||
rc += block + newLine;
|
d->m_description += block + newLine;
|
||||||
cursor.movePosition(QTextCursor::EndOfBlock);
|
cursor.movePosition(QTextCursor::EndOfBlock);
|
||||||
} else {
|
} else {
|
||||||
forever {
|
forever {
|
||||||
cursor.select(QTextCursor::LineUnderCursor);
|
cursor.select(QTextCursor::LineUnderCursor);
|
||||||
rc += cursor.selectedText();
|
d->m_description += cursor.selectedText();
|
||||||
rc += newLine;
|
d->m_description += newLine;
|
||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
if (cursor.atBlockEnd())
|
if (cursor.atBlockEnd())
|
||||||
break;
|
break;
|
||||||
@@ -319,7 +327,6 @@ static QString wrappedText(const QTextEdit *e)
|
|||||||
}
|
}
|
||||||
cursor.movePosition(QTextCursor::NextBlock);
|
cursor.movePosition(QTextCursor::NextBlock);
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SubmitEditorWidget::descriptionText() const
|
QString SubmitEditorWidget::descriptionText() const
|
||||||
@@ -551,12 +558,12 @@ void SubmitEditorWidget::hideDescription()
|
|||||||
|
|
||||||
void SubmitEditorWidget::descriptionTextChanged()
|
void SubmitEditorWidget::descriptionTextChanged()
|
||||||
{
|
{
|
||||||
QString rc = trimMessageText(lineWrap() ? wrappedText(d->m_ui.description) :
|
d->m_description = cleanupDescription(d->m_ui.description->toPlainText());
|
||||||
d->m_ui.description->toPlainText());
|
wrapDescription();
|
||||||
// append field entries
|
trimDescription();
|
||||||
foreach (const SubmitFieldWidget *fw, d->m_fieldWidgets)
|
foreach (const SubmitFieldWidget *fw, d->m_fieldWidgets)
|
||||||
rc += fw->fieldValues();
|
d->m_description += fw->fieldValues();
|
||||||
d->m_description = cleanupDescription(rc);
|
// append field entries
|
||||||
updateSubmitAction();
|
updateSubmitAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
bool hasSelection() const;
|
bool hasSelection() const;
|
||||||
int checkedFilesCount() const;
|
int checkedFilesCount() const;
|
||||||
|
void wrapDescription();
|
||||||
|
void trimDescription();
|
||||||
|
|
||||||
SubmitEditorWidgetPrivate *d;
|
SubmitEditorWidgetPrivate *d;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user