Skip to content

Commit

Permalink
Notebook activation makes first active or program the current source.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Jul 5, 2015
1 parent 6c61fcb commit 030a836
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion web/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ define([ "cm/lib/codemirror",
role: "source",
placeholder: "Your Prolog rules and facts go here ...",
lineNumbers: true,
autoCurrent: true,
save: false,
theme: "prolog",
matchBrackets: true,
Expand Down Expand Up @@ -192,7 +193,8 @@ define([ "cm/lib/codemirror",

if ( options.mode == "prolog" && data.role == "source" ) {
elem.on("activate-tab", function(ev) {
elem.prologEditor('makeCurrent');
if ( options.autoCurrent )
elem.prologEditor('makeCurrent');
data.cm.refresh(); /* needed if a tab has been opened */
});

Expand Down
18 changes: 18 additions & 0 deletions web/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ var cellTypes = {
}
});

/* Activate the active source or first source. If the active
* cell is a query, we could activate the source of the query?
*/
elem.on("activate-tab", function(ev) {
if ( ev.target == elem[0] ) {
var eds = elem.find(".nb-content")
.children(".nb-cell.program");
var aeds = eds.filter(".active");
var nc = aeds[0]||eds[0];

if ( nc ) {
$(nc).find(".prolog-editor").prologEditor('makeCurrent');
}
ev.stopPropagation();
}
});

elem.data(pluginName, data); /* store with element */

/* restore content */
Expand Down Expand Up @@ -640,6 +657,7 @@ var cellTypes = {
var editor;

options = options||{};
options.autoCurrent = false;

this.html("");
this.append(editor=$.el.div({class:"editor"}));
Expand Down

0 comments on commit 030a836

Please sign in to comment.