| Summary: | After formatting, the code position is reset to top of file | ||
|---|---|---|---|
| Product: | [Applications] kdevelop | Reporter: | rusconi <listes.rusconi> |
| Component: | All editors | Assignee: | kdevelop-bugs-null |
| Status: | CONFIRMED --- | ||
| Severity: | minor | CC: | igorkuo |
| Priority: | NOR | ||
| Version First Reported In: | 5.13.240180 | ||
| Target Milestone: | --- | ||
| Platform: | Debian testing | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
|
Description
rusconi
2023-11-30 10:12:51 UTC
The relevant code appears to be in SourceFormatterController::FileFormatter::formatDocument() at https://invent.kde.org/kdevelop/kdevelop/-/blob/8f23c66e87587db3116d81f14e7d7ea3caf03150/kdevplatform/shell/sourceformattercontroller.cpp#L729-735 I think the bug can be fixed by introducing new API QVector<KTextEditor::Cursor> IDocument::allCursorPositions() and void IDocument::setAllCursorPositions(const QVector<KTextEditor::Cursor> &); and using the new API in formatDocument() to save and restore the cursor positions of all views, not just the active one. Since this API does not exist yet, similar bugs are possible elsewhere. A merge request is welcome. (In reply to Igor Kushnir from comment #1) > The relevant code appears to be in > SourceFormatterController::FileFormatter::formatDocument() at > https://invent.kde.org/kdevelop/kdevelop/-/blob/ > 8f23c66e87587db3116d81f14e7d7ea3caf03150/kdevplatform/shell/ > sourceformattercontroller.cpp#L729-735 > > I think the bug can be fixed by introducing new API > QVector<KTextEditor::Cursor> IDocument::allCursorPositions() and void > IDocument::setAllCursorPositions(const QVector<KTextEditor::Cursor> &); and > using the new API in formatDocument() to save and restore the cursor > positions of all views, not just the active one. Since this API does not > exist yet, similar bugs are possible elsewhere. > > A merge request is welcome. I would be eager to help. Please, give me some directions as to where I find the different views of a given opened file, to start with. Then, I'll try to find my way. Thank you, Filippo (In reply to rusconi from comment #2) > Please, give me some directions as to where I find > the different views of a given opened file, to start with. Then, I'll try to > find my way. TextDocument::cursorPosition() and TextDocument::setCursorPosition() (https://invent.kde.org/kdevelop/kdevelop/-/blob/5f6282cbb7e4ded41aca76596095a7fb28e4893e/kdevplatform/shell/textdocument.cpp#L449-L479) obtain an active view via TextDocument::activeTextView(), which looks for the active view in QList<View*> Sublime::Document::views(). If I understand correctly, you just need to obtain/set cursors for all elements of this list of views. Greetings, I have made a pull request at https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/530 that apparently sets the formatted file's views' cursor positions correctly right after the formatting of the file. I have left comments using cout(), of course remove them freely. In the hope this very first contribution is a good starting point to have code in the upstream source tree. Sincerely, Filippo |