Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122985

toggling TextEdit.format back and forth between AutoText and PlainText loses markdown after a couple of times

    XMLWordPrintable

Details

    • bc1bdd0e1 (dev), 206a1fa2a (6.7), 6b8bf79a5 (6.7.0)

    Description

      https://codereview.qt-project.org/c/qt/qtdeclarative/+/523645 is a manual test using this approach for an editor that allows editing either "source" form (html or markdown shown with PlainText format) or wysiwyg (shown with AutoText format). You can load a markdown file (the default in this manual test is AutoText, so markdown is shown wysiwyg by default); then switch textFormat = PlainText to see the raw markdown; then switch textFormat = AutoText; then switch textFormat = PlainText again. At this point, you no longer have markdown, but just the plain text that was extracted from the QTextDocument. So the editor kindof works, but you should be able to toggle back and forth indefinitely.

      Since QQuickTextDocumentPrivate::detectedFormat is not exposed in a property, it's not convenient in QML to detect whether the user actually loaded a markdown or html file. That's why this manual test just toggles back and forth between AutoText and PlainText. We could expose detectedFormat (and some users may do ugly hacks like detecting the extension from the URL that is loaded); but AutoText ought to work too, IMO.

      There might be some debate about which way is right, from the perspective that maybe you want to have a way to throw out the formatting and convert it to plain text. I'll try to add a way to this manual test to be sure. Probably just text = getText(0, length) or so.

      If you declare textFormat: PlainText and then put some markdown text into the text property, you see raw markdown. If you declare textFormat: PlainText and then put some html text into the text property, you see raw html. Therefore I think it's consistent that if you load a markdown file (or HTML file) by setting textDocument.source, and then change textFormat = PlainText, you should see the raw markdown (or HTML), not the plain text extracted from it. This makes it easy to write the kind of editor that toggles back and forth, and helps to ensure that the AutoText mode is as useful as possible.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              srutledg Shawn Rutledge
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes