Skip to content

Commit 8ffd759

Browse files
committed
Fix issue with loading and editing drafts from imported files
1 parent 262f8ad commit 8ffd759

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/corelib/business_layer/model/abstract_model.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <domain/document_object.h>
77
#include <utils/diff_match_patch/diff_match_patch_controller.h>
8+
#include <utils/logging.h>
89
#include <utils/tools/debouncer.h>
910

1011
#include <QApplication>
@@ -201,14 +202,15 @@ void AbstractModel::saveChanges()
201202
return;
202203
}
203204

205+
const auto documentContent = d->document->content();
204206
const auto content = toXml();
205207
//
206-
const QByteArray undoPatch = d->dmpController.makePatch(content, d->document->content());
208+
const QByteArray undoPatch = d->dmpController.makePatch(content, documentContent);
207209
if (undoPatch.isEmpty()) {
208210
return;
209211
}
210212
//
211-
const QByteArray redoPatch = d->dmpController.makePatch(d->document->content(), content);
213+
const QByteArray redoPatch = d->dmpController.makePatch(documentContent, content);
212214
if (redoPatch.isEmpty()) {
213215
return;
214216
}
@@ -218,7 +220,7 @@ void AbstractModel::saveChanges()
218220
// если содержимое документа было пустым (как правило это кейс после создания документа),
219221
// то отменять и нечего, поэтому игнорируем такие изменения
220222
//
221-
const auto needToNotifyAboutContentChanged = !d->document->content().isEmpty();
223+
const auto needToNotifyAboutContentChanged = !documentContent.isEmpty();
222224
d->document->setContent(content);
223225
if (needToNotifyAboutContentChanged) {
224226
emit contentsChanged(undoPatch, redoPatch);
@@ -291,7 +293,12 @@ bool AbstractModel::mergeDocumentChanges(const QByteArray _content,
291293
// Если патч не принёс успеха, значит ошибка в наложении изменений
292294
//
293295
if (patchedContent.size() == newContent.size() && patchedContent == newContent) {
294-
return false;
296+
//
297+
// ... логгируем и пропускаем патч, чтобы собрать какой-никакой результат
298+
//
299+
Log::warning("Can't apply patch for document: Patch is\n\n%1\n",
300+
qUtf8Printable(QByteArray::fromPercentEncoding(patch)));
301+
continue;
295302
}
296303

297304
newContent.swap(patchedContent);

src/corelib/business_layer/model/text/text_model_text_item.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ void TextModelTextItem::Implementation::readXml(QXmlStreamReader& _contentReader
120120
{
121121
paragraphType = textParagraphTypeFromString(_contentReader.name().toString());
122122
Q_ASSERT(paragraphType != TextParagraphType::Undefined);
123+
if (paragraphType == TextParagraphType::Undefined) {
124+
paragraphType = TextParagraphType::UnformattedText;
125+
}
123126

124127
auto currentTag = xml::readNextElement(_contentReader);
125128

@@ -286,6 +289,8 @@ QByteArray TextModelTextItem::Implementation::buildXml(int _from, int _length)
286289
return {};
287290
}
288291

292+
Q_ASSERT(paragraphType != TextParagraphType::Undefined);
293+
289294
const auto _end = _from + _length;
290295

291296
QByteArray xml;

0 commit comments

Comments
 (0)