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
-
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.
-
Great work .... I Love it!
-
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?
-
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.
-
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.
-
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 codevar configLoadModules := { completion: true, badges: true, evalJS: true };
byvar 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. -
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.
-
@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 :
-
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.
Content aside
-
14
Likes
- 2 yrs agoLast active
- 71Replies
- 1556Views
-
18
Following