Menu

#1272 Add API to set default fold display text

Completed
closed
None
5
2019-04-16
2019-03-22
Zufu Liu
No

Most editors use ellipsis (three dots) as the text, set a default text can avoid duplicating it on each folding.
After the default text been set, unless some line need show a different fold text, application can use ToggleFold instead of ToggleFoldShowText to toggle folding.

The default text can be set with ToggleFoldShowText (-1, "..."), and released in the destructor (not in Clear method).

Related

Feature Requests: #1419

Discussion

  • Zufu Liu

    Zufu Liu - 2019-03-23

    suggest tiny changes to fold display text box.
    1. reduce height to avoid overlap
    2. increase width (left/right inner margin)

     
    • Neil Hodgson

      Neil Hodgson - 2019-03-23

      This feature was a subject of much discussion on the mailing list so any change in appearance should go back there to see if the creators and users like the change.

      The patch only affects the box, so the background colour leaks out the top and doesn't fill the right of 68 in this example.
      background not matching box

       
      • Zufu Liu

        Zufu Liu - 2019-03-24

        Line 1203 FontAlias fontText and line 1221 FontAlias textFont in DrawFoldDisplayText() is same.

         
        • Neil Hodgson

          Neil Hodgson - 2019-04-02

          Fixed with [8d77e5].

           

          Related

          Commit: [8d77e5]

    • Neil Hodgson

      Neil Hodgson - 2019-03-23

      Forcing extra spacing limits the control that applications have over the appearance. If you want an inner margin then add spacing characters like HAIR SPACE \xE2\x80\x8A.

       
  • Neil Hodgson

    Neil Hodgson - 2019-03-23

    APIs that do something different when a magic value is passed as an argument are irregular, more difficult to understand, and more likely to be buggy. Add a new default fold text API.

     
  • Zufu Liu

    Zufu Liu - 2019-03-24

    Updated the patch for the box. don't known it's better than before or not.

     
  • Zufu Liu

    Zufu Liu - 2019-03-25

    Patch for set default fold display text.

     
    • Neil Hodgson

      Neil Hodgson - 2019-03-27

      Is ContractionState the best place to hold this? It seems to be a global fold display setting like the existing EditModel::foldDisplayTextStyle so belongs in the same location as that.

      Its fine for it to be a std::string as there is only going to be one per instance. ContractionState uses UniqueString in case there are large numbers of unique texts.

       
      • Zufu Liu

        Zufu Liu - 2019-03-27

        Change to EditModel is fine, but require extra method GetFoldDisplayTextShown() and anothor method to check whether the text is shown.

        Default UniqueString returns NULL while std::string returns non-null empty string, with std::string, model.pcs->GetFoldDisplayTextShown(line) is redundent or adding extra check to ensure text is not empty.

        Maybe the GetDefaultFoldDisplayText can ommited just like foldDisplayTextStyle.

         
        • Neil Hodgson

          Neil Hodgson - 2019-03-27

          There should be a get for each set, so there should be a FoldDisplayTextGetStyle.

           
  • Zufu Liu

    Zufu Liu - 2019-03-26

    Please change title to Add API to set default fold display text or something.

    The patch is in above post.

     
  • Neil Hodgson

    Neil Hodgson - 2019-03-27
    • summary: Allow use ToggleFoldShowText() to set a global default text --> Add API to set default fold display text
     
  • Zufu Liu

    Zufu Liu - 2019-03-30

    Moved defaultFoldDisplayText into EditModel, maybe need a new UniqueStringCopy() that treat empty string as null as in the patch.

    if pcs->GetFoldDisplayText() maybe expensive, GetFoldDisplayTextShown() can be changed to return the text directly.

     
  • Zufu Liu

    Zufu Liu - 2019-03-30

    With model.foldDisplayTextStyle == SC_FOLDDISPLAYTEXT_HIDDEN kept in EditView.cxx.

     
  • Neil Hodgson

    Neil Hodgson - 2019-03-30

    Committed FoldDisplayTextGetStyle as [8fe3c5].

    Unsure about changing handling of empty strings in UniqueStringCopy as it makes it more likely that downstream code (possibly in external platform layers) is exposed to nullptr when it wasn't previously.

     

    Related

    Commit: [8fe3c5]

  • Zufu Liu

    Zufu Liu - 2019-03-31

    Added allowEmpty to UniqueStringCopy.

     
    • Neil Hodgson

      Neil Hodgson - 2019-04-02

      This doesn't appear sufficiently motivated to me: the job of UniqueStringCopy is to make a copy its input and it makes sense to me that copying a nullptr is a nullptr and copying an empty string is an empty string. If an empty string should be treated the same as a nullptr then that is an interpretation being made by the calling code. Maybe this code would be simpler if there is a helper that returns <bool>(!p || !*p) or its inverse.</bool>

      GetFoldDisplayTextShown avoids calling foldDisplayTexts->ValueAt when there may be no data to index into as there have not been any folds contracted. If GetFoldDisplayTextShown is to be replaced with calls to GetFoldDisplayText then GetFoldDisplayText needs to safely handle all the cases that are handled in GetFoldDisplayTextShown.

      The result from GetFoldDisplayText can be a nullptr so can not be assigned to the string_view without testing first. Although a string_view containing nullptr is legal, constructing a string_view from a nullptr argument is currently non-portable - not supported in C++17 although it probably will be in C++20.

       
  • Zufu Liu

    Zufu Liu - 2019-04-03

    Added IsNullOrEmpty() helper.

     
  • Neil Hodgson

    Neil Hodgson - 2019-04-05

    Committed as [9fcb52] with APIs renumbered, minor formatting changes and an API test.

    One potential issue is that once the application has defined a default folding text, it cannot override that with nothing for a line.

     

    Related

    Commit: [9fcb52]

  • Zufu Liu

    Zufu Liu - 2019-04-06

    I think, once FoldDisplayTextStyle is set to non-hidden, application is assumed some text (either the default or specific text for a line) will showing on folding.
    They can use ToggleFoldShowText() to clear / replace the specific text previously set.

     
  • Neil Hodgson

    Neil Hodgson - 2019-04-16
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.