Here's a modified version of the html_header subroutine from the tryityourself application:
[CODE lang="b4x" title="Add css and js files" highlight="7,18-24"]Private Sub html_header(sb As StringBuilder,theme As String,mode As String) As StringBuilder
sb.Append("<html>")
sb.Append("<head>")
sb.Append("<meta name='viewport' content='width=device-width, initial-scale=1'>")
sb = add_stylesheet(sb,"codemirror.css")
sb = add_stylesheet(sb,"eclipse.css")
sb = add_stylesheet(sb,"show-hint.css")
If theme <> "" And theme <> "default" Then sb = add_stylesheet(sb,theme & ".css")
sb = add_javascript(sb,"codemirror.js")
sb = add_javascript(sb,"javascript.js")
sb = add_javascript(sb,"htmlmixed.js")
sb = add_javascript(sb,"css.js")
sb = add_javascript(sb,"clike.js") 'needed for php
sb = add_javascript(sb,"php.js")
sb = add_javascript(sb,"vb.js")
sb = add_javascript(sb,"sql.js")
sb = add_javascript(sb,"xml.js")
sb = add_javascript(sb,"show-hint.js")
sb = add_javascript(sb,"anyword-hint.js")
sb = add_javascript(sb,"css-hint.js")
sb = add_javascript(sb,"html-hint.js")
sb = add_javascript(sb,"javascript-hint.js")
sb = add_javascript(sb,"sql-hint.js")
sb = add_javascript(sb,"xml-hint.js")
Return sb
End Sub
[/CODE]
Of course you have to add the files in the highlighted lines in the Files Manager.
(the files can be found in the CodeMirror source code folders mode, theme, addon/hints, ...)
And then you need to change the html_body subroutine.
I'm using the smart string literal to make the code more readable and editable.
[CODE lang="b4x" title="autocomplete additions" highlight="3-7,11-30"]Private Sub html_body(sb As StringBuilder, strtext As String,pn As Pane,mode As String,theme As String) As StringBuilder
'Log("mode argument: " & mode)
Dim strmode As String = mode
If mode = "vb" Then strmode = "text/x-vb"
If mode = "php" Then strmode = "application/x-httpd-php"
If mode = "sql" Then strmode = "text/x-sql"
Log(mode)
If pn = B4XPages.MainPage.pnright Then
sb.Append("</head><body style='background-color:#DDDAFF;'>")
sb.Append("<textarea id='editor'>").Append(strtext).Append("</textarea>").Append(CRLF)
Dim strcm As String = $"
<script> var editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
mode:'${strmode}',
theme:'${theme}',
styleActiveLine:true,
lineNumbers:true,
lineWrapping:true,
dragDrop:true,
indentUnit:4,
indentWithTabs:true,
tabMode:'indent',
enterMode:'indent'
});
editor.setSize('null','100%');
editor.setOption('extraKeys', {
"Ctrl-Space": "autocomplete",
});
</script>
"$
sb.Append(strcm)
Else
'sb = add_stylesheet(sb,"w3.css") 'use stylesheet from file
sb.Append("</head><body>")
sb.Append("<div>").Append(strtext).Append("</div>").Append(CRLF)
End If
'Log(sb.ToString)
Return sb
End Sub
[/CODE]
You can find an example of the words that are in the autocomplete list for vb in the vb.js file.
Tip: you can create a b4x.js file and put all the b4x words in it... and use a b4x mode...
If you want the autocomplete to start when you start typing then you can consult the CodeMirror documentation for a 'keydown' function.
Add such a function to the script in the html_body <script> section from the editor.
And this should do the job...