Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Side by Side Diff: packages/dart_style/web/main.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/dart_style/web/index.html ('k') | packages/dart_style/web/style.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import 'dart:html';
2
3 import 'package:dart_style/dart_style.dart';
4
5 TextAreaElement before;
6 TextAreaElement after;
7
8 int width = 80;
9
10 PreElement columnMarker = querySelector(".column-marker");
11 InputElement widthInput = querySelector("#width");
12 OutputElement widthOutput = querySelector("#width-output");
13
14 void main() {
15 before = querySelector("#before") as TextAreaElement;
16 after = querySelector("#after") as TextAreaElement;
17
18 before.onKeyUp.listen((event) {
19 reformat();
20
21 window.localStorage["code"] = before.value;
22 });
23
24 var code = window.localStorage["code"];
25 if (code != null) before.text = code;
26
27 if (window.localStorage.containsKey("width")) {
28 setWidth(window.localStorage["width"]);
29 }
30
31 widthInput.onInput.listen((event) {
32 setWidth(widthInput.value);
33 window.localStorage["width"] = widthInput.value;
34 });
35
36 reformat();
37 }
38
39 void reformat() {
40 var source = before.value;
41
42 try {
43 after.value = new DartFormatter(pageWidth: width).format(source);
44 return;
45 } on FormatterException {
46 // Do nothing.
47 }
48
49 // Maybe it's a statement.
50 try {
51 after.value = new DartFormatter(pageWidth: width).formatStatement(source);
52 } on FormatterException catch (err) {
53 after.value = "Format failed:\n$err";
54 }
55 }
56
57 void setWidth(String widthString) {
58 width = int.parse(widthString);
59
60 widthInput.value = widthString;
61 widthOutput.value = widthString;
62
63 var pad = " " * width + "|";
64 columnMarker.innerHtml = "$pad $width columns" + "\n$pad" * 29;
65 reformat();
66 }
OLDNEW
« no previous file with comments | « packages/dart_style/web/index.html ('k') | packages/dart_style/web/style.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698