From d2210e2ab0b370b8884a9aac735062dce7c29058 Mon Sep 17 00:00:00 2001 From: Daize Date: Mon, 4 Dec 2023 22:44:12 -0500 Subject: [PATCH 1/2] add language specific hint option --- .../runestone/activecode/js/activecode.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bases/rsptx/interactives/runestone/activecode/js/activecode.js b/bases/rsptx/interactives/runestone/activecode/js/activecode.js index 362d28216..60c66a25f 100755 --- a/bases/rsptx/interactives/runestone/activecode/js/activecode.js +++ b/bases/rsptx/interactives/runestone/activecode/js/activecode.js @@ -26,6 +26,10 @@ import "codemirror/lib/codemirror.css"; import "codemirror/addon/hint/show-hint.js"; import "codemirror/addon/hint/show-hint.css"; import "codemirror/addon/hint/sql-hint.js"; +import "codemirror/addon/hint/css-hint.js"; +import "codemirror/addon/hint/html-hint.js"; +import "codemirror/addon/hint/javascript-hint.js"; +import "codemirror/addon/hint/xml-hint.js"; import "codemirror/addon/hint/anyword-hint.js"; import "codemirror/addon/edit/matchbrackets.js"; import "./skulpt.min.js"; @@ -52,7 +56,18 @@ var socket, connection, doc; var chatcodesServer = "chat.codes"; CodeMirror.commands.autocomplete = function (cm) { - cm.showHint({ hint: CodeMirror.hint.anyword }); + var doc = cm.getDoc(); + var POS = doc.getCursor(); + var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name; + if (mode == 'xml') { //html depends on xml + cm.showHint(cm, CodeMirror.hint.html); + } else if (mode == 'javascript') { + cm.showHint(cm, CodeMirror.hint.javascript); + } else if (mode == 'css') { + cm.showHint(cm, CodeMirror.hint.css); + }else { + cm.showHint({ hint: CodeMirror.hint.anyword }); + } }; // separate into constructor and init From 6048c0f1c28aa016a621dd90415551dc272e5b37 Mon Sep 17 00:00:00 2001 From: Daize Date: Wed, 6 Dec 2023 12:07:35 -0500 Subject: [PATCH 2/2] add sql under hinting options --- .../interactives/runestone/activecode/js/activecode.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bases/rsptx/interactives/runestone/activecode/js/activecode.js b/bases/rsptx/interactives/runestone/activecode/js/activecode.js index 60c66a25f..e44491632 100755 --- a/bases/rsptx/interactives/runestone/activecode/js/activecode.js +++ b/bases/rsptx/interactives/runestone/activecode/js/activecode.js @@ -55,18 +55,22 @@ window.componentMap = {}; var socket, connection, doc; var chatcodesServer = "chat.codes"; -CodeMirror.commands.autocomplete = function (cm) { +CodeMirror.commands.autocomplete = function(cm) { var doc = cm.getDoc(); var POS = doc.getCursor(); var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name; + // CodeMirror presently supports JavaScript, XML, CSS, and SQL modes. + // If the mode is not one of the supported types, fall back to the anyword hint. if (mode == 'xml') { //html depends on xml cm.showHint(cm, CodeMirror.hint.html); } else if (mode == 'javascript') { cm.showHint(cm, CodeMirror.hint.javascript); } else if (mode == 'css') { cm.showHint(cm, CodeMirror.hint.css); - }else { - cm.showHint({ hint: CodeMirror.hint.anyword }); + } else if (mode == 'sql') { + cm.showHint(cm, CodeMirror.hint.sql); + } else { + cm.showHint({hint:CodeMirror.hint.anyword}) } };