Skip to content

Commit

Permalink
Move jsonld-hint into standalone module
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBlueHat committed Jan 24, 2017
1 parent 28c65f7 commit 2dc2a4c
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 224 deletions.
50 changes: 3 additions & 47 deletions code-mirror.js
Expand Up @@ -7,59 +7,15 @@ require('codemirror/addon/lint/lint');
require('codemirror/addon/lint/json-lint');

// custom json-ld hinter
require('codemirror/addon/hint/show-hint');

// TODO: move this into a CodeMirror addon
function suggest(cm, pred) {
var terms = [
'@base',
'@container', '@context',
'@graph',
'@id',
'@language', '@list',
'@reverse',
'@set',
'@type',
'@vocab'
];
if (!pred || pred()) setTimeout(function() {
if (!cm.state.completionActive) {
cm.showHint({
hint: function (cm, options) {
var cur = cm.getCursor(),
token = cm.getTokenAt(cur);
var start = token.start - 1,
end = token.end;
var list = terms;
if (token.type === 'property') {
let search = token.string.match(/\w/);
if (search !== null) {
list = terms.filter(function(t) {
if (t.indexOf(search) > -1) {
return t;
}
});
}
return {
list: list, //value[i].listCallback(),
from: CodeMirror.Pos(cur.line, start+2),
to: CodeMirror.Pos(cur.line, end-1)
};
}
}
});
}
}, 100);
return CodeMirror.Pass;
}
require('./jsonld-hint.js');

const default_options = {
lineNumbers: true,
gutters: ["CodeMirror-lint-markers"],
lint: true,
extraKeys: {
"'@'": suggest,
"Ctrl-Space": suggest
"'@'": CodeMirror.hint.jsonld,
"Ctrl-Space": CodeMirror.hint.jsonld
}
};

Expand Down

0 comments on commit 2dc2a4c

Please sign in to comment.