Use file mode in Preview add-on
ClosedPublic

Authored by croick on Apr 11 2018, 11:16 PM.

Details

Summary
  • prefer file mode over content-based mime type
  • update preview on update of file mode and change of url
  • fix crashes when switching views with opened preview

BUG: 398560

Test Plan
  • start empty kate session
  • enable preview add-on
  • open previewable document to replace empty default document
    • with patch the preview is displayed
  • change the file mode to Normal
    • preview is cleared
  • restore the original file mode
    • preview is displayed again
  • close file
    • preview is cleared
  • open a few previewable files and lock one of them, switch tabs
  • close the locked file
    • previous behaviour with locked previews is maintained

Diff Detail

Repository
R40 Kate
Branch
previewmode
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 136
Build 136: arc lint + arc unit
croick created this revision.Apr 11 2018, 11:16 PM
Restricted Application added a project: Kate. · View Herald TranscriptApr 11 2018, 11:16 PM
croick requested review of this revision.Apr 11 2018, 11:16 PM

Thanks for taking up the challenge to fix some of the glitches with the preview plugin. Happy to see that.

Did not yet get around for some real review, but here at least some first quick comments.

addons/preview/previewwidget.cpp
117–118

Unrelated, please separate commit.

142–143

One not yet implemented idea has been that the preview would keep/memorize the state (e.g.scroll position, zoom) it is in. So when having multiple views and switching between the views, the preview would switch to the state matching the view.
Example: a longer MD document where one edits two related sections at the same time, and for that has two views on the same text document open. When switching the views, the preview should switch the view state (i.e. the section it shows) as well. Unless the preview is locked to a certain view.

So not doing things on view->document() == m_previewedTextEditorDocument would introduce an assumption which might make implementing that idea harder in the future.

169

Does this also work in KDevelop?

Could there be any challenge in the order of entries in the mimetypes list read for a mode?

croick marked an inline comment as done.Apr 17 2018, 11:28 PM

Thanks for taking up the challenge to fix some of the glitches with the preview plugin. Happy to see that.

I actually tried to edit the SDDM readme and had to realize that the mode is detected as some matlab file type instead of markdown. I thought I should find out why that is and why I can't change it.

I realized today that (using the patch) KDevelop crashes when closing the program with an opened preview. m_partView is deleted before the document gets closed and the PreviewWidget does not know about this. Using a QPointer somehow only shifts the problem (or uncovers another?) deeper into KTextEditor::Document. So this I have to fix first.

addons/preview/previewwidget.cpp
142–143

I see, my new approach would be to just keep and check both (m_previewedTextEditorDocument and m_previewedTextEditorView).
Comparing to the document is required, because the document may change while the view remains.

169

This is how KTextEditor is getting the mode information (therefore the same for KDevelop). There is no public interface to this KTE::DocumentPrivate data however and I didn't want to start a discussion whether it's worth changing the KTE API for that.

I think (to be checked), the order in the list is the one which is set in the config file. So if another mimetype should be preferred, the user has to change the configuration. For MD I actually had to add the mime type manually in (Editor Configuration->Open/Save->Modes & Filetypes).

croick updated this revision to Diff 33283.Apr 29 2018, 12:04 PM
  • restore check for active view
  • use QPointer for m_partView, which may be deleted by KDevelop automatically

I realized today that (using the patch) KDevelop crashes when closing the program with an opened preview. m_partView is deleted before the document gets closed and the PreviewWidget does not know about this. Using a QPointer somehow only shifts the problem (or uncovers another?) deeper into KTextEditor::Document. So this I have to fix first.

D12527 and QPointer for m_partView is fixing this.
One thing which remains and which I just can't figure out, is a crash when switching to Patch Review with an opened preview.
Before this patch KDevelop just crashes inside m_xmlGuiFactory->removeClient(m_partView->kPart()) when switching back to normal mode. With this patch it crashes when changing previews after switching back from Patch Review. Somehow one of the containers in the KXMLGuiFactorygets deleted unnoticed.

croick updated this revision to Diff 36360.Jun 19 2018, 10:07 PM
croick edited the summary of this revision. (Show Details)
  • Fix crashes in KDevelop after switching views
Restricted Application added a subscriber: kwrite-devel. · View Herald TranscriptJun 19 2018, 10:07 PM

@croick Will see to give this a look later this week/on the WE.

@kossebau Akademy is in full swing, and we try to get the review requests down. Could you move this forward? Would be really nice :-)

I won't be available the following three weeks. If you feel like committing, please go ahead.

Should we now commit this or is there something left to fix?

croick edited the summary of this revision. (Show Details)Jan 10 2019, 10:14 AM

In my opinion this should be committed, since it fixes a few crashes next to improving the file mode identification.

Friedrich: any opinion if that should just go in to improve the status quo?

Friedrich: any opinion if that should just go in to improve the status quo?

I fear I have mentally moved too far away from this plugin for a qualified comment, sorry.

cullmann accepted this revision.Mar 31 2019, 10:42 AM

I think then we should add this instead of letting the work rot.

This revision is now accepted and ready to land.Mar 31 2019, 10:42 AM

This will override 5d28eaaf9041 (fixing the same bug), but I'll apply it anyway.

This revision was automatically updated to reflect the committed changes.