Changeset 4932

Show
Ignore:
Timestamp:
10/29/09 11:40:27 (4 weeks ago)
Author:
auno
Message:

Updated new version codemirror for fixing bugs. BugzID#102871 102872 102873

Location:
branches/greyhound
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • branches/greyhound/mt-static/codemirror/css/docs.css

    r4158 r4932  
    1616h2 { 
    1717  font-size: 14pt; 
     18} 
     19 
     20h3 { 
     21  font-size: 12pt; 
    1822} 
    1923 
  • branches/greyhound/mt-static/codemirror/index.html

    r4587 r4932  
    6060  <li><a href="contrib/python/index.html">Python</a> (courtesy of <a href="contrib/python/LICENSE">Timothy Farrell</a>)</li> 
    6161  <li><a href="contrib/lua/index.html">Lua</a> (courtesy of <a href="http://francio.pl/">Franciszek Wawrzak</a>)</li> 
    62   <li><a href="http://stuff.hantl.cz/ruby-in-codemirror/">Ruby</a> (by Michal Hantl, <a href="http://github.com/hakunin/ruby-in-codemirror/tree/master">unfinished</a>)</li> 
     62  <li><a href="http://d.hantl.cz/d/ruby-in-codemirror/">Ruby</a> (by Michal Hantl, <a href="http://github.com/hakunin/ruby-in-codemirror/tree/master">unfinished</a>)</li> 
     63  <li><a href="contrib/sql/index.html">SQL</a> (courtesy of John Benediktsson)</li> 
    6364</ul> 
    6465 
     
    7879<h2>Releases</h2> 
    7980 
     81<p class="rel"><em>23-09-2009</em>: <a 
     82href="http://marijn.haverbeke.nl/codemirror/codemirror-0.64.zip">Version 
     830.64</a>: Solves some issues introduced by the paste-handling changes 
     84from the previous release. Adds <code>setSpellcheck</code>, 
     85<code>setTextWrapping</code>, <code>setIndentUnit</code>, 
     86<code>setUndoDepth</code>, <code>setTabMode</code>, and 
     87<code>setLineNumbers</code> to customise a running editor. Introduces 
     88an <a href="contrib/sql/index.html">SQL</a> parser. Fixes a few small 
     89problems in the <a href="contrib/python/index.html">Python</a> parser. 
     90And, as usual, add workarounds for various newly discovered browser 
     91incompatibilities.</p> 
     92 
    8093<p class="rel"><em>31-08-2009</em>: <a 
    8194href="http://marijn.haverbeke.nl/codemirror/codemirror-0.63.zip">Version 
    82950.63</a>: Overhaul of paste-handling (less fragile), fixes for several 
    8396serious IE8 issues (cursor jumping, end-of-document bugs) and a number 
    84 of small problems. 
    85  
    86 Introduces <a href="contrib/python/index.html">Python</a> 
    87 and <a href="contrib/lua/index.html">Lua</a> parsers. Add 
    88 <code>setParser</code> (on-the-fly mode changing) and 
    89 <code>clearHistory</code> methods. Make parsing passes time-based 
    90 instead of lines-based (see the <code>passTime</code> option).</p> 
     97of small problems.</p> 
    9198 
    9299<p class="rel"><em>30-05-2009</em>: <a 
  • branches/greyhound/mt-static/codemirror/js/codemirror.js

    r4587 r4932  
    2727  // their meaning. 
    2828  setDefaults(CodeMirrorConfig, { 
     29    lang: "en", 
    2930    stylesheet: "", 
    3031    path: "", 
     
    5455  }); 
    5556 
    56   function wrapLineNumberDiv(place) { 
    57     return function(node) { 
    58       var container = document.createElement("DIV"), 
    59           nums = document.createElement("DIV"), 
    60           scroller = document.createElement("DIV"); 
    61       container.style.position = "relative"; 
    62       nums.style.position = "absolute"; 
    63       nums.style.height = "100%"; 
    64       if (nums.style.setExpression) { 
    65         try {nums.style.setExpression("height", "this.previousSibling.offsetHeight + 'px'");} 
    66         catch(e) {} // Seems to throw 'Not Implemented' on some IE8 versions 
    67       } 
    68       nums.style.top = "0px"; 
    69       nums.style.overflow = "hidden"; 
    70       place(container); 
    71       container.appendChild(node); 
    72       container.appendChild(nums); 
    73       scroller.className = "CodeMirror-line-numbers"; 
    74       nums.appendChild(scroller); 
    75     } 
    76   } 
    77  
    78   function applyLineNumbers(frame) { 
     57  function addLineNumberDiv(container) { 
     58    var nums = document.createElement("DIV"), 
     59        scroller = document.createElement("DIV"); 
     60    nums.style.position = "absolute"; 
     61    nums.style.height = "100%"; 
     62    if (nums.style.setExpression) { 
     63      try {nums.style.setExpression("height", "this.previousSibling.offsetHeight + 'px'");} 
     64      catch(e) {} // Seems to throw 'Not Implemented' on some IE8 versions 
     65    } 
     66    nums.style.top = "0px"; 
     67    nums.style.overflow = "hidden"; 
     68    container.appendChild(nums); 
     69    scroller.className = "CodeMirror-line-numbers"; 
     70    nums.appendChild(scroller); 
     71    return nums; 
     72  } 
     73 
     74  function activateLineNumbers(frame, nums) { 
    7975    var win = frame.contentWindow, doc = win.document, 
    80         nums = frame.nextSibling, scroller = nums.firstChild; 
     76        scroller = nums.firstChild; 
    8177 
    8278    var nextNum = 1, barWidth = null; 
    8379    function sizeBar() { 
    84       if (!frame.offsetWidth || !win.Editor) { 
    85         for (var cur = frame; cur.parentNode; cur = cur.parentNode) { 
    86           if (cur != document) { 
    87             clearInterval(sizeInterval); 
    88             return; 
    89           } 
    90         } 
     80      for (var root = frame; root.parentNode; root = root.parentNode); 
     81      if (!nums.parentNode || root != document || !win.Editor) { 
     82        // Clear event handlers (their nodes might already be collected, so try/catch) 
     83        try{onScroll();}catch(e){} 
     84        try{onResize();}catch(e){} 
     85        clearInterval(sizeInterval); 
     86        return; 
    9187      } 
    9288 
     
    105101      nums.scrollTop = doc.body.scrollTop || doc.documentElement.scrollTop || 0; 
    106102    } 
     103    var onScroll = win.addEventHandler(win, "scroll", update, true), 
     104        onResize = win.addEventHandler(win, "resize", update, true), 
     105        sizeInterval = setInterval(sizeBar, 500); 
    107106    sizeBar(); 
    108107    update(); 
    109     win.addEventHandler(win, "scroll", update); 
    110     win.addEventHandler(win, "resize", update); 
    111     var sizeInterval = setInterval(sizeBar, 500); 
    112108  } 
    113109 
     
    132128    frame.style.display = "block"; 
    133129 
    134     if (place.appendChild) { 
    135       var node = place; 
    136       place = function(n){node.appendChild(n);}; 
    137     } 
    138     if (options.lineNumbers) place = wrapLineNumberDiv(place); 
    139     place(frame); 
     130    var div = this.wrapping = document.createElement("DIV"); 
     131    div.style.position = "relative"; 
     132    div.className = "CodeMirror-wrapping"; 
     133    if (place.appendChild) place.appendChild(div); 
     134    else place(div); 
     135    div.appendChild(frame); 
     136    if (options.lineNumbers) this.lineNumbers = addLineNumberDiv(div); 
    140137 
    141138    // Link back to this object, so that the editor can fetch options 
     
    149146      options.stylesheet = [options.stylesheet]; 
    150147 
    151     var html = ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head>"]; 
     148    var html = ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html lang="+options.lang+"><head>"]; 
    152149    // Hack to work around a bunch of IE8-specific problems. 
    153150    html.push("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7\"/>"); 
     
    156153    }); 
    157154    forEach(options.basefiles.concat(options.parserfile), function(file) { 
    158       html.push("<script type=\"text/javascript\" src=\"" + options.path + file + "\"></script>"); 
     155      html.push("<script type=\"text/javascript\" src=\"" + options.path + file + "\"><" + "/script>"); 
    159156    }); 
    160157    html.push("</head><body style=\"border-width: 0;\" class=\"editbox\" spellcheck=\"" + 
     
    170167    init: function() { 
    171168      if (this.options.initCallback) this.options.initCallback(this); 
    172       if (this.options.lineNumbers) applyLineNumbers(this.frame); 
     169      if (this.lineNumbers) activateLineNumbers(this.frame, this.lineNumbers); 
    173170      if (this.options.reindentOnLoad) this.reindent(); 
    174171    }, 
     
    176173    getCode: function() {return this.editor.getCode();}, 
    177174    setCode: function(code) {this.editor.importCode(code);}, 
    178     selection: function() {return this.editor.selectedText();}, 
     175    selection: function() {this.focusIfIE(); return this.editor.selectedText();}, 
    179176    reindent: function() {this.editor.reindent();}, 
    180     reindentSelection: function() {this.editor.reindentSelection(null);}, 
    181  
     177    reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);}, 
     178 
     179    focusIfIE: function() { 
     180      // in IE, a lot of selection-related functionality only works when the frame is focused 
     181      if (this.win.select.ie_selection) this.focus(); 
     182    }, 
    182183    focus: function() { 
    183184      this.win.focus(); 
    184185      if (this.editor.selectionSnapshot) // IE hack 
    185         this.win.select.selectCoords(this.win, this.editor.selectionSnapshot); 
     186        this.win.select.setBookmark(this.win.document.body, this.editor.selectionSnapshot); 
    186187    }, 
    187188    replaceSelection: function(text) { 
     
    193194      this.editor.replaceChars(text, start, end); 
    194195    }, 
    195     getSearchCursor: function(string, fromCursor) { 
    196       return this.editor.getSearchCursor(string, fromCursor); 
     196    getSearchCursor: function(string, fromCursor, caseFold) { 
     197      return this.editor.getSearchCursor(string, fromCursor, caseFold); 
    197198    }, 
    198199 
     
    206207 
    207208    setParser: function(name) {this.editor.setParser(name);}, 
    208  
    209     cursorPosition: function(start) { 
    210       if (this.win.select.ie_selection) this.focus(); 
    211       return this.editor.cursorPosition(start); 
    212     }, 
     209    setSpellcheck: function(on) {this.win.document.body.spellcheck = on;}, 
     210    setTextWrapping: function(on) {this.win.document.body.style.whiteSpace = on ? "" : "nowrap";}, 
     211    setIndentUnit: function(unit) {this.win.indentUnit = unit;}, 
     212    setUndoDepth: function(depth) {this.editor.history.maxDepth = depth;}, 
     213    setTabMode: function(mode) {this.options.tabMode = mode;}, 
     214    setLineNumbers: function(on) { 
     215      if (on && !this.lineNumbers) { 
     216        this.lineNumbers = addLineNumberDiv(this.wrapping); 
     217        activateLineNumbers(this.frame, this.lineNumbers); 
     218      } 
     219      else if (!on && this.lineNumbers) { 
     220        this.wrapping.removeChild(this.lineNumbers); 
     221        this.wrapping.style.marginLeft = ""; 
     222        this.lineNumbers = null; 
     223      } 
     224    }, 
     225 
     226    cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);}, 
    213227    firstLine: function() {return this.editor.firstLine();}, 
    214228    lastLine: function() {return this.editor.lastLine();}, 
  • branches/greyhound/mt-static/codemirror/js/editor.js

    r4587 r4932  
    8181        result.push(node); 
    8282      } 
    83       else if (node.nodeName == "BR" && node.childNodes.length == 0) { 
     83      else if (isBR(node) && node.childNodes.length == 0) { 
    8484        leaving = true; 
    8585        result.push(node); 
     
    8787      else { 
    8888        forEach(node.childNodes, simplifyNode); 
    89         if (!leaving && newlineElements.hasOwnProperty(node.nodeName)) { 
     89        if (!leaving && newlineElements.hasOwnProperty(node.nodeName.toUpperCase())) { 
    9090          leaving = true; 
    9191          if (!atEnd || !top) 
     
    176176        return yield(node.currentText, c); 
    177177      } 
    178       else if (node.nodeName == "BR") { 
     178      else if (isBR(node)) { 
    179179        nodeQueue.push(node); 
    180180        return yield("\n", c); 
     
    196196  // Determine the text size of a processed node. 
    197197  function nodeSize(node) { 
    198     if (node.nodeName == "BR") 
    199       return 1; 
    200     else 
    201       return node.currentText.length; 
     198    return isBR(node) ? 1 : node.currentText.length; 
    202199  } 
    203200 
     
    205202  // the start of the frame. 
    206203  function startOfLine(node) { 
    207     while (node && node.nodeName != "BR") node = node.previousSibling; 
     204    while (node && !isBR(node)) node = node.previousSibling; 
    208205    return node; 
    209206  } 
    210207  function endOfLine(node, container) { 
    211208    if (!node) node = container.firstChild; 
    212     else if (node.nodeName == "BR") node = node.nextSibling; 
    213  
    214     while (node && node.nodeName != "BR") node = node.nextSibling; 
     209    else if (isBR(node)) node = node.nextSibling; 
     210 
     211    while (node && !isBR(node)) node = node.nextSibling; 
    215212    return node; 
    216213  } 
     
    224221  // skip to the next find. Use the select and replace methods to 
    225222  // actually do something with the found locations. 
    226   function SearchCursor(editor, string, fromCursor) { 
     223  function SearchCursor(editor, string, fromCursor, caseFold) { 
    227224    this.editor = editor; 
     225    this.caseFold = caseFold; 
     226    if (caseFold) string = string.toLowerCase(); 
    228227    this.history = editor.history; 
    229228    this.history.commit(); 
     
    253252      // indexOf on the current line. 
    254253      function() { 
    255         var match = cleanText(self.history.textAfter(self.line).slice(self.offset)).indexOf(string); 
     254        var line = cleanText(self.history.textAfter(self.line).slice(self.offset)); 
     255        var match = (self.caseFold ? line.toLowerCase() : line).indexOf(string); 
    256256        if (match > -1) 
    257257          return {from: {node: self.line, offset: self.offset + match}, 
     
    263263      function() { 
    264264        var firstLine = cleanText(self.history.textAfter(self.line).slice(self.offset)); 
    265         var match = firstLine.lastIndexOf(target[0]); 
     265        var match = (self.caseFold ? firstLine.toLowerCase() : firstLine).lastIndexOf(target[0]); 
    266266        if (match == -1 || match != firstLine.length - target[0].length) 
    267267          return false; 
     
    270270        var line = self.history.nodeAfter(self.line); 
    271271        for (var i = 1; i < target.length - 1; i++) { 
    272           if (cleanText(self.history.textAfter(line)) != target[i]) 
     272          var line = cleanText(self.history.textAfter(line)); 
     273          if ((self.caseFold ? line.toLowerCase() : line) != target[i]) 
    273274            return false; 
    274275          line = self.history.nodeAfter(line); 
    275276        } 
    276277 
    277         if (cleanText(self.history.textAfter(line)).indexOf(target[target.length - 1]) != 0) 
     278        var lastLine = cleanText(self.history.textAfter(line)); 
     279        if ((self.caseFold ? lastLine.toLowerCase() : lastLine).indexOf(target[target.length - 1]) != 0) 
    278280          return false; 
    279281 
     
    367369    if (options.content) 
    368370      this.importCode(options.content); 
    369     else // FF acts weird when the editable document is completely empty 
    370       container.appendChild(this.doc.createElement("BR")); 
    371371 
    372372    if (!options.readOnly) { 
     
    403403 
    404404      addEventHandler(document, "keydown", method(this, "keyDown")); 
     405      addEventHandler(document, "keypress", method(this, "keyPress")); 
     406      addEventHandler(document, "keyup", method(this, "keyUp")); 
    405407 
    406408      function cursorActivity() {self.cursorActivity(false);} 
     
    418420        if (text !== null) { 
    419421          self.replaceSelection(text); 
     422          select.scrollToCursor(this.container); 
    420423          event.stop(); 
    421424        } 
    422425      }); 
    423  
    424       addEventHandler(document.body, "beforepaste", method(this, "reroutePasteEvent")); 
    425426 
    426427      if (this.options.autoMatchParens) 
     
    505506      var accum = []; 
    506507      for (line = line ? line.nextSibling : this.container.firstChild; 
    507            line && line.nodeName != "BR"; line = line.nextSibling) 
     508           line && !isBR(line); line = line.nextSibling) 
    508509        accum.push(nodeText(line)); 
    509510      return cleanText(accum.join("")); 
     
    530531            break; 
    531532          } 
    532           var text = (cur.innerText || cur.textContent || cur.nodeValue || ""); 
     533          var text = nodeText(cur); 
    533534          if (text.length > position) { 
    534535            before = cur.nextSibling; 
     
    587588      var te = parent.document.createElement("TEXTAREA"); 
    588589      te.style.position = "absolute"; 
    589       te.style.left = "-500px"; 
     590      te.style.left = "-10000px"; 
    590591      te.style.width = "10px"; 
    591592      te.style.top = nodeTop(frameElement) + "px"; 
    592       parent.document.body.appendChild(te); 
     593      window.frameElement.CodeMirror.wrapping.appendChild(te); 
    593594      parent.focus(); 
    594595      te.focus(); 
     
    599600        self.win.focus(); 
    600601        if (self.selectionSnapshot) // IE hack 
    601           self.win.select.selectCoords(self.win, self.selectionSnapshot); 
     602          self.win.select.setBookmark(self.container, self.selectionSnapshot); 
    602603        var text = te.value; 
    603         if (text) self.replaceSelection(text); 
     604        if (text) { 
     605          self.replaceSelection(text); 
     606          select.scrollToCursor(self.container); 
     607        } 
    604608        removeElement(te); 
    605609      }, 10); 
     
    617621    }, 
    618622 
    619     getSearchCursor: function(string, fromCursor) { 
    620       return new SearchCursor(this, string, fromCursor); 
     623    getSearchCursor: function(string, fromCursor, caseFold) { 
     624      return new SearchCursor(this, string, fromCursor, caseFold); 
    621625    }, 
    622626 
     
    698702      } 
    699703      else if (code == 36 && !event.shiftKey && !event.ctrlKey) { // home 
    700         if (this.home()) 
    701           event.stop(); 
     704        if (this.home()) event.stop(); 
     705      } 
     706      else if (code == 35 && !event.shiftKey && !event.ctrlKey) { // end 
     707        if (this.end()) event.stop(); 
    702708      } 
    703709      else if ((code == 219 || code == 221) && event.ctrlKey && !event.altKey) { // [, ] 
     
    728734          this.options.saveFunction(); 
    729735          event.stop(); 
     736        } 
     737        else if (internetExplorer && code == 86) { 
     738          this.reroutePasteEvent(); 
    730739        } 
    731740      } 
     
    840849    }, 
    841850 
     851    // Custom home behaviour that doesn't land the cursor in front of 
     852    // leading whitespace unless pressed twice. 
    842853    home: function() { 
    843854      var cur = select.selectionTopNode(this.container, true), start = cur; 
    844       if (cur === false || !(!cur || cur.isPart || cur.nodeName == "BR") || !this.container.firstChild) 
     855      if (cur === false || !(!cur || cur.isPart || isBR(cur)) || !this.container.firstChild) 
    845856        return false; 
    846857 
    847       while (cur && cur.nodeName != "BR") cur = cur.previousSibling; 
     858      while (cur && !isBR(cur)) cur = cur.previousSibling; 
    848859      var next = cur ? cur.nextSibling : this.container.firstChild; 
    849860      if (next && next != start && next.isPart && hasClass(next, "whitespace")) 
     
    852863        select.focusAfterNode(cur, this.container); 
    853864 
     865      select.scrollToCursor(this.container); 
     866      return true; 
     867    }, 
     868 
     869    // Some browsers (Opera) don't manage to handle the end key 
     870    // properly in the face of vertical scrolling. 
     871    end: function() { 
     872      var cur = select.selectionTopNode(this.container, true); 
     873      if (cur === false) return false; 
     874      cur = endOfLine(cur, this.container); 
     875      if (!cur) return false; 
     876      select.focusAfterNode(cur.previousSibling, this.container); 
    854877      select.scrollToCursor(this.container); 
    855878      return true; 
     
    900923        var stack = [], ch, ok = true;; 
    901924        for (var runner = cursor; runner; runner = dir ? runner.nextSibling : runner.previousSibling) { 
    902           if (runner.className == className && runner.nodeName == "SPAN" && (ch = paren(runner))) { 
     925          if (runner.className == className && isSpan(runner) && (ch = paren(runner))) { 
    903926            if (forward(ch) == dir) 
    904927              stack.push(ch); 
     
    909932            if (!stack.length) break; 
    910933          } 
    911           else if (runner.dirty || runner.nodeName != "SPAN" && runner.nodeName != "BR") { 
     934          else if (runner.dirty || !isSpan(runner) && !isBR(runner)) { 
    912935            return {node: runner, status: "dirty"}; 
    913936          } 
     
    945968    // the cursor is on so that it is indented properly. 
    946969    indentAtCursor: function(direction) { 
     970      return; 
    947971      if (!this.container.firstChild) return; 
    948972      // The line has to have up-to-date lexical information, so we 
    949973      // highlight it first. 
    950974      if (!this.highlightAtCursor()) return; 
    951       // prevent indent for now. 
    952       return; 
    953975      var cursor = select.selectionTopNode(this.container, false); 
    954976      // If we couldn't determine the place of the cursor, 
     
    969991    indentRegion: function(start, end, direction) { 
    970992      var current = (start = startOfLine(start)), before = start && startOfLine(start.previousSibling); 
    971       if (end.nodeName != "BR") end = endOfLine(end, this.container); 
     993      if (!isBR(end)) end = endOfLine(end, this.container); 
    972994 
    973995      do { 
     
    9861008      if (internetExplorer) { 
    9871009        this.container.createTextRange().execCommand("unlink"); 
    988         this.selectionSnapshot = select.selectionCoords(this.win); 
     1010        this.selectionSnapshot = select.getBookmark(this.container); 
    9891011      } 
    9901012 
     
    9961018        if (activity) activity(cursor); 
    9971019        if (!safe) { 
    998           this.scheduleHighlight(); 
     1020//          this.scheduleHighlight(); 
    9991021          this.addDirtyNode(cursor); 
    10001022        } 
     
    11281150      // parse stored. 
    11291151      while (from && (!from.parserFromHere || from.dirty)) { 
    1130         if (maxBacktrack != null && from.nodeName == "BR" && (--maxBacktrack) < 0) 
     1152        if (maxBacktrack != null && isBR(from) && (--maxBacktrack) < 0) 
    11311153          return false; 
    11321154        from = from.previousSibling; 
     
    12091231          // for the FF cursor bug workaround (see select.js, 
    12101232          // insertNewlineAtCursor). 
    1211           while (part && part.nodeName == "SPAN" && part.currentText == "") { 
     1233          while (part && isSpan(part) && part.currentText == "") { 
    12121234            var old = part; 
    12131235            this.remove(); 
     
    12311253          // The idea of the two streams actually staying synchronized 
    12321254          // is such a long shot that we explicitly check. 
    1233           if (part.nodeName != "BR") 
     1255          if (!isBR(part)) 
    12341256            throw "Parser out of sync. Expected BR."; 
    12351257 
     
    12591281        } 
    12601282        else { 
    1261           if (part.nodeName != "SPAN") 
     1283          if (!isSpan(part)) 
    12621284            throw "Parser out of sync. Expected SPAN."; 
    12631285          if (part.dirty) 
  • branches/greyhound/mt-static/codemirror/js/mirrorframe.js

    r4158 r4932  
    3737    var first = true; 
    3838    do { 
    39       var cursor = this.mirror.getSearchCursor(text, first); 
     39      var cursor = this.mirror.getSearchCursor(text, first, true); 
    4040      first = false; 
    4141      while (cursor.findNext()) { 
  • branches/greyhound/mt-static/codemirror/js/parsejavascript.js

    r4158 r4932  
    1111  // Token types that can be considered to be atoms. 
    1212  var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true}; 
     13  // Setting that can be used to have JSON data indent properly. 
     14  var json = false; 
    1315  // Constructor for the lexical context objects. 
    1416  function JSLexical(indented, column, type, align, prev, info) { 
     
    231233      else if (type == "keyword a") cont(pushlex("form"), expression, statement, poplex); 
    232234      else if (type == "keyword b") cont(pushlex("form"), statement, poplex); 
     235      else if (type == "{" && json) cont(pushlex("}"), commasep(objprop, "}"), poplex); 
    233236      else if (type == "{") cont(pushlex("}"), block, poplex); 
    234237      else if (type == "function") cont(functiondef); 
     
    338341  } 
    339342 
    340   return {make: parseJS, electricChars: "{}:"}; 
     343  return { 
     344    make: parseJS, 
     345    electricChars: "{}:", 
     346    configure: function(obj) { 
     347      if (obj.json != null) json = obj.json; 
     348    } 
     349  }; 
    341350})(); 
  • branches/greyhound/mt-static/codemirror/js/select.js

    r4587 r4932  
    3838                || !element.nextSibling.nextSibling.nextSibling; 
    3939    // In Opera (and recent Webkit versions), BR elements *always* 
    40     // have a scrollTop property of zero. 
     40    // have a offsetTop property of zero. 
    4141    var compensateHack = 0; 
    4242    while (element && !element.offsetTop) { 
     
    5353      y += pos.offsetTop; 
    5454      // Don't count X offset for <br> nodes 
    55       if (pos.nodeName != "BR") 
     55      if (!isBR(pos)) 
    5656        x += pos.offsetLeft; 
    5757      pos = pos.offsetParent; 
     
    248248          if (cur) { 
    249249            try{range.moveToElementText(cur);} 
    250             catch(e){} 
     250            catch(e){return false;} 
    251251            range.collapse(false); 
    252252          } 
     
    254254          if (count) range.move("character", count); 
    255255        } 
    256         else range.moveToElementText(node); 
     256        else { 
     257          try{range.moveToElementText(node);} 
     258          catch(e){return false;} 
     259        } 
     260        return true; 
    257261      } 
    258262 
     
    263267        var middle = Math.ceil((end + start) / 2), node = container.childNodes[middle]; 
    264268        if (!node) return false; // Don't ask. IE6 manages this sometimes. 
    265         moveToNodeStart(range2, node); 
     269        if (!moveToNodeStart(range2, node)) return false; 
    266270        if (range.compareEndPoints("StartToStart", range2) == 1) 
    267271          start = middle; 
     
    315319 
    316320      var topNode = select.selectionTopNode(container, start); 
    317       while (topNode && topNode.nodeName != "BR") 
     321      while (topNode && !isBR(topNode)) 
    318322        topNode = topNode.previousSibling; 
    319323 
     
    357361 
    358362    // Some hacks for storing and re-storing the selection when the editor loses and regains focus. 
    359     select.selectionCoords = function (win) { 
    360       var selection = win.document.selection; 
    361       if (!selection) return null; 
    362       var start = selection.createRange(), end = start.duplicate(); 
    363       start.collapse(true); 
    364       end.collapse(false); 
    365  
    366       var body = win.document.body; 
    367       return {start: {x: start.boundingLeft + body.scrollLeft - 1, 
    368                       y: start.boundingTop + body.scrollTop}, 
    369               end: {x: end.boundingLeft + body.scrollLeft - 1, 
    370                     y: end.boundingTop + body.scrollTop}}; 
     363    select.getBookmark = function (container) { 
     364      var from = select.cursorPos(container, true), to = select.cursorPos(container, false); 
     365      if (from && to) return {from: from, to: to}; 
    371366    }; 
    372367 
    373368    // Restore a stored selection. 
    374     select.selectCoords = function(win, coords) { 
    375       if (!coords) return; 
    376  
    377       var range1 = win.document.body.createTextRange(), range2 = range1.duplicate(); 
    378       // This can fail for various hard-to-handle reasons. 
    379       try { 
    380         range1.moveToPoint(coords.start.x, coords.start.y); 
    381         range2.moveToPoint(coords.end.x, coords.end.y); 
    382         range1.setEndPoint("EndToStart", range2); 
    383         range1.select(); 
    384       } catch(e) {} 
     369    select.setBookmark = function(container, mark) { 
     370      if (!mark) return; 
     371      select.setCursorPos(container, mark.from, mark.to); 
    385372    }; 
    386373  } 
     
    408395      // until a 'leaf' is reached (or is it *up* the DOM tree?). 
    409396      function normalize(point){ 
    410         while (point.node.nodeType != 3 && point.node.nodeName != "BR") { 
     397        while (point.node.nodeType != 3 && !isBR(point.node)) { 
    411398          var newNode = point.node.childNodes[point.offset] || point.node.nextSibling; 
    412399          point.offset = 0; 
     
    426413 
    427414    select.selectMarked = function () { 
    428       if (!currentSelection || !currentSelection.changed) return; 
    429       var win = currentSelection.window, range = win.document.createRange(); 
     415      var cs = currentSelection; 
     416      if (!(cs && (cs.changed || (webkit && cs.start.node == cs.end.node)))) return; 
     417      var win = cs.window, range = win.document.createRange(); 
    430418 
    431419      function setPoint(point, which) { 
     
    443431      } 
    444432 
    445       setPoint(currentSelection.end, "End"); 
    446       setPoint(currentSelection.start, "Start"); 
     433      setPoint(cs.end, "End"); 
     434      setPoint(cs.start, "Start"); 
    447435      selectRange(range, win); 
    448436    }; 
     
    472460      // Work around (yet another) bug in Opera's selection model. 
    473461      if (window.opera && !start && range.endContainer == container && range.endOffset == range.startOffset + 1 && 
    474           container.childNodes[range.startOffset] && container.childNodes[range.startOffset].nodeName == "BR") 
     462          container.childNodes[range.startOffset] && isBR(container.childNodes[range.startOffset])) 
    475463        offset--; 
    476464 
     
    487475      // selection. If the offset is 0, we take the start of the frame 
    488476      // ('after null'), otherwise, we take the last node. 
    489       else if (node.nodeName == "HTML") { 
     477      else if (node.nodeName.toUpperCase() == "HTML") { 
    490478        return (offset == 1 ? null : container.lastChild); 
    491479      } 
     
    558546 
    559547      var topNode = select.selectionTopNode(container, start); 
    560       while (topNode && topNode.nodeName != "BR") 
     548      while (topNode && !isBR(topNode)) 
    561549        topNode = topNode.previousSibling; 
    562550 
  • branches/greyhound/mt-static/codemirror/js/tokenizejavascript.js

    r4158 r4932  
    4949 
    5050  // Some helper regexps 
    51   var isOperatorChar = /[+\-*&%\/=<>!?|]/; 
     51  var isOperatorChar = /[+\-*&%=<>!?|]/; 
    5252  var isHexDigit = /[0-9A-Fa-f]/; 
    5353  var isWordChar = /[\w\$_]/; 
  • branches/greyhound/mt-static/codemirror/js/undo.js

    r4587 r4932  
    110110    } 
    111111    this.pushChains([chain], from == null && to == null); 
     112    if (this.onChange) this.onChange(); 
    112113  }, 
    113114 
     
    251252      var text = []; 
    252253      for (var cur = node ? node.nextSibling : self.container.firstChild; 
    253            cur && cur.nodeName != "BR"; cur = cur.nextSibling) 
     254           cur && !isBR(cur); cur = cur.nextSibling) 
    254255        if (cur.currentText) text.push(cur.currentText); 
    255256      return {from: node, to: cur, text: cleanText(text.join(""))}; 
     
    276277    function nextBR(node, dir) { 
    277278      var link = dir + "Sibling", search = node[link]; 
    278       while (search && search.nodeName != "BR") 
     279      while (search && !isBR(search)) 
    279280        search = search[link]; 
    280281      return search; 
  • branches/greyhound/mt-static/codemirror/js/util.js

    r4587 r4932  
    113113 
    114114function nodeText(node) { 
    115   return node.innerText || node.textContent || node.nodeValue || ""; 
     115  return node.textContent || node.innerText || node.nodeValue || ""; 
    116116} 
    117117 
     
    124124  return top; 
    125125} 
     126 
     127function isBR(node) { 
     128  var nn = node.nodeName; 
     129  return nn == "BR" || nn == "br"; 
     130} 
     131function isSpan(node) { 
     132  var nn = node.nodeName; 
     133  return nn == "SPAN" || nn == "span"; 
     134} 
  • branches/greyhound/mt-static/codemirror/manual.html

    r4587 r4932  
    234234 
    235235      <dt><code>undoDepth</code></dt><dd>Maximum length of the undo 
    236       history. Default is 50.</dd> 
     236      history. Default is 50. This setting is changeable with the 
     237      <code>setUndoDepth(depth)</code> method on CodeMirror 
     238      instances.</dd> 
    237239 
    238240      <dt><code>onChange</code></dt><dd>An optional function of zero 
     
    252254      disable spell-checking on browsers that support it (Firefox 2+). 
    253255      Default is <code>true</code>, since for most code spell-checking 
    254       is useless.</dd> 
     256      is useless. Can be changed with the 
     257      <code>setSpellCheck(on)</code> method.</dd> 
    255258 
    256259      <dt><code>textWrapping</code></dt><dd>Can be used to disable or 
    257260      enable text-wrapping in the editor frame. Default is 
    258       <code>true</code>.</dd> 
     261      <code>true</code>. Changeable with the 
     262      <code>setTextWrapping(on)</code> method.</dd> 
    259263 
    260264      <dt><code>lineNumbers</code></dt><dd>Show line numbers to the 
     
    268272      <code>false</code>. When enabling this, you have to disable 
    269273      <code>textWrapping</code>, since the line numbers don't take 
    270       wrapped lines into account.</dd> 
     274      wrapped lines into account. Changeable with the 
     275      <code>setLineNumbers(on)</code> method.</dd> 
    271276 
    272277      <dt><code>indentUnit</code></dt><dd>An integer that specifies 
    273278      the amount of spaces one 'level' of indentation should add. 
    274       Default is <code>2</code>.</dd> 
     279      Default is <code>2</code>. Changeable in a running editor using 
     280      the <code>setIndentUnit(spaces)</code> method.</dd> 
    275281 
    276282      <dt><code>tabMode</code></dt><dd>Determines what the effect of 
     
    290296        deeper, pressing shift-tab or ctrl-tab (whichever your browser 
    291297        does not interfere with), un-indents it.</dd> 
    292       </dl></dd> 
     298      </dl> 
     299      This option can be changed at run-time using the 
     300      <code>setTabMode(mode)</code> method.</dd> 
    293301 
    294302      <dt><code>reindentOnLoad</code></dt><dd>When <code>true</code>, 
     
    356364      href="jstest.html">demo</a>)</dt><dd>The JavaScript parser. 
    357365      Example colours in <code><a 
    358       href="css/jscolors.css">css/jscolors.css</a></code></dd> 
     366      href="css/jscolors.css">css/jscolors.css</a></code>. Takes one 
     367      configuration option, <code>json</code>, that can be set when 
     368      the editor content is JSON data. It causes every opening brace 
     369      to be treated as the start of an object, rather than a 
     370      block.</dd> 
    359371 
    360372      <dt><code><a href="js/parsecss.js">parsecss.js</a></code> (<a 
     
    404416    plain editable field, without any accompanying buttons, bells, and 
    405417    whistles. <code>CodeMirror</code> objects do, however, provide a 
    406     number of methods that make it possible to add extra functionality 
    407     around the editor. <a 
    408     href="js/mirrorframe.js"><code>mirrorframe.js</code></a> provides a 
    409     basic example of their usage.</p> 
     418    number of methods and properties that make it possible to add 
     419    extra functionality around the editor. <a 
     420    href="js/mirrorframe.js"><code>mirrorframe.js</code></a> provides 
     421    a basic example of their usage.</p> 
     422 
     423    <h3>Properties</h3> 
    410424 
    411425    <dl> 
    412  
     426      <dt><code>frame</code></dt><dd>The editable frame.</dd> 
     427      <dt><code>win</code></dt><dd>The window of the editable frame. 
     428      Mostly useful for attaching event handlers.</dd> 
     429      <dt><code>wrapping</code></dt><dd>The <code>DIV</code> element 
     430      wrapped around the frame. This always has a CSS class of 
     431      <code>CodeMirror-wrapping</code>.</dd> 
     432    </dl> 
     433 
     434    <h3>Methods</h3> 
     435 
     436    <dl> 
    413437      <dt><code>getCode()</code> &#8594; 
    414438      <code>string</code></dt><dd>Returns the current content of the 
     
    444468      re-indent the selected lines.</dd> 
    445469 
    446       <dt><code>getSearchCursor(string, atCursor)</code> &#8594; 
    447       <code>cursor</code></dt><dd>The first argument indicates the 
    448       string that should be searched for, and the second indicates 
     470      <dt><code>getSearchCursor(string, atCursor, caseFold)</code> 
     471      &#8594; <code>cursor</code></dt><dd>The first argument indicates 
     472      the string that should be searched for, and the second indicates 
    449473      whether searching should start at the cursor (<code>true</code>) 
    450       or at the start of the document (<code>false</code>). Returns an 
    451       object that provides an interface for searching. Call its 
    452       <code>findNext()</code> method to search for an occurrence of 
    453       the given string. This returns <code>true</code> if something is 
    454       found, or <code>false</code> if the end of document is reached. 
    455       When an occurrence has been found, you can call 
    456       <code>select()</code> to select it, or 
     474      or at the start of the document (<code>false</code>). When 
     475      <code>caseFold</code> is true, the search will be 
     476      case-insensivive. Returns an object that provides an interface 
     477      for searching. Call its <code>findNext()</code> method to search 
     478      for an occurrence of the given string. This returns 
     479      <code>true</code> if something is found, or <code>false</code> 
     480      if the end of document is reached. When an occurrence has been 
     481      found, you can call <code>select()</code> to select it, or 
    457482      <code>replace(string)</code> to replace it with a given string. 
    458483      Note that letting the user change the document, or 
  • branches/greyhound/tmpl/cms/edit_template.tmpl

    r4858 r4932  
    775775    tabMode: "default", 
    776776    indentUnit: 0, 
    777     height: "500px" 
     777    height: "500px", 
     778    lang: "<mt:var name="language_tag">" 
    778779}); 
    779780/* ]]> */