Skip to content

[Fix#44] Add language hints active code #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions bases/rsptx/interactives/runestone/activecode/js/activecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -51,8 +55,23 @@ window.componentMap = {};
var socket, connection, doc;
var chatcodesServer = "chat.codes";

CodeMirror.commands.autocomplete = function (cm) {
cm.showHint({ hint: CodeMirror.hint.anyword });
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 if (mode == 'sql') {
cm.showHint(cm, CodeMirror.hint.sql);
} else {
cm.showHint({hint:CodeMirror.hint.anyword})
}
};

// separate into constructor and init
Expand Down