Menu

#1523 [Patch] Add STYLE_AUTOCOMPLETION and SCI_AUTOCUSESTYLE

Committed
closed
nobody
5
2024-07-22
2024-06-19
No

Here's patch which adds STYLE_AUTOCOMPLETION and SCI_AUTOCUSESTYLE to enable it.

This is similar to STYLE_CALLTIP and SCI_CALLTIPUSESTYLE except that it only the font face name, font size, and character set attributes are used and not the colours.

It was actually added a long time ago by Jordan Russell for Inno Setup and I recently updated this to the lastest version of Scintilla and also added SCI_AUTOCUSESTYLE for backward compatibility. In Inno Setup this style is used to change the font for autocompletion lists to the normal dialog font.

The default value of 2 for the lineHeight property is how it was in old versions of Scintilla.

The patch includes updates of Scintilla.iface and ScintillaDoc.html.

https://patch-diff.githubusercontent.com/raw/jrsoftware/scintilla/pull/6.diff
https://patch-diff.githubusercontent.com/raw/jrsoftware/scintilla/pull/6.patch
https://github.com/jrsoftware/scintilla/pull/6/files

Discussion

  • Neil Hodgson

    Neil Hodgson - 2024-06-19

    Style 40 is already used by lexers (with SCE_PL_SUB_PROTOTYPE and SCE_RB_STDERR, for example) and can not be repurposed for other uses.

     
    • Martijn Laan

      Martijn Laan - 2024-06-20

      Ah, sorry, I wasn't aware of that. We don't use a lexer so haven't run into this limitation. Is there a way to workaround this, assuming you find the feature interesting?

       
  • Zufu Liu

    Zufu Liu - 2024-06-20

    SC_ELEMENT_LIST* can be used to custom auto-completion list colors.

     
    • Martijn Laan

      Martijn Laan - 2024-06-20

      Thanks but this patch is to change the font name & size and not the colors.

       
  • Neil Hodgson

    Neil Hodgson - 2024-06-20

    An extended style can be allocated with SCI_ALLOCATEEXTENDEDSTYLES.

    Then there could be an API to set this as the autocompletion style.

     
    • Martijn Laan

      Martijn Laan - 2024-06-21

      Sounds good, thanks! Will look into this.

       
    • Martijn Laan

      Martijn Laan - 2024-06-22

      I've updated the patch: replaced STYLE_AUTOCOMPLETION and SCI_AUTOCUSESTYLE with SCI_AUTOCSETSTYLEOFFSET (and SCI_AUTOCGETSTYLEOFFSET). Also fixed some preexisting typos in Scintilla.iface.

      I haven't worked with extended styles before but think I made it how they're supposed to work. My container now does calls like this:

      FAutoCompleteStyleOffset := Call(SCI_ALLOCATEEXTENDEDSTYLES, 1, 0);
      CallStr(SCI_STYLESETFONT, STYLE_DEFAULT + FAutoCompleteStyleOffset, ...);
      Call(SCI_AUTOCSETSTYLEOFFSET, FAutoCompleteStyleOffset, 0);
      
       
  • Neil Hodgson

    Neil Hodgson - 2024-06-24

    Adding STYLE_DEFAULT (32) appears wrong as SCI_ALLOCATEEXTENDEDSTYLES should return the allocated style number.

    Also fixed some preexisting typos in Scintilla.iface.

    Please don't do this as it makes it more difficult to see what was changed by a feature. Fixing issues with other code should be in separate change sets.

     
    • Martijn Laan

      Martijn Laan - 2024-06-24

      I removed the typo fixes from the patch.

      Also made it correct so the container doesn't have to add STYLE_DEFAULT anymore. I got confused by the use of 'Offset' in MarginSetStyleOffset but understand it now. The patch should now be good to commit.

       
  • Neil Hodgson

    Neil Hodgson - 2024-06-29

    This may produce different height lines than before (and different to the edit view) as it defaults to using the height of STYLE_DEFAULT instead of the max height of all fonts and doesn't take into account the extra ascent and descent that can be used to ensure extra-large text like emojis and accented characters are displayed OK.

    It is likely that changing the height of autocompletion list lines and thus number of lines visible is a motivation for this change but it shouldn't affect applications that do not call SCI_AUTOCSETSTYLE.

    Possibly drop FontMeasurements::lineHeight and use explicit code in ScintillaBase::AutoCompleteStart that maintains current behaviour unless ViewStyle::autocStyle was set.

     
    • Martijn Laan

      Martijn Laan - 2024-06-29

      Thanks for reviewing again and sorry it wasn't correct yet. I've applied your recommendations to the patch. I based the method of getting a surface for measurement on how it's done for call tips.

       
  • Neil Hodgson

    Neil Hodgson - 2024-07-01

    The font pointer Font *fontText is being used after it may become invalid inside the ac.Start(...) statement where the fonts may be refreshed. This caused a crash when I tested the code. It is safest to use the full expression vs.styles[vs.autocStyle].font.get() for each use.

    The scintilla.iface interface definition file doesn't have an argument for AutoCSetStyle:

    -set void AutoCSetStyle=2806(,)
    +set void AutoCSetStyle=2806(int style,)
    

    It is worthwhile having some simple tests to check the API definition works as does the API.

    --- a/test/simpleTests.py   Mon Jul 01 17:59:03 2024 +1000
    +++ b/test/simpleTests.py   Mon Jul 01 20:39:13 2024 +1000
    @@ -3106,6 +3106,10 @@
            self.assertEqual(self.ed.AutoCGetDropRestOfWord(), 1)
            self.ed.AutoCSetDropRestOfWord(0)
    
    +       self.ed.AutoCSetStyle(13)
    +       self.assertEqual(self.ed.AutoCGetStyle(), 13)
    +       self.ed.AutoCSetStyle(32)
    +
        def testAutoShow(self):
            self.assertEqual(self.ed.AutoCActive(), 0)
            self.ed.SetSel(0, 0)
    

    The surfaceMeasure creation code is repeated before calling AutoCompleteStart and there could be a single implementation inside the method. This would also preserve the current method signature.

     
    • Martijn Laan

      Martijn Laan - 2024-07-01

      Thanks, I've updated the patch with your suggestions.

       
  • Neil Hodgson

    Neil Hodgson - 2024-07-03
    • labels: scintilla --> scintilla, autocompletion
    • Group: Initial --> Committed
     
  • Neil Hodgson

    Neil Hodgson - 2024-07-03

    Committed with minor changes as [d30a84]. The API numbers were changed to use some spare ones from near other autocompletion methods.

     

    Related

    Commit: [d30a84]

    • Martijn Laan

      Martijn Laan - 2024-07-03

      Thanks!

       
  • Neil Hodgson

    Neil Hodgson - 2024-07-22
    • status: open --> closed
     

Log in to post a comment.