14

Set auto completion on Ninox editor

Hello everyone, 

I was fed up with always having to close the code editor to fetch the name of a field or table, so I set up the Ninox code editor to have an auto-completion function :

press ctrl+space on the editor to display the completion list.

The list contain all Ninox functions, data base table and fields for each table and global user functions :

Ninox uses CodeMirror to edit its code. This editor is very complete and I didn't have too much trouble adding autocomplete. It is a classic CodeMirror add-on and there are many examples of how to do it on the web. The CodeMirror documentation also helped me a lot.
I think it is easy to improve the syntax highlighting.  I will try it later.

 

Because this code is long, I create GitHub repository with all code I did and published in this forum. You can download it here : https://github.com/JacquesTur/Ninext

To add the code on your application, you can copy the content of the completion.html file on GitHub and put it in on one formula :

html("
put the copy of code here
");

Or use the following code in your formula:

html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/completion.html").result)

In this last solution, your application will have directly the last modifications of the code in real time, the improvement... but also the new bugs 😅.    

71 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    Thanks Jacques, I got it working.

    Yes, first I needed to change the Keyboard shortcut for Input Source to something other than ctrl+space.

    I first tried it at the default table view then went to Edit Fields and that didn't work. Then I re-read the post and comments and realized I needed to open a record so the formula can load.

    It works as you described.

    • Arjan_G
    • 2 yrs ago
    • Reported - view

    Great work .... I Love it!

    • Lars
    • 2 yrs ago
    • Reported - view

    It works - awesome and thank you so much.

    I think you have to install it in each database you have, but that's worth it. Or am I wrong?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Lars Yes, you are right, it should be installed in every database.

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    Thank you for all your messages!!!

    I have just uploaded a new version with the following improvements:

    - Display of the table name in grey next to the field name.

    - Display a "no items found" message when completion is not possible.

    -Case insensitive sorting.

    • Fred
    • 2 yrs ago
    • Reported - view

    Just want to let MacOS app users know that you can use the short code on the front page of Jacques' gitHub page.

    I took out the close record feature if not in admin mode because I can image myself freaking out in the future trying to figure out why I can't open a record. I guess I could put it into a new table called system or something like that.

    Anyways, thanks again to Jacques for this great piece of work.

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Fred Yes, Fred the automatic closing was to answer people who wanted to know how to make the initialization more discreet. 

      But it is true that it can be surprising not to be able to open a record. That's why I cancelled the administrator mode to have a simple way to access the form.

      Thank you Fred for allowing this clarification. 

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    Hello everyone, 
    I have added the following improvements:
    1 - the afterLoadModules event is called only once after the code initialization. So, if you leave the closeRecord() function, it will only run once and you can reopen the form afterwards.

    2 - The auto-completion appears directly when you add a character in the editor (a-z, 0-9 or .). If you want it to appear only on ctrl-space, replace the code 

    var configLoadModules := {
            completion: true,
            badges: true,
            evalJS: true    };


    by

    var configLoadModules := {
            completion: {shortKey : 'Ctrl-Space'},
            badges: true,
            evalJS: true    };

    cf: https://codemirror.net/doc/manual.html#keymaps to find other possible key combinations.

    3 - when you select a function in the completion list, the cursor is positioned between the brackets so that you can directly enter the function parameters.

      • Fred
      • 2 yrs ago
      • Reported - view

      Jacques TUR YES! I love number 3! It always annoyed me that I have to keep clicking around after selecting field names the old Ninox way.

      Very thankful that you are spending your time doing this.

    • Fred
    • 2 yrs ago
    • Reported - view

    I came across an interesting issue. If I type "F" then "l" (lower case L) before Jacques code kicks in, it automagically fills in the floor command. This doesn't happen with any other command.

    Can anyone else duplicate it?

    I'm using v3.5.14 of the MacOS app.

      • Nick
      • 2 yrs ago
      • Reported - view

      Fred You're right. I can duplicate it.

      MacOS app v3.5.14

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    @Free and Nick,

    Effactively, there were several unwanted behaviours: capital letters were not taken into account and did not display the completion list. When only one item was in the list, it was automatically added in the editor. This last behaviour, which does not really pose a problem for coding, can be problematic when typing current text in a string.

    I have put back the possibility to display the completion list with the Ctrl-Space keys (or any other key defined in configLoadModules.completion) . This can be used when you select a text and want to display the completion list.

    I also added the positioning of the cursor after the open parenthesis when completing a global function.

    in global script :

    in use completion :

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    I have updated the completion. It is now version 1.04.

    The new features are :

    - name in color according to type :

    • green: local variables,
    • blue: Ninox functions
    • red : global function
    • black : fields
    • grey : tables

     

    - local variables detection

    - detection of the type of variable returned by formulas, global functions and variables.

    - display of possible fields on a formula, a global function or a variable that returns a table is followed by a dot.

      • Gianluca
      • 2 yrs ago
      • Reported - view

      Jacques TUR getting better and better! Thanks!

      • UweG
      • 2 yrs ago
      • Reported - view

      Jacques TUR Hi Jaques. Is the 1.04 online?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      UweG Yes, since 1 hour 🙂

      • Arjan_G
      • 2 yrs ago
      • Reported - view

      Jacques TUR Hello Jacques,

      Another great piece of development!
      Does the code work even from the API call ?
      html(http("GET","https://raw.githubusercontent.com/JacquesTur/Ninext/main/completion.html").result)

      Greets Arjan Groen

      • Peter_Romao.1
      • 2 yrs ago
      • Reported - view

      Jacques TUR thnx for the updates but my Ninox still shows v 1.01 as a result in the formula field (i'm on a mac - not the cloud version). Another ninox I have on a virtual machine when I am not on the laptop does not even start the auto completion (i.e. I do not have any result)

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Arjan G No Arjan, that's the old code. I had to give it up quickly because it didn't allow me to devolve efficiently.
      You have to use this code now:

      var configLoadModules := {
              completion: true,
              badges: true,
              evalJS: true
          };
      function afterLoadModules() do
          if not isAdminMode() then closeRecord() end
      end;
      html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/loadModules.html").result)
      

      You can see it on GitHub

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Peter Romão Several modules are loaded at the same time, including file and comment badge management, JavaScript functions and auto-completion.

      There is also a utilities module which has functions common to the other three modules and the module for loading modules.

      Recently I have also added a module under test that will allow you to search for a keyword or a field throughout the application code.

      Each module has its own version number which is displayed in the initialization form. The version number of the main module is displayed all the time, but the others only the first time the formula is run. I will fix this so that all version numbers are displayed all the time.
      Also, if the formula is not big enough, you can't see the bottom lines.

      Please tell me if you can now see what the version number of the auto-completion module is. It should be 1.04 beta, like on the picture.

      • Fred
      • 2 yrs ago
      • Reported - view

      Jacques TUR Thanks for supporting the code you have created.

      I've noticed that the first time I view a record with the html code to get your extensions it shows the picture above. If I exit the record and select it again from the all view, it changes to:

      Modules version 1.01 beta already loaded

      I'm guessing there is code to keep the html from loading and reloading. Is there way we can keep the module description on subsequent loads?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Fred Yes 👍, that's what I said above, I'll update the code so that the version numbers of all the modules remain displayed (while preventing the code from loading multiple times)

      • Fred
      • 2 yrs ago
      • Reported - view

      Jacques TUR oops, you are correct. I missed that part.

      • Peter_Romao.1
      • 2 yrs ago
      • Reported - view

      Jacques TUR Nope same thing is showing on the Mac. "Modules version 1.01 beta already loaded" Is there a way I can close the database to start loading from the beginning again? I used the close database command in the menu but to no avail.

      • Fred
      • 2 yrs ago
      • Reported - view

      Peter Romão Have you tried exiting the DB then going back in to the table with Jacques' formula?

Content aside

  • 14 Likes
  • 2 yrs agoLast active
  • 71Replies
  • 1556Views
  • 18 Following