Uploaded image for project: 'Apache Flex'
  1. Apache Flex
  2. FLEX-34592

Can't use optionnal importer for TLF plainTextFormat and TextLayoutFormat

    XMLWordPrintableJSON

Details

    Description

      When you add importer to the TextConverter class, you should be able to let the importer decline the conversion by having its importToFlow method returning null (as it is stated in the TLF blogpost http://blogs.adobe.com/tlf/2010/11/custom-clipboard-formats.htm ).
      It works for all format except plainTextFormat and textLayoutFormat because of these lines in flashx.textLayout.edit.TextClipboard, method importToScrap #170:

      var textFlow:TextFlow = importer.importToFlow(textOnClipboard);
      if (textFlow)
      textScrap = new TextScrap(textFlow);

      if (format == TextConverter.PLAIN_TEXT_FORMAT)
      textScrap.setPlainText(true);
      else if (format == TextConverter.TEXT_LAYOUT_FORMAT)
      textScrap.setPlainText(false);

      If the importer return null, textFlow==null, so textScrap==null and textScrap.setPlainText(...) cause a null object error.

      The solution is trivial. This method should not assume these formats will always have the importer return a non-null textFlow, and should test either the existence of the textFlow or the existence of the textScrap. The correct code would be:

      var textFlow:TextFlow = importer.importToFlow(textOnClipboard);
      if (textFlow)
      textScrap = new TextScrap(textFlow);

      if (format == TextConverter.PLAIN_TEXT_FORMAT && textScrap)
      textScrap.setPlainText(true);
      else if (format == TextConverter.TEXT_LAYOUT_FORMAT && textScrap)
      textScrap.setPlainText(false);

      This bug prevent me from having some converter that check for patterns in a plain text from clipboard and chose to handle the conversion if the patterns are found.

      Attachments

        1. BasicTextImporter.as
          1 kB
          dimitri kara
        2. PoundFirstTextImporter.as
          1 kB
          dimitri kara
        3. TLFImporterBugTestCase.as
          4 kB
          dimitri kara

        Activity

          People

            doublefx Frédéric THOMAS
            korosif dimitri kara
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified