Skip to content

Commit 56747d6

Browse files
committed
Rename Graph to Explain & add selected state for Details
Signed-off-by: Grant Skinner <[email protected]>
1 parent b348805 commit 56747d6

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ <h1 class="tool-label"></h1>
212212
<li class="button replace active" data-tool="replace">Replace</li>
213213
<li class="button list" data-tool="list">List</li>
214214
<li class="button details" data-tool="details">Details</li>
215-
<li class="button graph" data-tool="graph">Graph</li>
215+
<li class="button explain" data-tool="explain">Explain</li>
216216
</ul>
217217
</div>
218218

js/SourceHighlighter.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ p.initialize = function (cm, canvas, fill) {
4040
this.fill = fill || this.fill;
4141
};
4242

43-
p.draw = function (matches, activeMatch) {
43+
p.draw = function (matches, activeMatch, selectedMatch) {
4444
this.clear();
4545
if (!matches || !matches.length) {
4646
return;
4747
}
48+
4849

4950
var cm = this.cm;
5051
var doc = cm.getDoc();
@@ -64,7 +65,6 @@ p.draw = function (matches, activeMatch) {
6465

6566
for (var i = 0, l = matches.length; i < l; i++) {
6667
var match = matches[i];
67-
var active = (match == activeMatch);
6868
var start = match.index;
6969
var end = match.end;
7070
if (start > bottom) {
@@ -75,10 +75,11 @@ p.draw = function (matches, activeMatch) {
7575
} // not visible, so don't mark.
7676
var startPos = match.startPos || (match.startPos = doc.posFromIndex(start));
7777
var endPos = match.endPos || (match.endPos = doc.posFromIndex(end));
78+
var active = (match === activeMatch);
79+
var selected = (match === selectedMatch);
7880

79-
if (active) {
80-
ctx.globalAlpha = 0.6;
81-
}
81+
if (active || selected) { ctx.globalAlpha = 0.45; }
82+
8283
var startRect = cm.charCoords(startPos, "local");
8384
var endRect = cm.charCoords(endPos, "local");
8485

@@ -98,9 +99,8 @@ p.draw = function (matches, activeMatch) {
9899
this.drawHighlight(ctx, 0, endRect.top, endRect.right, endRect.bottom, scroll.top, true);
99100
// CMUtils.getEOLPos(this.sourceCM, startPos);
100101
}
101-
if (active) {
102-
ctx.globalAlpha = 1;
103-
}
102+
103+
if (active || selected) { ctx.globalAlpha = 1; }
104104
}
105105
};
106106

js/documentation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var library = {
6969
{
7070
label:"List",
7171
desc:"The <b>List</b> tool lists all found matches."+
72-
"<p>You can specify either a simple deliminator (ex. <code>,</code> or <code>\\n</code>), or use <a href='javascript:showLib(\"subst\")'>substitution tokens</a> (ex. <code>$&</code> or <code>$1</code>) to generate more advanced reports.</p>"+
72+
"<p>You can specify either a simple delimiter (ex. <code>,</code> or <code>\\n</code>), or use <a href='javascript:showLib(\"subst\")'>substitution tokens</a> (ex. <code>$&</code> or <code>$1</code>) to generate more advanced reports.</p>"+
7373
"<p>Escaped characters compatible with the JS string format are supported, such as <code>\\n</code>, <code>\\t</code> & <code>\\u0009</code>.</p>"+
7474
"<p>Roll over tokens for information.</p>"
7575
},
@@ -79,8 +79,9 @@ var library = {
7979
"<p>Click on a highlighted match in the <b>Text</b> panel to display details for that match.</p>"
8080
},
8181
{
82-
label:"Graph",
83-
desc:"The <b>Graph</b> tool displays a detailed breakdown of the Expression."
82+
label:"Explain",
83+
desc:"The <b>Explain</b> tool displays a detailed breakdown of the <b>Expression</b>."+
84+
"<p>Mouse over the explanation to highlight the related tokens in the <b>Expression</b> panel.</p>"
8485
}
8586
]
8687
},

js/views/DocView.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var SubstLexer = require('../SubstLexer');
4040
var Utils = require('../utils/Utils');
4141

4242
var Docs = require('../utils/Docs');
43-
var Graph = require('../utils/Graph');
43+
var Explain = require('../views/Explain');
4444
var CodeMirror = require('codemirror');
4545

4646
var DocView = function (element) {
@@ -88,6 +88,7 @@ p.saveTooltip = null;
8888
p.matches = null;
8989
p.error = null;
9090
p.hoverMatch = null;
91+
p.selectedMatch = null;
9192
p.exprLexer = null;
9293
p.toolsLexer = null;
9394
p.tool = null;
@@ -545,8 +546,8 @@ p.update = function () {
545546
// used primarily to handle fwdslash errors.
546547
if (this.exprLexer.errors.length || !regex) {
547548
this.error = "ERROR";
548-
this.updateTool();
549549
this.updateResults();
550+
this.updateTool();
550551
return;
551552
}
552553

@@ -556,6 +557,7 @@ p.update = function () {
556557
_this.matches = matches;
557558

558559
_this.updateResults();
560+
_this.updateTool(str, regex);
559561
$.defer(_this, _this.drawSourceHighlights, "draw");
560562

561563
if (ExpressionModel.isDirty()) {
@@ -565,8 +567,6 @@ p.update = function () {
565567
if (ExpressionModel.id) {
566568
BrowserHistory.go($.createID(ExpressionModel.id));
567569
}
568-
569-
_this.updateTool(str, regex);
570570
});
571571
};
572572

@@ -583,6 +583,9 @@ p.getRegEx = function(global) {
583583
}
584584

585585
p.updateTool = function (source, regex) {
586+
var oldMatch = this.selectedMatch;
587+
var match = this.selectedMatch = null;
588+
586589
if (!this.toolsEnabled) { return; }
587590
source = source||this.sourceCM.getValue();
588591
var result = "", toolsCM = this.getToolCM(), err = this.error;
@@ -619,7 +622,8 @@ p.updateTool = function (source, regex) {
619622
}
620623
this.toolsOutCM.setValue(result);
621624
} else if (this.tool == "details") {
622-
var cm = this.sourceCM, match=this.getMatchAt(cm.indexFromPos(cm.getCursor()), true);
625+
var cm = this.sourceCM;
626+
match = this.getMatchAt(cm.indexFromPos(cm.getCursor()), true);
623627

624628
if (match) {
625629
result += "<h1><b>Match #"+match.num+"</b>"+
@@ -632,15 +636,21 @@ p.updateTool = function (source, regex) {
632636
" <b>Length:</b> "+match[i].length+"</h1>"+
633637
"<p>"+TextUtils.htmlSafe(match[i])+"</p>";
634638
}
635-
} else {
636-
result = "<i>click a <span class='match'>match</span> above for details</i>";
637639
}
640+
641+
result += "<p class='info'>click a <span class='match'>match</span> above for details</p>";
638642
$.el(".content",this.toolsResults).innerHTML = "<code><pre>"+result+"</code></pre>";
639-
} else if (this.tool == "graph") {
643+
644+
} else if (this.tool == "explain") {
640645
var token = this.exprLexer.token, expr = this.expressionCM.getValue();
641-
result = Graph.forExpression(expr, token, this.expressionHighlighter);
646+
result = Explain.forExpression(expr, token, this.expressionHighlighter);
642647
$.empty($.el(".content",this.toolsResults)).appendChild(result);
643648
}
649+
650+
if (match !== oldMatch) {
651+
this.selectedMatch = match;
652+
$.defer(this, this.drawSourceHighlights, "draw");
653+
}
644654
};
645655

646656
p.getMatchAt = function(index, inclusive) {
@@ -658,7 +668,7 @@ p.getMatchAt = function(index, inclusive) {
658668
};
659669

660670
p.drawSourceHighlights = function () {
661-
this.sourceHighlighter.draw(this.error == "ERROR" ? null : this.matches, this.hoverMatch);
671+
this.sourceHighlighter.draw(this.error == "ERROR" ? null : this.matches, this.hoverMatch, this.selectedMatch);
662672
};
663673

664674
p.updateResults = function () {

js/utils/Graph.js renamed to js/views/Explain.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
SOFTWARE.
2323
*/
2424

25-
var Utils = require('./Utils');
26-
var Docs = require('./Docs');
25+
var Utils = require('../utils//Utils');
26+
var Docs = require('../utils/Docs');
2727
var ExpressionHighlighter = require('../ExpressionHighlighter');
2828

29-
var Graph = {};
29+
var Explain = {};
3030

31-
Graph.forExpression = function(expr, token, highlighter) {
31+
Explain.forExpression = function(expr, token, highlighter) {
3232
var groupClasses = ExpressionHighlighter.GROUP_CLASS_BY_TYPE, pre = "exp-";
33-
var result = $.div(null, "graph"), el = result;
33+
var result = $.div(null, "explain"), el = result;
3434

3535
var enterHandler = function(evt) {
3636
var o = evt.currentTarget;
@@ -91,4 +91,4 @@ Graph.forExpression = function(expr, token, highlighter) {
9191

9292
return result;
9393
};
94-
module.exports = Graph;
94+
module.exports = Explain;

scss/views/docView.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
}
137137
}
138138

139-
.tools .graph {
139+
.tools .explain {
140140
div {
141141
padding: calc(0.5em + 1px);
142142
margin-top: 0.75em;
@@ -189,7 +189,7 @@
189189
}
190190

191191
/*
192-
Expression backgrounds need to be transparent so the selection shows through, but it looks wrong for the graph.
192+
Expression backgrounds need to be transparent so the selection shows through, but it looks wrong for the explain.
193193
*/
194194
.exp-group-0 { background: tint($group-color, 89%); }
195195

@@ -228,7 +228,7 @@
228228
.tool-list .editor.list, .tool-list .editor.out {
229229
display: block;
230230
}
231-
.tool-details .tools.results, .tool-graph .tools.results {
231+
.tool-details .tools.results, .tool-explain .tools.results {
232232
display: block;
233233
}
234234
}
@@ -257,11 +257,16 @@
257257
.match {
258258
background: $theme-color;
259259
}
260+
261+
.info {
262+
font-style: italic;
263+
background: $editor-toolsres-bg;
264+
}
260265

261266
h1 {
262267
font-size: 1em;
263268
margin: 0;
264-
padding: 0.5em;
269+
padding: $pad;
265270
padding-left: $pad;
266271
padding-right: $pad;
267272
font-weight: normal;

0 commit comments

Comments
 (0)