--- a/src/main.cpp Mon Jul 04 15:37:22 2022 +0300 +++ b/src/main.cpp Mon Jul 04 19:53:13 2022 +0300 @@ -52,7 +52,6 @@ std::unique_ptr<EditTools> tools; std::unique_ptr<AxesLayer> axesLayer; std::unique_ptr<GridLayer> gridLayer; - std::unique_ptr<QTextDocument> textbuffer; std::unique_ptr<QTextCursor> textcursor; Model* model; }; @@ -484,6 +483,7 @@ }, }, action); */ + }; const auto restoreSettings = [&]{ recentlyOpenedFiles = setting<Setting::RecentFiles>(); @@ -523,15 +523,8 @@ data->canvas->setLayerEnabled(data->axesLayer.get(), setting<Setting::DrawAxes>()); data->canvas->addRenderLayer(data->gridLayer.get()); data->canvas->addRenderLayer(data->tools.get()); - QString modeltext; - QTextStream stream{&modeltext}; - ::save(*model, &stream); - data->textbuffer = std::make_unique<QTextDocument>(); - data->textbuffer->setPlainText(modeltext); - data->textbuffer->setDefaultFont(monospace()); - data->textbuffer->setDocumentLayout(new QPlainTextDocumentLayout(data->textbuffer.get())); - new LDrawSyntaxHighlighter{data->textbuffer.get()}; - data->textcursor = std::make_unique<QTextCursor>(data->textbuffer.get()); + new LDrawSyntaxHighlighter{model}; + data->textcursor = std::make_unique<QTextCursor>(model); documents.setModelPayload(modelId, data); QObject::connect( data->tools.get(), @@ -716,7 +709,7 @@ if (modelSubWindow != nullptr) { if (ModelData* data = documents.findPayload<ModelData>(modelSubWindow->modelId)) { checkEditingModeAction(data->tools->currentEditingMode()); - ui.modelEdit->setDocument(data->textbuffer.get()); + ui.modelEdit->setDocument(data->model); ui.modelEdit->setTextCursor(*data->textcursor); } } @@ -775,12 +768,6 @@ &QPlainTextEdit::textChanged, [&]{ if (ModelData* data = currentModelData(&ui, &documents)) { - Model* const model = data->model; - model->clear(); - QString text = ui.modelEdit->toPlainText(); - QTextStream stream{&text}; - Parser parser(stream); - parser.parseBody(*data->model); documents.loadDependenciesForAllModels(libraries); data->canvas->update(); }