##// END OF EJS Templates
Fix a bug in renaming notebook...
Fix a bug in renaming notebook There was a bug in NotebookManager.save_notebook_object. Here is how to reproduce: 0. Make sure you don't have Untitled0. 1. Open new notebook Untitled0. 2. Rename it to something else. 3. Copy Untitled0.ipynb to the notebook dir from somewhere. (Do not use notebook UI.) 4. New copied Untitled0 cannot be opened. The renamed notebook is opened when tried. Indeed, accessing to http://localhost:XXXX/notebooks shows duplicated notebook_id. The problem was that NotebookManager.rev_mapping keeps old notebook name after renaming.

File last commit:

r7196:b0be2d03
r7359:ef719b62
Show More
contexthint.js
94 lines | 2.9 KiB | application/javascript | JavascriptLexer
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 // highly adapted for codemiror jshint
Matthias BUSSONNIER
space after function keyword in context-hint
r7195 (function () {
Matthias BUSSONNIER
fix and retab javascript
r7133 "use strict";
Matthias BUSSONNIER
beautify context-hint.js
r7194
Matthias BUSSONNIER
fix and retab javascript
r7133 function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 }
Matthias BUSSONNIER
beautify context-hint.js
r7194
Matthias BUSSONNIER
fix and retab javascript
r7133 function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
Matthias BUSSONNIER
beautify context-hint.js
r7194 if (arr[i] === item) {
return true;
}
Matthias BUSSONNIER
fix and retab javascript
r7133 }
return false;
}
return arr.indexOf(item) != -1;
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 }
Matthias BUSSONNIER
beautify context-hint.js
r7194
Matthias BUSSONNIER
space after function keyword in context-hint
r7195 CodeMirror.contextHint = function (editor) {
Matthias BUSSONNIER
fix and retab javascript
r7133 // Find the token at the cursor
Matthias BUSSONNIER
beautify context-hint.js
r7194 var cur = editor.getCursor(),
token = editor.getTokenAt(cur),
tprop = token;
Matthias BUSSONNIER
fix and retab javascript
r7133 // If it's not a 'word-style' token, ignore the token.
// If it is a property, find out what it is a property of.
var list = new Array();
Matthias BUSSONNIER
beautify context-hint.js
r7194 var clist = getCompletions(token, editor);
for (var i = 0; i < clist.length; i++) {
list.push({
str: clist[i],
type: "context",
from: {
line: cur.line,
ch: token.start
},
to: {
line: cur.line,
ch: token.end
}
})
Matthias BUSSONNIER
fix and retab javascript
r7133 }
return list;
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 }
Matthias BUSSONNIER
fix and retab javascript
r7133 // find all 'words' of current cell
Matthias BUSSONNIER
space after function keyword in context-hint
r7195 var getAllTokens = function (editor) {
Matthias BUSSONNIER
beautify context-hint.js
r7194 var found = [];
// add to found if not already in it
Matthias BUSSONNIER
be smarter for context completion...
r7140
Matthias BUSSONNIER
beautify context-hint.js
r7194 function maybeAdd(str) {
if (!arrayContains(found, str)) found.push(str);
}
// loop through all token on all lines
var lineCount = editor.lineCount();
// loop on line
for (var l = 0; l < lineCount; l++) {
var line = editor.getLine(l);
//loop on char
for (var c = 1; c < line.length; c++) {
var tk = editor.getTokenAt({
line: l,
ch: c
});
// if token has a class, it has geat chances of beeing
// of interest. Add it to the list of possible completions.
// we could skip token of ClassName 'comment'
// or 'number' and 'operator'
if (tk.className != null) {
maybeAdd(tk.string);
}
// jump to char after end of current token
c = tk.end;
Matthias BUSSONNIER
be smarter for context completion...
r7140 }
}
Matthias BUSSONNIER
beautify context-hint.js
r7194 return found;
Matthias BUSSONNIER
fix and retab javascript
r7133 }
Matthias BUSSONNIER
implement the completer in a separate class...
r7131
Matthias BUSSONNIER
be smarter for context completion...
r7140
Matthias BUSSONNIER
beautify context-hint.js
r7194 function getCompletions(token, editor) {
Matthias BUSSONNIER
fix and retab javascript
r7133 var candidates = getAllTokens(editor);
// filter all token that have a common start (but nox exactly) the lenght of the current token
Matthias BUSSONNIER
space after function keyword in context-hint
r7195 var lambda = function (x) {
Matthias BUSSONNIER
beautify context-hint.js
r7194 return (x.indexOf(token.string) == 0 && x != token.string)
Matthias BUSSONNIER
fix and retab javascript
r7133 };
var filterd = candidates.filter(lambda);
return filterd;
Matthias BUSSONNIER
implement the completer in a separate class...
r7131 }
})();