Skip to content

Commit 7cd0c3b

Browse files
committed
fix bug in rename
1 parent 7b4889e commit 7cd0c3b

3 files changed

Lines changed: 169 additions & 10 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"));
7+
else if (typeof define == "function" && define.amd) // AMD
8+
define(["../../lib/codemirror"], mod);
9+
else // Plain browser env
10+
mod(CodeMirror);
11+
})(function(CodeMirror) {
12+
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
13+
(document.documentMode == null || document.documentMode < 8);
14+
15+
var Pos = CodeMirror.Pos;
16+
17+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<", "<": ">>", ">": "<<"};
18+
19+
function bracketRegex(config) {
20+
return config && config.bracketRegex || /[(){}[\]]/
21+
}
22+
23+
function findMatchingBracket(cm, where, config) {
24+
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
25+
var afterCursor = config && config.afterCursor
26+
if (afterCursor == null)
27+
afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className)
28+
var re = bracketRegex(config)
29+
30+
// A cursor is defined as between two characters, but in in vim command mode
31+
// (i.e. not insert mode), the cursor is visually represented as a
32+
// highlighted box on top of the 2nd character. Otherwise, we allow matches
33+
// from before or after the cursor.
34+
var match = (!afterCursor && pos >= 0 && re.test(line.text.charAt(pos)) && matching[line.text.charAt(pos)]) ||
35+
re.test(line.text.charAt(pos + 1)) && matching[line.text.charAt(++pos)];
36+
if (!match) return null;
37+
var dir = match.charAt(1) == ">" ? 1 : -1;
38+
if (config && config.strict && (dir > 0) != (pos == where.ch)) return null;
39+
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
40+
41+
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
42+
if (found == null) return null;
43+
return {from: Pos(where.line, pos), to: found && found.pos,
44+
match: found && found.ch == match.charAt(0), forward: dir > 0};
45+
}
46+
47+
// bracketRegex is used to specify which type of bracket to scan
48+
// should be a regexp, e.g. /[[\]]/
49+
//
50+
// Note: If "where" is on an open bracket, then this bracket is ignored.
51+
//
52+
// Returns false when no bracket was found, null when it reached
53+
// maxScanLines and gave up
54+
function scanForBracket(cm, where, dir, style, config) {
55+
var maxScanLen = (config && config.maxScanLineLength) || 10000;
56+
var maxScanLines = (config && config.maxScanLines) || 1000;
57+
58+
var stack = [];
59+
var re = bracketRegex(config)
60+
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
61+
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
62+
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
63+
var line = cm.getLine(lineNo);
64+
if (!line) continue;
65+
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
66+
if (line.length > maxScanLen) continue;
67+
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
68+
for (; pos != end; pos += dir) {
69+
var ch = line.charAt(pos);
70+
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
71+
var match = matching[ch];
72+
if (match && (match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
73+
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
74+
else stack.pop();
75+
}
76+
}
77+
}
78+
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
79+
}
80+
81+
function matchBrackets(cm, autoclear, config) {
82+
// Disable brace matching in long lines, since it'll cause hugely slow updates
83+
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
84+
var marks = [], ranges = cm.listSelections();
85+
for (var i = 0; i < ranges.length; i++) {
86+
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
87+
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
88+
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
89+
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
90+
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
91+
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
92+
}
93+
}
94+
95+
if (marks.length) {
96+
// Kludge to work around the IE bug from issue #1193, where text
97+
// input stops going to the textare whever this fires.
98+
if (ie_lt8 && cm.state.focused) cm.focus();
99+
100+
var clear = function() {
101+
cm.operation(function() {
102+
for (var i = 0; i < marks.length; i++) marks[i].clear();
103+
});
104+
};
105+
if (autoclear) setTimeout(clear, 800);
106+
else return clear;
107+
}
108+
}
109+
110+
function doMatchBrackets(cm) {
111+
cm.operation(function() {
112+
if (cm.state.matchBrackets.currentlyHighlighted) {
113+
cm.state.matchBrackets.currentlyHighlighted();
114+
cm.state.matchBrackets.currentlyHighlighted = null;
115+
}
116+
cm.state.matchBrackets.currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
117+
});
118+
}
119+
120+
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
121+
function clear(cm) {
122+
if (cm.state.matchBrackets && cm.state.matchBrackets.currentlyHighlighted) {
123+
cm.state.matchBrackets.currentlyHighlighted();
124+
cm.state.matchBrackets.currentlyHighlighted = null;
125+
}
126+
}
127+
128+
if (old && old != CodeMirror.Init) {
129+
cm.off("cursorActivity", doMatchBrackets);
130+
cm.off("focus", doMatchBrackets)
131+
cm.off("blur", clear)
132+
clear(cm);
133+
}
134+
if (val) {
135+
cm.state.matchBrackets = typeof val == "object" ? val : {};
136+
cm.on("cursorActivity", doMatchBrackets);
137+
cm.on("focus", doMatchBrackets)
138+
cm.on("blur", clear)
139+
}
140+
});
141+
142+
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
143+
CodeMirror.defineExtension("findMatchingBracket", function(pos, config, oldConfig){
144+
// Backwards-compatibility kludge
145+
if (oldConfig || typeof config == "boolean") {
146+
if (!oldConfig) {
147+
config = config ? {strict: true} : null
148+
} else {
149+
oldConfig.strict = config
150+
config = oldConfig
151+
}
152+
}
153+
return findMatchingBracket(this, pos, config)
154+
});
155+
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
156+
return scanForBracket(this, pos, dir, style, config);
157+
});
158+
});

notebookjs/src/public/javascripts/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ function exec_cell(c_id) {
9191
}
9292

9393
}
94+
console.log(output)
95+
9496
}
9597

9698
// $(`#out_${id}`).empty()
@@ -165,13 +167,9 @@ function add_new_code_cell(c_id, where) {
165167
166168
</div>
167169
<div class="col-md-2"></div>
168-
<div class="col-md-1"></div>
169-
<div id="log_container-${new_id}" class="col-md-9 out-divs">
170-
<pre id="log-${new_id}"></pre>
171-
</div>
172-
<div id="out_div-${new_id}" class="col-md-9 out-divs">
173170
174-
</div>
171+
<div class="col-md-1"></div>
172+
<div id="out_div-${new_id}" class="col-md-9 out-divs"></div>
175173
<div class="col-md-2"></div>
176174
</div>
177175
`
@@ -402,7 +400,8 @@ $("#download").click(function () {
402400
var url = (window.URL || window.webkitURL).createObjectURL(blob);
403401

404402
var link = document.createElement('a');
405-
link.download = 'danfo_notebook.json';
403+
var name = document.getElementById("namebook").value
404+
link.download = `${name}.json`;
406405
link.href = url;
407406

408407
var link_pae = $(link);

notebookjs/src/views/layout.hbs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
<link rel='stylesheet' href='stylesheets/show-hint.css' />
3535
<script src="javascripts/addons/javascript-hint.js"></script>
3636
<script src="javascripts/addons/closebrackets.js"></script>
37+
<script src="javascripts/addons/matchbrackets.js"></script>
38+
3739

3840
</head>
3941

4042
<body>
41-
<nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top">
43+
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
4244
<a class="navbar-brand" href="/"><img style="width: 40px; width: 40px; margin-left: 5px; border-radius: 10px;"
4345
src="images/danfo.svg" /> notebook</a>
4446
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
@@ -67,7 +69,7 @@
6769
Options
6870
</a>
6971
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
70-
<a class="dropdown-item" data-toggle="modal" data-target="#nameNoteModal" href="#">Name Notebook</a>
72+
<a class="dropdown-item" data-toggle="modal" data-target="#nameNoteModal" href="#">Rename Notebook</a>
7173
<a class="dropdown-item" id="download" href="#">Download Notebook</a>
7274
<a class="dropdown-item" data-toggle="modal" data-target="#uploadNoteModal" href="#">Upload Notebook</a>
7375

@@ -127,7 +129,7 @@
127129
<div class="modal-body">
128130
<form>
129131
<div class="form-group">
130-
<input type="text" class="form-control-file" name="name-notebook" id="namebook">
132+
<input type="text" class="form-control-file" name="name-notebook" id="namebook" value="untitled">
131133
</div>
132134
</form>
133135
</div>

0 commit comments

Comments
 (0)