Diff
Modified: trunk/Source/WebCore/ChangeLog (145519 => 145520)
--- trunk/Source/WebCore/ChangeLog 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/ChangeLog 2013-03-12 11:18:54 UTC (rev 145520)
@@ -1,3 +1,28 @@
+2013-03-12 Andrey Lushnikov <lushni...@chromium.org>
+
+ Web Inspector: [CodeMirror] highlight matching braces
+ https://bugs.webkit.org/show_bug.cgi?id=112041
+
+ Reviewed by Vsevolod Vlasov.
+
+ Add "matchbrackets" add-on to CodeMirror text editor add override
+ default styles for matched and unmatched braces.
+
+ No new tests.
+
+ * WebCore.gypi:
+ * WebCore.vcproj/WebCore.vcproj:
+ * WebCore.vcxproj/WebCore.vcxproj:
+ * WebCore.vcxproj/WebCore.vcxproj.filters:
+ * inspector/front-end/CodeMirrorTextEditor.js:
+ (WebInspector.CodeMirrorTextEditor):
+ * inspector/front-end/WebKit.qrc:
+ * inspector/front-end/cm/cmdevtools.css:
+ (.CodeMirror-matchingbracket):
+ (.CodeMirror-nonmatchingbracket):
+ * inspector/front-end/cm/matchbrackets.js: Added.
+ (.):
+
2013-03-12 Matt Falkenhagen <fal...@chromium.org>
Refactoring: Pull Node::disabled() and Node::isInert() down to Element.
Modified: trunk/Source/WebCore/WebCore.gypi (145519 => 145520)
--- trunk/Source/WebCore/WebCore.gypi 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/WebCore.gypi 2013-03-12 11:18:54 UTC (rev 145520)
@@ -5593,6 +5593,7 @@
'inspector/front-end/cm/codemirror.js',
'inspector/front-end/cm/css.js',
'inspector/front-end/cm/htmlmixed.js',
+ 'inspector/front-end/cm/matchbrackets.js',
'inspector/front-end/cm/_javascript_.js',
'inspector/front-end/cm/xml.js',
],
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (145519 => 145520)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2013-03-12 11:18:54 UTC (rev 145520)
@@ -77398,6 +77398,10 @@
>
</File>
<File
+ RelativePath="..\inspector\front-end\cm\matchbrackets.js"
+ >
+ </File>
+ <File
RelativePath="..\inspector\front-end\ImageView.js"
>
</File>
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (145519 => 145520)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj 2013-03-12 11:18:54 UTC (rev 145520)
@@ -10980,6 +10980,7 @@
<None Include="..\inspector\front-end\helpScreen.css" />
<None Include="..\inspector\front-end\HelpScreen.js" />
<None Include="..\inspector\front-end\cm\htmlmixed.js" />
+ <None Include="..\inspector\front-end\cm\matchbrackets.js" />
<None Include="..\inspector\front-end\ImageView.js" />
<None Include="..\inspector\front-end\IndexedDBModel.js" />
<None Include="..\inspector\front-end\indexedDBViews.css" />
Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (145519 => 145520)
--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters 2013-03-12 11:18:54 UTC (rev 145520)
@@ -14707,6 +14707,9 @@
<None Include="..\inspector\front-end\cm\htmlmixed.js">
<Filter>inspector\front-end</Filter>
</None>
+ <None Include="..\inspector\front-end\cm\matchbrackets.js">
+ <Filter>inspector\front-end</Filter>
+ </None>
<None Include="..\inspector\front-end\ImageView.js">
<Filter>inspector\front-end</Filter>
</None>
@@ -15294,4 +15297,4 @@
<Filter>rendering</Filter>
</CustomBuildStep>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
Modified: trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js (145519 => 145520)
--- trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-12 11:18:54 UTC (rev 145520)
@@ -33,6 +33,7 @@
importScript("cm/_javascript_.js");
importScript("cm/xml.js");
importScript("cm/htmlmixed.js");
+importScript("cm/matchbrackets.js");
/**
* @constructor
@@ -52,7 +53,8 @@
this._codeMirror = window.CodeMirror(this.element, {
lineNumbers: true,
- gutters: ["CodeMirror-linenumbers", "breakpoints"]
+ gutters: ["CodeMirror-linenumbers", "breakpoints"],
+ matchBrackets: true
});
var indent = WebInspector.settings.textEditorIndent.get();
Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (145519 => 145520)
--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc 2013-03-12 11:18:54 UTC (rev 145520)
@@ -41,6 +41,7 @@
<file>cm/codemirror.js</file>
<file>cm/css.js</file>
<file>cm/htmlmixed.js</file>
+ <file>cm/matchbrackets.js</file>
<file>cm/_javascript_.js</file>
<file>cm/xml.js</file>
<file>Database.js</file>
Modified: trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css (145519 => 145520)
--- trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css 2013-03-12 11:18:29 UTC (rev 145519)
+++ trunk/Source/WebCore/inspector/front-end/cm/cmdevtools.css 2013-03-12 11:18:54 UTC (rev 145520)
@@ -31,9 +31,20 @@
.cm-breakpoint-disabled {
opacity: 0.5;
}
+
+.CodeMirror-matchingbracket {
+ border-bottom: 1px solid black;
+ color: black !important;
+}
+
+.CodeMirror-nonmatchingbracket {
+ color: black !important;
+}
+
.cm-breakpoint-conditional {
-webkit-border-image: url(Images/breakpointConditionalBorder.png) 1 14 1 2;
}
+
.cm-execution-line {
background-color: rgb(171, 191, 254) !important;
outline: 1px solid rgb(64, 115, 244);
Added: trunk/Source/WebCore/inspector/front-end/cm/matchbrackets.js (0 => 145520)
--- trunk/Source/WebCore/inspector/front-end/cm/matchbrackets.js (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/cm/matchbrackets.js 2013-03-12 11:18:54 UTC (rev 145520)
@@ -0,0 +1,74 @@
+(function() {
+ var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
+ (document.documentMode == null || document.documentMode < 8);
+
+ var Pos = CodeMirror.Pos;
+ // Disable brace matching in long lines, since it'll cause hugely slow updates
+ var maxLineLen = 1000;
+
+ var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
+ function findMatchingBracket(cm) {
+ var cur = cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
+ var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
+ if (!match) return null;
+ var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
+ var style = cm.getTokenAt(Pos(cur.line, pos + 1)).type;
+
+ var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
+ function scan(line, lineNo, start) {
+ if (!line.text) return;
+ var pos = forward ? 0 : line.text.length - 1, end = forward ? line.text.length : -1;
+ if (start != null) pos = start + d;
+ for (; pos != end; pos += d) {
+ var ch = line.text.charAt(pos);
+ if (re.test(ch) && cm.getTokenAt(Pos(lineNo, pos + 1)).type == style) {
+ var match = matching[ch];
+ if (match.charAt(1) == ">" == forward) stack.push(ch);
+ else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
+ else if (!stack.length) return {pos: pos, match: true};
+ }
+ }
+ }
+ for (var i = cur.line, found, e = forward ? Math.min(i + 100, cm.lineCount()) : Math.max(-1, i - 100); i != e; i+=d) {
+ if (i == cur.line) found = scan(line, i, pos);
+ else found = scan(cm.getLineHandle(i), i);
+ if (found) break;
+ }
+ return {from: Pos(cur.line, pos), to: found && Pos(i, found.pos), match: found && found.match};
+ }
+
+ function matchBrackets(cm, autoclear) {
+ var found = findMatchingBracket(cm);
+ if (!found || cm.getLine(found.from.line).length > maxLineLen ||
+ found.to && cm.getLine(found.to.line).length > maxLineLen)
+ return;
+
+ var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
+ var _one_ = cm.markText(found.from, Pos(found.from.line, found.from.ch + 1), {className: style});
+ var two = found.to && cm.markText(found.to, Pos(found.to.line, found.to.ch + 1), {className: style});
+ // Kludge to work around the IE bug from issue #1193, where text
+ // input stops going to the textare whever this fires.
+ if (ie_lt8 && cm.state.focused) cm.display.input.focus();
+ var clear = function() {
+ cm.operation(function() { one.clear(); two && two.clear(); });
+ };
+ if (autoclear) setTimeout(clear, 800);
+ else return clear;
+ }
+
+ var currentlyHighlighted = null;
+ function doMatchBrackets(cm) {
+ cm.operation(function() {
+ if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
+ if (!cm.somethingSelected()) currentlyHighlighted = matchBrackets(cm, false);
+ });
+ }
+
+ CodeMirror.defineOption("matchBrackets", false, function(cm, val) {
+ if (val) cm.on("cursorActivity", doMatchBrackets);
+ else cm.off("cursorActivity", doMatchBrackets);
+ });
+
+ CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
+ CodeMirror.defineExtension("findMatchingBracket", function(){return findMatchingBracket(this);});
+})();