Commit d9404aac authored by Christoph Cullmann's avatar Christoph Cullmann 🍨
Browse files

fix crash on startup via "kate lala.txt:1234"

we need to ensure the view is properly registered before doing
the cursor setup
parent 1e69bb66
Pipeline #235035 passed with stage
in 6 minutes and 13 seconds
......@@ -495,28 +495,6 @@ KTextEditor::View *KateViewManager::createView(KTextEditor::Document *doc, KateV
*/
KTextEditor::View *view = (vs ? vs : activeViewSpace())->createView(doc);
/**
* connect to signal here so we can handle post-load
* set cursor position for this view if we need to
*/
KateDocumentInfo *docInfo = KateApp::self()->documentManager()->documentInfo(doc);
if (docInfo->startCursor.isValid()) {
KTextEditor::Cursor c = docInfo->startCursor; // Was a cursor position requested?
docInfo->startCursor = KTextEditor::Cursor::invalid(); // do this only once
if (!doc->url().isLocalFile()) {
QSharedPointer<QMetaObject::Connection> conn(new QMetaObject::Connection());
auto handler = [view, conn, c](KTextEditor::Document *) {
QObject::disconnect(*conn);
view->setCursorPosition(c);
};
*conn = connect(doc, &KTextEditor::Document::textChanged, view, handler);
} else if (c.isValid()) {
view->setCursorPosition(c);
}
}
/**
* remember this view, active == false, min age set
* create activity resource
......@@ -545,6 +523,30 @@ KTextEditor::View *KateViewManager::createView(KTextEditor::Document *doc, KateV
updateViewSpaceActions();
/**
* connect to signal here so we can handle post-load
* set cursor position for this view if we need to
* do this after the view is properly registered, else we might trigger assertions
* about unknown views in the connected lambdas
*/
KateDocumentInfo *docInfo = KateApp::self()->documentManager()->documentInfo(doc);
if (docInfo->startCursor.isValid()) {
KTextEditor::Cursor c = docInfo->startCursor; // Was a cursor position requested?
docInfo->startCursor = KTextEditor::Cursor::invalid(); // do this only once
if (!doc->url().isLocalFile()) {
QSharedPointer<QMetaObject::Connection> conn(new QMetaObject::Connection());
auto handler = [view, conn, c](KTextEditor::Document *) {
QObject::disconnect(*conn);
view->setCursorPosition(c);
};
*conn = connect(doc, &KTextEditor::Document::textChanged, view, handler);
} else if (c.isValid()) {
view->setCursorPosition(c);
}
}
return view;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment