Changeset 4966
- Timestamp:
- 11/02/09 07:41:56 (4 weeks ago)
- Location:
- branches/greyhound/mt-static/codemirror
- Files:
-
- 2 modified
-
js/editor.js (modified) (10 diffs)
-
manual.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/greyhound/mt-static/codemirror/js/editor.js
r4959 r4966 441 441 442 442 if (this.options.autoMatchParens) 443 addEventHandler(document.body, "click", method(this, "scheduleParen Blink"));443 addEventHandler(document.body, "click", method(this, "scheduleParenHighlight")); 444 444 } 445 445 else if (!options.textWrapping) { … … 449 449 450 450 function isSafeKey(code) { 451 return (code >= 16 && code <= 18) || // shift, control, alt451 return (code >= 16 && code <= 18) || (code == 13) || // shift, control, alt 452 452 (code >= 33 && code <= 40); // arrows, home, end 453 453 } … … 696 696 // Schedule a paren-highlight event, if configured. 697 697 if (this.options.autoMatchParens) 698 this.scheduleParen Blink();698 this.scheduleParenHighlight(); 699 699 700 700 // The various checks for !altKey are there because AltGr sets both … … 727 727 } 728 728 else if ((code == 219 || code == 221) && event.ctrlKey && !event.altKey) { // [, ] 729 this. blinkParens(event.shiftKey);729 this.highlightParens(event.shiftKey, true); 730 730 event.stop(); 731 731 } … … 783 783 keyUp: function(event) { 784 784 this.cursorActivity(isSafeKey(event.keyCode)); 785 if (event.keyCode == 13) 786 this.scheduleHighlight(); 785 787 }, 786 788 … … 898 900 }, 899 901 900 // Delay (or initiate) the next paren blinkevent.901 scheduleParen Blink: function() {902 // Delay (or initiate) the next paren highlight event. 903 scheduleParenHighlight: function() { 902 904 if (this.parenEvent) this.parent.clearTimeout(this.parenEvent); 903 905 var self = this; 904 this.parenEvent = this.parent.setTimeout(function(){self. blinkParens();}, 300);906 this.parenEvent = this.parent.setTimeout(function(){self.highlightParens();}, 300); 905 907 }, 906 908 … … 909 911 // highlight them in green for a moment, or red if no proper match 910 912 // was found. 911 blinkParens: function(jump) { 913 highlightParens: function(jump, fromKey) { 914 var self = this; 915 // give the relevant nodes a colour. 916 function highlight(node, ok) { 917 if (!node) return; 918 if (self.options.markParen) { 919 self.options.markParen(node, ok); 920 } 921 else { 922 node.style.fontWeight = "bold"; 923 node.style.color = ok ? "#8F8" : "#F88"; 924 } 925 } 926 function unhighlight(node) { 927 if (!node) return; 928 if (self.options.unmarkParen) { 929 self.options.unmarkParen(node); 930 } 931 else { 932 node.style.fontWeight = ""; 933 node.style.color = ""; 934 } 935 } 936 if (!fromKey && self.highlighted) { 937 unhighlight(self.highlighted[0]); 938 unhighlight(self.highlighted[1]); 939 } 940 912 941 if (!window.select) return; 913 942 // Clear the event property. … … 927 956 } 928 957 929 var ch, self = this,cursor = select.selectionTopNode(this.container, true);958 var ch, cursor = select.selectionTopNode(this.container, true); 930 959 if (!cursor || !this.highlightAtCursor()) return; 931 960 cursor = select.selectionTopNode(this.container, true); … … 957 986 return {node: runner, status: runner && ok}; 958 987 } 959 // Temporarily give the relevant nodes a colour.960 function blink(node, ok) {961 node.style.fontWeight = "bold";962 node.style.color = ok ? "#8F8" : "#F88";963 self.parent.setTimeout(function() {node.style.fontWeight = ""; node.style.color = "";}, 500);964 }965 988 966 989 while (true) { … … 974 997 } 975 998 else { 976 blink(cursor, found.status); 977 if (found.node) { 978 blink(found.node, found.status); 979 if (jump) select.focusAfterNode(found.node.previousSibling, this.container); 980 } 999 highlight(cursor, found.status); 1000 highlight(found.node, found.status); 1001 if (fromKey) 1002 self.parent.setTimeout(function() {unhighlight(cursor); unhighlight(found.node);}, 500); 1003 else 1004 self.highlighted = [cursor, found.node]; 1005 if (jump && found.node) 1006 select.focusAfterNode(found.node.previousSibling, this.container); 981 1007 break; 982 1008 } -
branches/greyhound/mt-static/codemirror/manual.html
r4959 r4966 226 226 the user clicks on the document. Defaults to <code>false</code>. 227 227 Might be expensive for big documents.</dd> 228 229 <dt><code>markParen</code>, 230 <code>unmarkParen</code></dt><dd>Functions. Can be used to 231 customise the way brackets are marked (and unmarked) when 232 matched. Both take the bracket's <code>SPAN</code> node as their 233 first argument, and <code>markParen</code> takes a second 234 boolean argument indicating whether a successful match was 235 found. The default is to make the brackets bold and green (or 236 red, if not matched).</dd> 228 237 229 238 <dt><code>saveFunction</code></dt><dd>If given a function
