forked from qt-creator/qt-creator
Utils: Create a reusable AnsiEscapeCodeHandler::setTextInEditor
Change-Id: Ic8ebe57287b08870e36e0a5cadbf3d322d14b2fe Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
35df237df2
commit
6471572135
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
|
||||||
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -268,6 +270,20 @@ void AnsiEscapeCodeHandler::endFormatScope()
|
|||||||
m_previousFormatClosed = true;
|
m_previousFormatClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnsiEscapeCodeHandler::setTextInEditor(QPlainTextEdit *editor, const QString &text)
|
||||||
|
{
|
||||||
|
AnsiEscapeCodeHandler handler;
|
||||||
|
const QList<FormattedText> formattedTextList = handler.parseText(FormattedText(text));
|
||||||
|
editor->clear();
|
||||||
|
QTextCursor cursor = editor->textCursor();
|
||||||
|
cursor.beginEditBlock();
|
||||||
|
for (const auto &formattedChunk : formattedTextList)
|
||||||
|
cursor.insertText(formattedChunk.text, formattedChunk.format);
|
||||||
|
cursor.endEditBlock();
|
||||||
|
cursor.movePosition(QTextCursor::Start);
|
||||||
|
editor->document()->setModified(false);
|
||||||
|
}
|
||||||
|
|
||||||
void AnsiEscapeCodeHandler::setFormatScope(const QTextCharFormat &charFormat)
|
void AnsiEscapeCodeHandler::setFormatScope(const QTextCharFormat &charFormat)
|
||||||
{
|
{
|
||||||
m_previousFormat = charFormat;
|
m_previousFormat = charFormat;
|
||||||
|
|||||||
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
#include <QTextCharFormat>
|
#include <QTextCharFormat>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QPlainTextEdit;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT FormattedText {
|
class QTCREATOR_UTILS_EXPORT FormattedText {
|
||||||
@@ -25,6 +29,7 @@ class QTCREATOR_UTILS_EXPORT AnsiEscapeCodeHandler
|
|||||||
public:
|
public:
|
||||||
QList<FormattedText> parseText(const FormattedText &input);
|
QList<FormattedText> parseText(const FormattedText &input);
|
||||||
void endFormatScope();
|
void endFormatScope();
|
||||||
|
static void setTextInEditor(QPlainTextEdit *editor, const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setFormatScope(const QTextCharFormat &charFormat);
|
void setFormatScope(const QTextCharFormat &charFormat);
|
||||||
|
|||||||
@@ -186,17 +186,7 @@ void GitEditorWidget::setPlainText(const QString &text)
|
|||||||
switch (contentType())
|
switch (contentType())
|
||||||
{
|
{
|
||||||
case LogOutput: {
|
case LogOutput: {
|
||||||
AnsiEscapeCodeHandler handler;
|
AnsiEscapeCodeHandler::setTextInEditor(this, text);
|
||||||
const QList<FormattedText> formattedTextList = handler.parseText(FormattedText(text));
|
|
||||||
|
|
||||||
clear();
|
|
||||||
QTextCursor cursor = textCursor();
|
|
||||||
cursor.beginEditBlock();
|
|
||||||
for (const auto &formattedChunk : formattedTextList)
|
|
||||||
cursor.insertText(formattedChunk.text, formattedChunk.format);
|
|
||||||
cursor.endEditBlock();
|
|
||||||
document()->setModified(false);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case AnnotateOutput:
|
case AnnotateOutput:
|
||||||
|
|||||||
Reference in New Issue
Block a user