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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/dart_style/web/main.dart
diff --git a/packages/dart_style/web/main.dart b/packages/dart_style/web/main.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a005653764adab97ca424f2a1455264449de0d2a
--- /dev/null
+++ b/packages/dart_style/web/main.dart
@@ -0,0 +1,66 @@
+import 'dart:html';
+
+import 'package:dart_style/dart_style.dart';
+
+TextAreaElement before;
+TextAreaElement after;
+
+int width = 80;
+
+PreElement columnMarker = querySelector(".column-marker");
+InputElement widthInput = querySelector("#width");
+OutputElement widthOutput = querySelector("#width-output");
+
+void main() {
+ before = querySelector("#before") as TextAreaElement;
+ after = querySelector("#after") as TextAreaElement;
+
+ before.onKeyUp.listen((event) {
+ reformat();
+
+ window.localStorage["code"] = before.value;
+ });
+
+ var code = window.localStorage["code"];
+ if (code != null) before.text = code;
+
+ if (window.localStorage.containsKey("width")) {
+ setWidth(window.localStorage["width"]);
+ }
+
+ widthInput.onInput.listen((event) {
+ setWidth(widthInput.value);
+ window.localStorage["width"] = widthInput.value;
+ });
+
+ reformat();
+}
+
+void reformat() {
+ var source = before.value;
+
+ try {
+ after.value = new DartFormatter(pageWidth: width).format(source);
+ return;
+ } on FormatterException {
+ // Do nothing.
+ }
+
+ // Maybe it's a statement.
+ try {
+ after.value = new DartFormatter(pageWidth: width).formatStatement(source);
+ } on FormatterException catch (err) {
+ after.value = "Format failed:\n$err";
+ }
+}
+
+void setWidth(String widthString) {
+ width = int.parse(widthString);
+
+ widthInput.value = widthString;
+ widthOutput.value = widthString;
+
+ var pad = " " * width + "|";
+ columnMarker.innerHtml = "$pad $width columns" + "\n$pad" * 29;
+ reformat();
+}
« 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