forked from qt-creator/qt-creator
UnifiedDiffEditor: Move polishing selections into working thread
In case of big commit (like 05c35356ab)
polishing selections took about 200 ms. Move this work into
thread to avoid extra 200 ms freeze of GUI thread.
Change-Id: If159e3f0869264f467c4c015f944a3054609f812
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -20,6 +20,11 @@ SelectableTextEditorWidget::SelectableTextEditorWidget(Utils::Id id, QWidget *pa
|
||||
|
||||
SelectableTextEditorWidget::~SelectableTextEditorWidget() = default;
|
||||
|
||||
void SelectableTextEditorWidget::setSelections(const DiffSelections &selections)
|
||||
{
|
||||
m_diffSelections = selections;
|
||||
}
|
||||
|
||||
static QList<DiffSelection> subtractSelection(
|
||||
const DiffSelection &minuendSelection,
|
||||
const DiffSelection &subtrahendSelection)
|
||||
@@ -49,9 +54,9 @@ static QList<DiffSelection> subtractSelection(
|
||||
return diffList;
|
||||
}
|
||||
|
||||
void SelectableTextEditorWidget::setSelections(const QMap<int, QList<DiffSelection> > &selections)
|
||||
DiffSelections SelectableTextEditorWidget::polishedSelections(const DiffSelections &selections)
|
||||
{
|
||||
m_diffSelections.clear();
|
||||
DiffSelections polishedSelections;
|
||||
for (auto it = selections.cbegin(), end = selections.cend(); it != end; ++it) {
|
||||
const QList<DiffSelection> diffSelections = it.value();
|
||||
QList<DiffSelection> workingList;
|
||||
@@ -72,8 +77,9 @@ void SelectableTextEditorWidget::setSelections(const QMap<int, QList<DiffSelecti
|
||||
}
|
||||
workingList.append(diffSelection);
|
||||
}
|
||||
m_diffSelections.insert(it.key(), workingList);
|
||||
polishedSelections.insert(it.key(), workingList);
|
||||
}
|
||||
return polishedSelections;
|
||||
}
|
||||
|
||||
void SelectableTextEditorWidget::setFoldingIndent(const QTextBlock &block, int indent)
|
||||
|
||||
@@ -20,14 +20,20 @@ public:
|
||||
QTextCharFormat *format = nullptr;
|
||||
};
|
||||
|
||||
// block number, list of ranges
|
||||
// DiffSelection.start - can be -1 (continues from the previous line)
|
||||
// DiffSelection.end - can be -1 (spans to the end of line, even after the last character in line)
|
||||
using DiffSelections = QMap<int, QList<DiffSelection>>;
|
||||
|
||||
class SelectableTextEditorWidget : public TextEditor::TextEditorWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SelectableTextEditorWidget(Utils::Id id, QWidget *parent = nullptr);
|
||||
~SelectableTextEditorWidget() override;
|
||||
void setSelections(const QMap<int, QList<DiffSelection> > &selections);
|
||||
void setSelections(const DiffSelections &selections);
|
||||
|
||||
static DiffSelections polishedSelections(const DiffSelections &selections);
|
||||
static void setFoldingIndent(const QTextBlock &block, int indent);
|
||||
|
||||
private:
|
||||
@@ -37,10 +43,7 @@ private:
|
||||
const QVector<QTextLayout::FormatRange> &selections,
|
||||
const QRect &clipRect) const override;
|
||||
|
||||
// block number, list of ranges
|
||||
// DiffSelection.start - can be -1 (continues from the previous line)
|
||||
// DiffSelection.end - can be -1 (spans to the end of line, even after the last character in line)
|
||||
QMap<int, QList<DiffSelection> > m_diffSelections;
|
||||
DiffSelections m_diffSelections;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -353,7 +353,7 @@ void SideDiffEditorWidget::clearAll(const QString &message)
|
||||
void SideDiffEditorWidget::clearAllData()
|
||||
{
|
||||
m_data = {};
|
||||
setSelections(QMap<int, QList<DiffSelection>>());
|
||||
setSelections({});
|
||||
}
|
||||
|
||||
void SideDiffEditorWidget::scrollContentsBy(int dx, int dy)
|
||||
@@ -844,8 +844,8 @@ void SideBySideDiffEditorWidget::restoreState()
|
||||
|
||||
void SideBySideDiffEditorWidget::showDiff()
|
||||
{
|
||||
QMap<int, QList<DiffSelection>> leftFormats;
|
||||
QMap<int, QList<DiffSelection>> rightFormats;
|
||||
DiffSelections leftFormats;
|
||||
DiffSelections rightFormats;
|
||||
|
||||
SideDiffData leftData;
|
||||
SideDiffData rightData;
|
||||
@@ -1001,8 +1001,8 @@ void SideBySideDiffEditorWidget::showDiff()
|
||||
for (int b = 0; block.isValid(); block = block.next(), ++b)
|
||||
SelectableTextEditorWidget::setFoldingIndent(block, foldingIndent.value(b, 3));
|
||||
|
||||
m_leftEditor->setSelections(leftFormats);
|
||||
m_rightEditor->setSelections(rightFormats);
|
||||
m_leftEditor->setSelections(SelectableTextEditorWidget::polishedSelections(leftFormats));
|
||||
m_rightEditor->setSelections(SelectableTextEditorWidget::polishedSelections(rightFormats));
|
||||
}
|
||||
|
||||
void SideBySideDiffEditorWidget::setFontSettings(
|
||||
|
||||
@@ -301,7 +301,7 @@ void UnifiedDiffEditorWidget::setDiff(const QList<FileData> &diffFileList)
|
||||
|
||||
QString UnifiedDiffData::setChunk(const DiffEditorInput &input, const ChunkData &chunkData,
|
||||
bool lastChunk, int *blockNumber, int *charNumber,
|
||||
QMap<int, QList<DiffSelection>> *selections)
|
||||
DiffSelections *selections)
|
||||
{
|
||||
if (chunkData.contextChunk)
|
||||
return QString();
|
||||
@@ -537,6 +537,7 @@ UnifiedDiffOutput UnifiedDiffData::setDiff(QFutureInterface<void> &fi, int progr
|
||||
}
|
||||
|
||||
output.diffText.replace('\r', ' ');
|
||||
output.selections = SelectableTextEditorWidget::polishedSelections(output.selections);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -568,7 +569,6 @@ void UnifiedDiffEditorWidget::showDiff()
|
||||
for (int b = 0; block.isValid(); block = block.next(), ++b)
|
||||
setFoldingIndent(block, result.foldingIndent.value(b, 3));
|
||||
}
|
||||
// TODO: this could probably be done in thread, too
|
||||
setSelections(result.selections);
|
||||
}
|
||||
m_watcher.release()->deleteLater();
|
||||
|
||||
@@ -33,8 +33,7 @@ public:
|
||||
// value where 1 indicates start of new file and 2 indicates a diff chunk.
|
||||
// Remaining lines (diff contents) are assigned 3.
|
||||
QHash<int, int> foldingIndent;
|
||||
|
||||
QMap<int, QList<DiffSelection>> selections;
|
||||
DiffSelections selections;
|
||||
};
|
||||
|
||||
class UnifiedDiffData
|
||||
@@ -59,7 +58,7 @@ private:
|
||||
void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex);
|
||||
QString setChunk(const DiffEditorInput &input, const ChunkData &chunkData, bool lastChunk,
|
||||
int *blockNumber, int *charNumber,
|
||||
QMap<int, QList<DiffSelection>> *selections);
|
||||
DiffSelections *selections);
|
||||
};
|
||||
|
||||
class UnifiedDiffEditorWidget final : public SelectableTextEditorWidget
|
||||
@@ -117,7 +116,7 @@ private:
|
||||
QSharedPointer<TextEditor::TextDocument> textDocument;
|
||||
UnifiedDiffData diffData;
|
||||
QHash<int, int> foldingIndent;
|
||||
QMap<int, QList<DiffSelection>> selections;
|
||||
DiffSelections selections;
|
||||
};
|
||||
|
||||
std::unique_ptr<QFutureWatcher<ShowResult>> m_watcher;
|
||||
|
||||
Reference in New Issue
Block a user