Skip to content

Commit

Permalink
Merge pull request #6654 from zz85/editor-tern-autocomplete
Browse files Browse the repository at this point in the history
Editor: Integrate tern-threejs in script editor
  • Loading branch information
mrdoob committed Jun 6, 2015
2 parents 3828f5a + 56bce46 commit 5ab4a4a
Show file tree
Hide file tree
Showing 19 changed files with 16,173 additions and 2 deletions.
18 changes: 18 additions & 0 deletions editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@

<script src="js/libs/codemirror/mode/glsl.js"></script>

<link rel="stylesheet" href="js/libs/codemirror/addon/dialog.css">
<link rel="stylesheet" href="js/libs/codemirror/addon/show-hint.css">
<link rel="stylesheet" href="js/libs/codemirror/addon/tern.css">
<script src="js/libs/codemirror/addon/dialog.js"></script>
<script src="js/libs/codemirror/addon/show-hint.js"></script>
<script src="js/libs/codemirror/addon/tern.js"></script>
<script src="js/libs/acorn/acorn.js"></script>
<script src="js/libs/acorn/acorn_loose.js"></script>
<script src="js/libs/acorn/walk.js"></script>
<script src="js/libs/ternjs/polyfill.js"></script>
<script src="js/libs/ternjs/signal.js"></script>
<script src="js/libs/ternjs/tern.js"></script>
<script src="js/libs/ternjs/def.js"></script>
<script src="js/libs/ternjs/comment.js"></script>
<script src="js/libs/ternjs/infer.js"></script>
<script src="js/libs/ternjs/doc_comment.js"></script>
<script src="js/libs/tern-threejs/threejs.js"></script>

<script src="js/libs/jszip.min.js"></script>
<script src="js/libs/sortable.min.js"></script>
<script src="js/libs/signals.min.js"></script>
Expand Down
43 changes: 41 additions & 2 deletions editor/js/Script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ var Script = function ( editor ) {
matchBrackets: true,
indentWithTabs: true,
tabSize: 4,
indentUnit: 4
indentUnit: 4,
hintOptions: {
completeSingle: false
}
} );
codemirror.setOption( 'theme', 'monokai' );
codemirror.on( 'change', function () {
Expand Down Expand Up @@ -108,7 +111,6 @@ var Script = function ( editor ) {

} );


// validate

var errorLines = [];
Expand Down Expand Up @@ -223,6 +225,43 @@ var Script = function ( editor ) {

};

// tern js autocomplete

var server = new CodeMirror.TernServer( {
caseInsensitive: true,
plugins: { threejs: null }
} );

codemirror.setOption( 'extraKeys', {
'Ctrl-Space': function(cm) { server.complete(cm); },
'Ctrl-I': function(cm) { server.showType(cm); },
'Ctrl-O': function(cm) { server.showDocs(cm); },
'Alt-.': function(cm) { server.jumpToDef(cm); },
'Alt-,': function(cm) { server.jumpBack(cm); },
'Ctrl-Q': function(cm) { server.rename(cm); },
'Ctrl-.': function(cm) { server.selectName(cm); }
} );

codemirror.on( 'cursorActivity', function( cm ) {

if ( currentMode !== 'javascript' ) return;
server.updateArgHints( cm );

} );

codemirror.on( 'keypress', function( cm, kb ) {

if ( currentMode !== 'javascript' ) return;
var typed = String.fromCharCode( kb.which || kb.keyCode );
if ( /[\w\.]/.exec( typed ) ) {

server.complete( cm );

}

} );


//

signals.editorCleared.add( function () {
Expand Down
Loading

0 comments on commit 5ab4a4a

Please sign in to comment.