fnp
/
redakcja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b264c17
)
Fixed buttons and hotkeys.
author
Łukasz Rekucki
<lrekucki@gmail.com>
Mon, 5 Oct 2009 11:06:32 +0000
(13:06 +0200)
committer
Łukasz Rekucki
<lrekucki@gmail.com>
Mon, 5 Oct 2009 11:06:32 +0000
(13:06 +0200)
project/static/js/button_scripts.js
patch
|
blob
|
history
project/static/js/lib/codemirror/codemirror.js
patch
|
blob
|
history
project/static/js/lib/codemirror/editor.js
patch
|
blob
|
history
project/static/js/lib/codemirror/select.js
patch
|
blob
|
history
project/static/js/lib/codemirror/undo.js
patch
|
blob
|
history
project/static/js/lib/codemirror/util.js
patch
|
blob
|
history
diff --git
a/project/static/js/button_scripts.js
b/project/static/js/button_scripts.js
index
647f841
..
1032dcf
100644
(file)
--- a/
project/static/js/button_scripts.js
+++ b/
project/static/js/button_scripts.js
@@
-42,11
+42,11
@@
function ScriptletCenter()
output = start_tag + end_tag;
}
output = start_tag + end_tag;
}
- if (text.length == 0) {
- this.XMLEditorMoveCursorForward(context, params.tag.length + 2);
- }
-
this.XMLEditorReplaceSelectedText(context, output);
this.XMLEditorReplaceSelectedText(context, output);
+
+ if (text.length == 0) {
+ this.XMLEditorMoveCursorForward(context, -params.tag.length-3);
+ }
}.bind(this);
this.scriptlets['lineregexp'] = function(context, params) {
}.bind(this);
this.scriptlets['lineregexp'] = function(context, params) {
diff --git
a/project/static/js/lib/codemirror/codemirror.js
b/project/static/js/lib/codemirror/codemirror.js
index
97e2657
..
f63ed07
100644
(file)
--- a/
project/static/js/lib/codemirror/codemirror.js
+++ b/
project/static/js/lib/codemirror/codemirror.js
@@
-81,13
+81,10
@@
var CodeMirror = (function(){
var nextNum = 1, barWidth = null;
function sizeBar() {
var nextNum = 1, barWidth = null;
function sizeBar() {
- if (!frame.offsetWidth || !win.Editor) {
- for (var cur = frame; cur.parentNode; cur = cur.parentNode) {
- if (cur != document) {
- clearInterval(sizeInterval);
- return;
- }
- }
+ for (var root = frame; root.parentNode; root = root.parentNode);
+ if (root != document || !win.Editor) {
+ clearInterval(sizeInterval);
+ return;
}
if (nums.offsetWidth != barWidth) {
}
if (nums.offsetWidth != barWidth) {
@@
-135,6
+132,7
@@
var CodeMirror = (function(){
var node = place;
place = function(n){node.appendChild(n);};
}
var node = place;
place = function(n){node.appendChild(n);};
}
+
if (options.lineNumbers) place = wrapLineNumberDiv(place);
place(frame);
if (options.lineNumbers) place = wrapLineNumberDiv(place);
place(frame);
@@
-175,10
+173,14
@@
var CodeMirror = (function(){
getCode: function() {return this.editor.getCode();},
setCode: function(code) {this.editor.importCode(code);},
getCode: function() {return this.editor.getCode();},
setCode: function(code) {this.editor.importCode(code);},
- selection: function() {return this.editor.selectedText();},
+ selection: function() {
this.focusIfIE();
return this.editor.selectedText();},
reindent: function() {this.editor.reindent();},
reindent: function() {this.editor.reindent();},
- reindentSelection: function() {this.editor.reindentSelection(null);},
+ reindentSelection: function() {this.
focusIfIE(); this.
editor.reindentSelection(null);},
+ focusIfIE: function() {
+ // in IE, a lot of selection-related functionality only works when the frame is focused
+ if (this.win.select.ie_selection) this.focus();
+ },
focus: function() {
this.win.focus();
if (this.editor.selectionSnapshot) // IE hack
focus: function() {
this.win.focus();
if (this.editor.selectionSnapshot) // IE hack
@@
-206,10
+208,7
@@
var CodeMirror = (function(){
setParser: function(name) {this.editor.setParser(name);},
setParser: function(name) {this.editor.setParser(name);},
- cursorPosition: function(start) {
- if (this.win.select.ie_selection) this.focus();
- return this.editor.cursorPosition(start);
- },
+ cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);},
firstLine: function() {return this.editor.firstLine();},
lastLine: function() {return this.editor.lastLine();},
nextLine: function(line) {return this.editor.nextLine(line);},
firstLine: function() {return this.editor.firstLine();},
lastLine: function() {return this.editor.lastLine();},
nextLine: function(line) {return this.editor.nextLine(line);},
diff --git
a/project/static/js/lib/codemirror/editor.js
b/project/static/js/lib/codemirror/editor.js
index
0f7a8af
..
3d7a205
100644
(file)
--- a/
project/static/js/lib/codemirror/editor.js
+++ b/
project/static/js/lib/codemirror/editor.js
@@
-80,13
+80,13
@@
var Editor = (function(){
if (text.length) leaving = false;
result.push(node);
}
if (text.length) leaving = false;
result.push(node);
}
- else if (
node.nodeName == "BR"
&& node.childNodes.length == 0) {
+ else if (
isBR(node)
&& node.childNodes.length == 0) {
leaving = true;
result.push(node);
}
else {
forEach(node.childNodes, simplifyNode);
leaving = true;
result.push(node);
}
else {
forEach(node.childNodes, simplifyNode);
- if (!leaving && newlineElements.hasOwnProperty(node.nodeName)) {
+ if (!leaving && newlineElements.hasOwnProperty(node.nodeName
.toUpperCase()
)) {
leaving = true;
if (!atEnd || !top)
result.push(doc.createElement("BR"));
leaving = true;
if (!atEnd || !top)
result.push(doc.createElement("BR"));
@@
-175,7
+175,7
@@
var Editor = (function(){
nodeQueue.push(node);
return yield(node.currentText, c);
}
nodeQueue.push(node);
return yield(node.currentText, c);
}
- else if (
node.nodeName == "BR"
) {
+ else if (
isBR(node)
) {
nodeQueue.push(node);
return yield("\n", c);
}
nodeQueue.push(node);
return yield("\n", c);
}
@@
-195,23
+195,20
@@
var Editor = (function(){
// Determine the text size of a processed node.
function nodeSize(node) {
// Determine the text size of a processed node.
function nodeSize(node) {
- if (node.nodeName == "BR")
- return 1;
- else
- return node.currentText.length;
+ return isBR(node) ? 1 : node.currentText.length;
}
// Search backwards through the top-level nodes until the next BR or
// the start of the frame.
function startOfLine(node) {
}
// Search backwards through the top-level nodes until the next BR or
// the start of the frame.
function startOfLine(node) {
- while (node &&
node.nodeName != "BR"
) node = node.previousSibling;
+ while (node &&
!isBR(node)
) node = node.previousSibling;
return node;
}
function endOfLine(node, container) {
if (!node) node = container.firstChild;
return node;
}
function endOfLine(node, container) {
if (!node) node = container.firstChild;
- else if (
node.nodeName == "BR"
) node = node.nextSibling;
+ else if (
isBR(node)
) node = node.nextSibling;
- while (node &&
node.nodeName != "BR"
) node = node.nextSibling;
+ while (node &&
!isBR(node)
) node = node.nextSibling;
return node;
}
return node;
}
@@
-366,8
+363,6
@@
var Editor = (function(){
this.dirty = [];
if (options.content)
this.importCode(options.content);
this.dirty = [];
if (options.content)
this.importCode(options.content);
- else // FF acts weird when the editable document is completely empty
- container.appendChild(this.doc.createElement("BR"));
if (!options.readOnly) {
if (options.continuousScanning !== false) {
if (!options.readOnly) {
if (options.continuousScanning !== false) {
@@
-506,7
+501,7
@@
var Editor = (function(){
this.checkLine(line);
var accum = [];
for (line = line ? line.nextSibling : this.container.firstChild;
this.checkLine(line);
var accum = [];
for (line = line ? line.nextSibling : this.container.firstChild;
- line &&
line.nodeName != "BR"
; line = line.nextSibling)
+ line &&
!isBR(line)
; line = line.nextSibling)
accum.push(nodeText(line));
return cleanText(accum.join(""));
},
accum.push(nodeText(line));
return cleanText(accum.join(""));
},
@@
-531,7
+526,7
@@
var Editor = (function(){
before = cur;
break;
}
before = cur;
break;
}
- var text =
(cur.innerText || cur.textContent || cur.nodeValue || ""
);
+ var text =
nodeText(cur
);
if (text.length > position) {
before = cur.nextSibling;
content = text.slice(0, position) + content + text.slice(position);
if (text.length > position) {
before = cur.nextSibling;
content = text.slice(0, position) + content + text.slice(position);
@@
-663,7
+658,7
@@
var Editor = (function(){
// Intercept enter and tab, and assign their new functions.
keyDown: function(event) {
if (this.frozen == "leave") this.frozen = null;
// Intercept enter and tab, and assign their new functions.
keyDown: function(event) {
if (this.frozen == "leave") this.frozen = null;
- if (this.frozen && (!this.keyFilter || this.keyFilter(event))
) {
+ if (this.frozen && (!this.keyFilter || this.keyFilter(event))) {
event.stop();
this.frozen(event);
return;
event.stop();
this.frozen(event);
return;
@@
-843,10
+838,10
@@
var Editor = (function(){
home: function() {
var cur = select.selectionTopNode(this.container, true), start = cur;
home: function() {
var cur = select.selectionTopNode(this.container, true), start = cur;
- if (cur === false || !(!cur || cur.isPart ||
cur.nodeName == "BR"
) || !this.container.firstChild)
+ if (cur === false || !(!cur || cur.isPart ||
isBR(cur)
) || !this.container.firstChild)
return false;
return false;
- while (cur &&
cur.nodeName != "BR"
) cur = cur.previousSibling;
+ while (cur &&
!isBR(cur)
) cur = cur.previousSibling;
var next = cur ? cur.nextSibling : this.container.firstChild;
if (next && next != start && next.isPart && hasClass(next, "whitespace"))
select.focusAfterNode(next, this.container);
var next = cur ? cur.nextSibling : this.container.firstChild;
if (next && next != start && next.isPart && hasClass(next, "whitespace"))
select.focusAfterNode(next, this.container);
@@
-901,7
+896,7
@@
var Editor = (function(){
function tryFindMatch() {
var stack = [], ch, ok = true;;
for (var runner = cursor; runner; runner = dir ? runner.nextSibling : runner.previousSibling) {
function tryFindMatch() {
var stack = [], ch, ok = true;;
for (var runner = cursor; runner; runner = dir ? runner.nextSibling : runner.previousSibling) {
- if (runner.className == className &&
runner.nodeName == "SPAN"
&& (ch = paren(runner))) {
+ if (runner.className == className &&
isSpan(runner)
&& (ch = paren(runner))) {
if (forward(ch) == dir)
stack.push(ch);
else if (!stack.length)
if (forward(ch) == dir)
stack.push(ch);
else if (!stack.length)
@@
-910,7
+905,7
@@
var Editor = (function(){
ok = false;
if (!stack.length) break;
}
ok = false;
if (!stack.length) break;
}
- else if (runner.dirty ||
runner.nodeName != "SPAN" && runner.nodeName != "BR"
) {
+ else if (runner.dirty ||
!isSpan(runner) && !isBR(runner)
) {
return {node: runner, status: "dirty"};
}
}
return {node: runner, status: "dirty"};
}
}
@@
-968,7
+963,7
@@
var Editor = (function(){
// selection.
indentRegion: function(start, end, direction) {
var current = (start = startOfLine(start)), before = start && startOfLine(start.previousSibling);
// selection.
indentRegion: function(start, end, direction) {
var current = (start = startOfLine(start)), before = start && startOfLine(start.previousSibling);
- if (
end.nodeName != "BR"
) end = endOfLine(end, this.container);
+ if (
!isBR(end)
) end = endOfLine(end, this.container);
do {
var next = endOfLine(current, this.container);
do {
var next = endOfLine(current, this.container);
@@
-1127,7
+1122,7
@@
var Editor = (function(){
// Backtrack to the first node before from that has a partial
// parse stored.
while (from && (!from.parserFromHere || from.dirty)) {
// Backtrack to the first node before from that has a partial
// parse stored.
while (from && (!from.parserFromHere || from.dirty)) {
- if (maxBacktrack != null &&
from.nodeName == "BR"
&& (--maxBacktrack) < 0)
+ if (maxBacktrack != null &&
isBR(from)
&& (--maxBacktrack) < 0)
return false;
from = from.previousSibling;
}
return false;
from = from.previousSibling;
}
@@
-1208,7
+1203,7
@@
var Editor = (function(){
// Allow empty nodes when they are alone on a line, needed
// for the FF cursor bug workaround (see select.js,
// insertNewlineAtCursor).
// Allow empty nodes when they are alone on a line, needed
// for the FF cursor bug workaround (see select.js,
// insertNewlineAtCursor).
- while (part &&
part.nodeName == "SPAN"
&& part.currentText == "") {
+ while (part &&
isSpan(part)
&& part.currentText == "") {
var old = part;
this.remove();
part = this.get();
var old = part;
this.remove();
part = this.get();
@@
-1230,7
+1225,7
@@
var Editor = (function(){
if (token.value == "\n"){
// The idea of the two streams actually staying synchronized
// is such a long shot that we explicitly check.
if (token.value == "\n"){
// The idea of the two streams actually staying synchronized
// is such a long shot that we explicitly check.
- if (
part.nodeName != "BR"
)
+ if (
!isBR(part)
)
throw "Parser out of sync. Expected BR.";
if (part.dirty || !part.indentation) lineDirty = true;
throw "Parser out of sync. Expected BR.";
if (part.dirty || !part.indentation) lineDirty = true;
@@
-1258,7
+1253,7
@@
var Editor = (function(){
parts.next();
}
else {
parts.next();
}
else {
- if (
part.nodeName != "SPAN"
)
+ if (
!isSpan(part)
)
throw "Parser out of sync. Expected SPAN.";
if (part.dirty)
lineDirty = true;
throw "Parser out of sync. Expected SPAN.";
if (part.dirty)
lineDirty = true;
diff --git
a/project/static/js/lib/codemirror/select.js
b/project/static/js/lib/codemirror/select.js
index
d513ba5
..
7746240
100644
(file)
--- a/
project/static/js/lib/codemirror/select.js
+++ b/
project/static/js/lib/codemirror/select.js
@@
-52,7
+52,7
@@
var select = {};
while (pos && pos.offsetParent) {
y += pos.offsetTop;
// Don't count X offset for <br> nodes
while (pos && pos.offsetParent) {
y += pos.offsetTop;
// Don't count X offset for <br> nodes
- if (
pos.nodeName != "BR"
)
+ if (
!isBR(pos)
)
x += pos.offsetLeft;
pos = pos.offsetParent;
}
x += pos.offsetLeft;
pos = pos.offsetParent;
}
@@
-247,13
+247,17
@@
var select = {};
}
if (cur) {
try{range.moveToElementText(cur);}
}
if (cur) {
try{range.moveToElementText(cur);}
- catch(e){}
+ catch(e){
return false;
}
range.collapse(false);
}
else range.moveToElementText(node.parentNode);
if (count) range.move("character", count);
}
range.collapse(false);
}
else range.moveToElementText(node.parentNode);
if (count) range.move("character", count);
}
- else range.moveToElementText(node);
+ else {
+ try{range.moveToElementText(node);}
+ catch(e){return false;}
+ }
+ return true;
}
// Do a binary search through the container object, comparing
}
// Do a binary search through the container object, comparing
@@
-262,7
+266,7
@@
var select = {};
while (start < end) {
var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle];
if (!node) return false; // Don't ask. IE6 manages this sometimes.
while (start < end) {
var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle];
if (!node) return false; // Don't ask. IE6 manages this sometimes.
-
moveToNodeStart(range2, node)
;
+
if (!moveToNodeStart(range2, node)) return false
;
if (range.compareEndPoints("StartToStart", range2) == 1)
start = middle;
else
if (range.compareEndPoints("StartToStart", range2) == 1)
start = middle;
else
@@
-314,7
+318,7
@@
var select = {};
if (!selection) return null;
var topNode = select.selectionTopNode(container, start);
if (!selection) return null;
var topNode = select.selectionTopNode(container, start);
- while (topNode &&
topNode.nodeName != "BR"
)
+ while (topNode &&
!isBR(topNode)
)
topNode = topNode.previousSibling;
var range = selection.createRange(), range2 = range.duplicate();
topNode = topNode.previousSibling;
var range = selection.createRange(), range2 = range.duplicate();
@@
-407,7
+411,7
@@
var select = {};
// ancestors with a suitable offset. This goes down the DOM tree
// until a 'leaf' is reached (or is it *up* the DOM tree?).
function normalize(point){
// ancestors with a suitable offset. This goes down the DOM tree
// until a 'leaf' is reached (or is it *up* the DOM tree?).
function normalize(point){
- while (point.node.nodeType != 3 &&
point.node.nodeName != "BR"
) {
+ while (point.node.nodeType != 3 &&
!isBR(point.node)
) {
var newNode = point.node.childNodes[point.offset] || point.node.nextSibling;
point.offset = 0;
while (!newNode && point.node.parentNode) {
var newNode = point.node.childNodes[point.offset] || point.node.nextSibling;
point.offset = 0;
while (!newNode && point.node.parentNode) {
@@
-425,8
+429,9
@@
var select = {};
};
select.selectMarked = function () {
};
select.selectMarked = function () {
- if (!currentSelection || !currentSelection.changed) return;
- var win = currentSelection.window, range = win.document.createRange();
+ var cs = currentSelection;
+ if (!(cs && (cs.changed || (webkit && cs.start.node == cs.end.node)))) return;
+ var win = cs.window, range = win.document.createRange();
function setPoint(point, which) {
if (point.node) {
function setPoint(point, which) {
if (point.node) {
@@
-442,8
+447,8
@@
var select = {};
}
}
}
}
- setPoint(c
urrentSelection
.end, "End");
- setPoint(c
urrentSelection
.start, "Start");
+ setPoint(c
s
.end, "End");
+ setPoint(c
s
.start, "Start");
selectRange(range, win);
};
selectRange(range, win);
};
@@
-471,7
+476,7
@@
var select = {};
var offset = start ? range.startOffset : range.endOffset;
// Work around (yet another) bug in Opera's selection model.
if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 &&
var offset = start ? range.startOffset : range.endOffset;
// Work around (yet another) bug in Opera's selection model.
if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 &&
- container.childNodes[range.startOffset] &&
container.childNodes[range.startOffset].nodeName == "BR"
)
+ container.childNodes[range.startOffset] &&
isBR(container.childNodes[range.startOffset])
)
offset--;
// For text nodes, we look at the node itself if the cursor is
offset--;
// For text nodes, we look at the node itself if the cursor is
@@
-486,7
+491,7
@@
var select = {};
// Occasionally, browsers will return the HTML node as
// selection. If the offset is 0, we take the start of the frame
// ('after null'), otherwise, we take the last node.
// Occasionally, browsers will return the HTML node as
// selection. If the offset is 0, we take the start of the frame
// ('after null'), otherwise, we take the last node.
- else if (node.nodeName == "HTML") {
+ else if (node.nodeName
.toUpperCase()
== "HTML") {
return (offset == 1 ? null : container.lastChild);
}
// If the given node is our 'container', we just look up the
return (offset == 1 ? null : container.lastChild);
}
// If the given node is our 'container', we just look up the
@@
-557,7
+562,7
@@
var select = {};
if (!range) return;
var topNode = select.selectionTopNode(container, start);
if (!range) return;
var topNode = select.selectionTopNode(container, start);
- while (topNode &&
topNode.nodeName != "BR"
)
+ while (topNode &&
!isBR(topNode)
)
topNode = topNode.previousSibling;
range = range.cloneRange();
topNode = topNode.previousSibling;
range = range.cloneRange();
diff --git
a/project/static/js/lib/codemirror/undo.js
b/project/static/js/lib/codemirror/undo.js
index
5f717a9
..
97daf59
100644
(file)
--- a/
project/static/js/lib/codemirror/undo.js
+++ b/
project/static/js/lib/codemirror/undo.js
@@
-250,7
+250,7
@@
History.prototype = {
function buildLine(node) {
var text = [];
for (var cur = node ? node.nextSibling : self.container.firstChild;
function buildLine(node) {
var text = [];
for (var cur = node ? node.nextSibling : self.container.firstChild;
- cur &&
cur.nodeName != "BR"
; cur = cur.nextSibling)
+ cur &&
!isBR(cur)
; cur = cur.nextSibling)
if (cur.currentText) text.push(cur.currentText);
return {from: node, to: cur, text: cleanText(text.join(""))};
}
if (cur.currentText) text.push(cur.currentText);
return {from: node, to: cur, text: cleanText(text.join(""))};
}
@@
-275,7
+275,7
@@
History.prototype = {
// Get the BR element after/before the given node.
function nextBR(node, dir) {
var link = dir + "Sibling", search = node[link];
// Get the BR element after/before the given node.
function nextBR(node, dir) {
var link = dir + "Sibling", search = node[link];
- while (search &&
search.nodeName != "BR"
)
+ while (search &&
!isBR(search)
)
search = search[link];
return search;
}
search = search[link];
return search;
}
diff --git
a/project/static/js/lib/codemirror/util.js
b/project/static/js/lib/codemirror/util.js
index
796025e
..
0cd91d4
100644
(file)
--- a/
project/static/js/lib/codemirror/util.js
+++ b/
project/static/js/lib/codemirror/util.js
@@
-123,3
+123,12
@@
function nodeTop(node) {
}
return top;
}
}
return top;
}
+
+function isBR(node) {
+ var nn = node.nodeName;
+ return nn == "BR" || nn == "br";
+}
+function isSpan(node) {
+ var nn = node.nodeName;
+ return nn == "SPAN" || nn == "span";
+}