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
    • 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.

      • Peter_Romao
      • 2 yrs ago
      • Reported - view

      Fred Yep. Done that and when starting ninox again... same thing.

      • Peter_Romao
      • 2 yrs ago
      • Reported - view

      Peter Romão Same thing with the message but... see below my answer to Sean.

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

      Fred Now the version numbers remain displayed. The first time it says "loaded" and the second time "already loaded".

      • Fred
      • 2 yrs ago
      • Reported - view

      Jacques TUR you are the best!

      • Peter_Romao
      • 2 yrs ago
      • Reported - view

      Sean OK. Restarting ninox brought me to the same state as your Mac. Same message but working! Yay! Only thing that remains to check is to see if it is working in my Windows MacOS Virtual Machine. But that will have to wait until tomorrow. Thanks all!

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

    I updated the autocompletion to version 1.05 to fix some bugs:
    - Sometimes the list was not displayed, especially after a "select".
    - Added variables declared in a for loop: "for i in select...".

    • SMoore
    • 2 yrs ago
    • Reported - view

    A huge time saver!! Thank you for sharing this! 

    • Gianluca
    • 2 yrs ago
    • Reported - view

    Hi Jacques TUR

    call me dumb, but...I used to have your formula beginning with

    html("
    <div id='completion" + this.ID + "'>auto-complétion v1.00.14 intialized<br>press ctrl+space into script editor to use it
    </div>
    <style id='exCoredMirrorStyle' type='text/css'>
       

    and it worked, but now it doesn't anymore.

    I've seen you made changes so I tried to follow your new instructions, but I can't get the editor working. Maybe I'm missing some piece of the procedure to "install" the script in my database.

    Could you please explain me what I have to do, just like you would explain it to a baby?😄

    Merci beaucoup!

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

      Gianluca Hi Gianluca, thanks for all your messages.
      I'm not sure which version you mean. The first version which consisted in importing the completion.html file is no longer maintained and you have to use module.html (Did you see this post?) which can allow file and comment badges and EvalJS JavaScript calls to be included at the same time

      Let me know if it allows you to make the auto-completion work?

      • Gianluca
      • 2 yrs ago
      • Reported - view

      Jacques TUR thank you! I did as described in the post and it works. 
      Only, I need to check more in details but it seems to be working not in all the tables of the database (didn’t matter if they are related and unrelated). Am I doing it wrong  again? 
      Or do I have to set the formula in every single table?

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

      Gianluca I'm not sure I understand. Does auto-complete work on some tables and not on others? Normally, you only need to initialize it once for it to work until the database is closed (Mac app) or reloaded (web).
      Does this give you an answer?
      If not, send me an example that doesn't work and I'll look at what's wrong (in your example or in my code 😁).

      • Gianluca
      • 2 yrs ago
      • Reported - view

      Jacques TUR I've found out it was my fault (of course 😄)...I thought that it was enough to open the database to get the module started, while it only starts when I actually use the table where the formula is: once I open the table where autocompletion is, then it works everywhere.

      Given this, I will ask you an advice: would it be worth to insert the same field in all the tables, so I don't need to remember where it is. Or is there some "trick" I can use to initialize it every time I Just open the database?

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

      Gianluca Yes, you can add a script in the trigger Trigger after opening that opens the form on which there is the initialization formula:

      And in the formula of the Initialization form, you can add the following code:

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

      the afterLoadModules function will be called when the code is initialized and will close the initialization window. Thus, the code will be initialized each time the database is started in a relatively clean manner.

      • Gianluca
      • 2 yrs ago
      • Reported - view

      Jacques TUR thank you so much!

    • Fred
    • 2 yrs ago
    • Reported - view

    Anyone else having trouble loading Jacques' tools? My DBs take forever to load and when they do the formula field is blank.

      • Fred
      • 2 yrs ago
      • Reported - view

      looks like the hiccup went away.

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

      Fred I just made an update to viewEvent. Maybe it's because of this?

    • Fred
    • 2 yrs ago
    • Reported - view

    Jacques TUR , how does the new auto complete in v3.6 work with your code? Have you noticed any issues?

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

      Fred Now this part of the code remains compatible. It's not a problem, but it's no longer needed. You can remove only this option by putting false on the completion line, as below :

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

Content aside

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