Skip to content

Commit 4d8d251

Browse files
committed
Merge pull request #709 from dart-lang/devoncarew_source
always show source for methods
2 parents 4ccb5be + c3affe1 commit 4d8d251

File tree

6 files changed

+16
-53
lines changed

6 files changed

+16
-53
lines changed

lib/resources/styles.css

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -532,34 +532,8 @@ ol#sidebar li:first-child {
532532
.sidebar-offcanvas{position:absolute;top:0;width:50%;}
533533
}
534534

535-
/* toggling source code */
535+
/* source code method bodies */
536536

537537
.source-code pre {
538538
margin: 16px 0 16px 0;
539539
}
540-
541-
.source-code h4 {
542-
color: #455A64;
543-
text-transform: uppercase;
544-
font-size: 14px;
545-
}
546-
547-
.source-code h4:hover {
548-
cursor: pointer;
549-
}
550-
551-
.source-code-toggle {
552-
font-size: 80%;
553-
float: left;
554-
width: 1.2em;
555-
padding-top: 2px; /* how to avoid this? how to vertically align? */
556-
opacity: 0.7;
557-
}
558-
559-
.source-code-toggle.closed::before {
560-
content: '\25B6';
561-
}
562-
563-
.source-code-toggle.open::before {
564-
content: '\25BC';
565-
}

lib/src/model.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,15 @@ abstract class SourceCodeMixin {
11191119
break;
11201120
}
11211121
}
1122-
return contents.substring(node.offset - (node.offset - i), node.end);
1122+
1123+
// Trim the common indent from the source snippet.
1124+
String source =
1125+
contents.substring(node.offset - (node.offset - i), node.end);
1126+
String remainer = source.trimLeft();
1127+
String indent = source.substring(0, source.length - remainer.length);
1128+
return source.split('\n').map((line) {
1129+
return line.startsWith(indent) ? line.substring(indent.length) : line;
1130+
}).join('\n');
11231131
}
11241132

11251133
Element get element;

lib/templates/_footer.html

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,10 @@
5858
scrollBy(0, -68);
5959
}
6060

61-
function initSourceToggle() {
62-
var toggle = document.querySelector('.source-code h4');
63-
var toggleArrow = document.querySelector('.source-code-toggle');
64-
var code = document.querySelector('.source-code pre');
65-
66-
if (toggle && toggleArrow && code) {
67-
toggle.addEventListener('click', function(e) {
68-
var closed = toggleArrow.classList.contains('closed');
69-
toggleArrow.classList.toggle('closed', !closed);
70-
toggleArrow.classList.toggle('open', closed);
71-
code.style.display = closed ? 'block' : 'none';
72-
});
73-
}
74-
}
75-
7661
document.addEventListener("DOMContentLoaded", function() {
7762
prettyPrint();
7863
initScroller();
7964
initSideNav();
80-
initSourceToggle();
8165

8266
// Make sure the anchors scroll past the fixed page header (#648).
8367
if (location.hash) shiftWindow();

lib/templates/_readable_writable.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
<div class="readable-writable">
2-
{{#readOnly}}read-only{{/readOnly}}
3-
{{#writeOnly}}write-only{{/writeOnly}}
4-
{{#readWrite}}read / write{{/readWrite}}
5-
{{#isInherited}}, <span class="is-inherited">inherited</span>{{/isInherited}}
2+
{{#readOnly}}read-only{{/readOnly}}{{#writeOnly}}write-only{{/writeOnly}}{{#readWrite}}read / write{{/readWrite}}{{#isInherited}}, <span class="is-inherited">inherited</span>{{/isInherited}}
63
</div>

lib/templates/_source_code.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<section class="source-code">
2-
<h4><span class="source-code-toggle closed"></span> Source</h4>
3-
<pre style="display:none"><code class="prettyprint lang-dart">{{ sourceCode }}</code></pre>
1+
<section class="summary source-code">
2+
<h2>Source</h2>
3+
<pre><code class="prettyprint lang-dart">{{ sourceCode }}</code></pre>
44
</section>

test/model_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
473473
});
474474

475475
test('method source code indents correctly', () {
476-
expect(convertToMap.sourceCode,
477-
startsWith(' /// Converts itself to a map.'));
476+
expect(
477+
convertToMap.sourceCode, startsWith('/// Converts itself to a map.'));
478478
});
479479
});
480480

0 commit comments

Comments
 (0)