Changeset 4966

Show
Ignore:
Timestamp:
11/02/09 07:41:56 (4 weeks ago)
Author:
auno
Message:

Fixed template editor weirdness. BugzID#102871 102872

Location:
branches/greyhound/mt-static/codemirror
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/greyhound/mt-static/codemirror/js/editor.js

    r4959 r4966  
    441441 
    442442      if (this.options.autoMatchParens) 
    443         addEventHandler(document.body, "click", method(this, "scheduleParenBlink")); 
     443        addEventHandler(document.body, "click", method(this, "scheduleParenHighlight")); 
    444444    } 
    445445    else if (!options.textWrapping) { 
     
    449449 
    450450  function isSafeKey(code) { 
    451     return (code >= 16 && code <= 18) || // shift, control, alt 
     451    return (code >= 16 && code <= 18) || (code == 13) || // shift, control, alt 
    452452           (code >= 33 && code <= 40); // arrows, home, end 
    453453  } 
     
    696696      // Schedule a paren-highlight event, if configured. 
    697697      if (this.options.autoMatchParens) 
    698         this.scheduleParenBlink(); 
     698        this.scheduleParenHighlight(); 
    699699 
    700700      // The various checks for !altKey are there because AltGr sets both 
     
    727727      } 
    728728      else if ((code == 219 || code == 221) && event.ctrlKey && !event.altKey) { // [, ] 
    729         this.blinkParens(event.shiftKey); 
     729        this.highlightParens(event.shiftKey, true); 
    730730        event.stop(); 
    731731      } 
     
    783783    keyUp: function(event) { 
    784784      this.cursorActivity(isSafeKey(event.keyCode)); 
     785      if (event.keyCode == 13) 
     786        this.scheduleHighlight(); 
    785787    }, 
    786788 
     
    898900    }, 
    899901 
    900     // Delay (or initiate) the next paren blink event. 
    901     scheduleParenBlink: function() { 
     902    // Delay (or initiate) the next paren highlight event. 
     903    scheduleParenHighlight: function() { 
    902904      if (this.parenEvent) this.parent.clearTimeout(this.parenEvent); 
    903905      var self = this; 
    904       this.parenEvent = this.parent.setTimeout(function(){self.blinkParens();}, 300); 
     906      this.parenEvent = this.parent.setTimeout(function(){self.highlightParens();}, 300); 
    905907    }, 
    906908 
     
    909911    // highlight them in green for a moment, or red if no proper match 
    910912    // 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 
    912941      if (!window.select) return; 
    913942      // Clear the event property. 
     
    927956      } 
    928957 
    929       var ch, self = this, cursor = select.selectionTopNode(this.container, true); 
     958      var ch, cursor = select.selectionTopNode(this.container, true); 
    930959      if (!cursor || !this.highlightAtCursor()) return; 
    931960      cursor = select.selectionTopNode(this.container, true); 
     
    957986        return {node: runner, status: runner && ok}; 
    958987      } 
    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       } 
    965988 
    966989      while (true) { 
     
    974997        } 
    975998        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); 
    9811007          break; 
    9821008        } 
  • branches/greyhound/mt-static/codemirror/manual.html

    r4959 r4966  
    226226      the user clicks on the document. Defaults to <code>false</code>. 
    227227      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> 
    228237 
    229238      <dt><code>saveFunction</code></dt><dd>If given a function