From a5d326b8c3f187e9f66675b07ac420888c1610cb Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sat, 8 Oct 2022 13:58:41 -0700 Subject: [PATCH] Remove unused code --- .gitignore | 1 + lib/file.dart | 132 ++++++++++++-------------------------------- lib/input.dart | 37 ++++++++----- lib/line_info.dart | 1 - lib/main.dart | 1 - lib/outline.dart | 19 ++++--- lib/suggestion.dart | 42 -------------- 7 files changed, 71 insertions(+), 162 deletions(-) delete mode 100644 lib/suggestion.dart diff --git a/.gitignore b/.gitignore index 24476c5..faba45b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Miscellaneous *.class +example.md *.log *.pyc *.swp diff --git a/lib/file.dart b/lib/file.dart index 2b601d2..2670a28 100644 --- a/lib/file.dart +++ b/lib/file.dart @@ -7,7 +7,6 @@ import 'package:subwrite/annotation.dart'; import 'package:subwrite/section.dart'; import 'package:subwrite/sourcelink.dart'; -import 'package:subwrite/suggestion.dart'; import 'cursor_provider.dart'; import 'line_info.dart'; @@ -42,106 +41,42 @@ class LineFile extends ChangeNotifier { notifyListeners(); } - void cancelSuggestions() { - if (showSuggestions) { - suggestionIndex = 0; - showSuggestions = false; - notifyListeners(); - } - } - - ScrollController suggestionListController = ScrollController(initialScrollOffset: 0.0); - int suggestionIndex = 0; - List suggestions = List.empty(); - - // Future> loadSuggestions(IDE ide) async { - // return ide.getSuggestions(projectPath, path, cursor.line, cursor.column, base64()).then((list) { - // suggestions = list; - // return list; - // }); - // } - - void suggestListUp() { - suggestionIndex = (suggestionIndex - 1) % suggestions.length; - if (suggestions.length - suggestionIndex >= 14 || suggestionIndex == 0 || suggestionIndex == suggestions.length - 1) { - suggestionListController.animateTo(suggestionIndex * 13.0, duration: const Duration(milliseconds: 100), curve: Curves.decelerate); - } - notifyListeners(); - } - - void suggestListDown() { - suggestionIndex = (suggestionIndex + 1) % suggestions.length; - if (suggestions.length - suggestionIndex >= 14 || suggestionIndex == 0 || suggestionIndex == suggestions.length - 1) { - suggestionListController.animateTo(suggestionIndex * 13.0, duration: const Duration(milliseconds: 100), curve: Curves.decelerate); - } - notifyListeners(); - } - - void suggestListInsert() { - suggestionIndex = (suggestionIndex) % suggestions.length; - for (var char = suggestions[suggestionIndex].partialLen; char < suggestions[suggestionIndex].name.length; char++) { - insertChar(suggestions[suggestionIndex].name[char]); - } - cursor.publishCursor(backingLines); - notifyListeners(); - } - KeyEventResult handleKey(RawKeyEvent event) { // only process key down events... if (event.runtimeType.toString() == 'RawKeyDownEvent') { if (event.logicalKey == LogicalKeyboardKey.arrowLeft) { cursor.moveCursor(-1, 0, backingLines, keepAnchor: event.isShiftPressed); cursor.publishCursor(backingLines); - cancelSuggestions(); } else if (event.logicalKey == LogicalKeyboardKey.arrowRight) { cursor.moveCursor(1, 0, backingLines, keepAnchor: event.isShiftPressed); cursor.publishCursor(backingLines); - cancelSuggestions(); } else if (event.logicalKey == LogicalKeyboardKey.arrowUp) { - if (showSuggestions == false) { - cursor.moveCursor(0, -1, backingLines, keepAnchor: event.isShiftPressed); - cursor.publishCursor(backingLines); - } else { - suggestListUp(); - } + cursor.moveCursor(0, -1, backingLines, keepAnchor: event.isShiftPressed); + cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.arrowDown) { - if (showSuggestions == false) { - cursor.moveCursor(0, 1, backingLines, keepAnchor: event.isShiftPressed); - cursor.publishCursor(backingLines); - } else { - suggestListDown(); - } + cursor.moveCursor(0, 1, backingLines, keepAnchor: event.isShiftPressed); + cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.home) { - cancelSuggestions(); cursor.clearSelection(); cursor.moveCursorToLineStart(); cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.end) { - cancelSuggestions(); cursor.clearSelection(); cursor.moveCursorToLineEnd(backingLines[cursor.line - 1].text.length); cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.enter) { - if (showSuggestions == false) { - insertLine(); - cancelSuggestions(); - cursor.clearSelection(); - cursor.publishCursor(backingLines); - } else { - suggestListInsert(); - } + insertLine(); + cursor.clearSelection(); + cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.tab) { insertChar(" "); - cancelSuggestions(); cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.delete) { handleDelete(); - cancelSuggestions(); cursor.clearSelection(); cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.backspace) { handleBackspace(); - cancelSuggestions(); cursor.clearSelection(); cursor.publishCursor(backingLines); } else if (event.logicalKey == LogicalKeyboardKey.escape) { @@ -311,7 +246,6 @@ class LineFile extends ChangeNotifier { // rebuild the annotations manager void parse() { - sections.clear(); for (var i = 0; i < backingLines.length; i++) { @@ -320,19 +254,22 @@ class LineFile extends ChangeNotifier { backingLines[i].annotations.removeWhere((element) => element.tool == "markdown"); if (line.text.startsWith("//")) { - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "comment")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "comment")); if (line.text.contains("TODO")) { - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.todo, "todo")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.todo, "todo")); } } if (line.text.startsWith("#")) { // this is a header - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "header")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "header")); var level = 0; for (var lvl = 0; lvl < 6; lvl++) { @@ -349,18 +286,21 @@ class LineFile extends ChangeNotifier { } if (line.text.startsWith(" ")) { - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "code")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "code")); } _boldRegex.allMatches(backingLines[i].text).forEach((match) { - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: match.start, colEnd: match.end + 1, lineEnd: i), "markdown", AnnotationType.highlight, "bold")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: match.start, colEnd: match.end + 1, lineEnd: i), "markdown", AnnotationType.highlight, "bold")); }); _codeRegex.allMatches(backingLines[i].text).forEach((match) { - backingLines[i].annotations.add( - LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: match.start, colEnd: match.end + 1, lineEnd: i), "markdown", AnnotationType.highlight, "code")); + backingLines[i] + .annotations + .add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: match.start, colEnd: match.end + 1, lineEnd: i), "markdown", AnnotationType.highlight, "code")); }); } notifyListeners(); @@ -405,12 +345,10 @@ class LineFile extends ChangeNotifier { } void mouseDownUpdate(int line, int col) { - cancelSuggestions(); cursor.mouseDownUpdate(line, col, backingLines); } void mouseDownMoveUpdate(int col) { - cancelSuggestions(); cursor.mouseDownMoveUpdate(col, backingLines); } @@ -449,7 +387,6 @@ class LineFile extends ChangeNotifier { } addNote(String note) { - var notetype = "note"; if (note.startsWith("[incomplete]")) { notetype = "incomplete"; @@ -457,16 +394,15 @@ class LineFile extends ChangeNotifier { notetype = "edit"; } - backingLines[cursor.line-1].annotations.add( - LineAnnotation( - SourceLink( - path, - lineStart: cursor.line, - ), - "notes", - AnnotationType.note, - notetype, - description: note)); + backingLines[cursor.line - 1].annotations.add(LineAnnotation( + SourceLink( + path, + lineStart: cursor.line, + ), + "notes", + AnnotationType.note, + notetype, + description: note)); notifyListeners(); } } diff --git a/lib/input.dart b/lib/input.dart index f50a692..b8bea14 100644 --- a/lib/input.dart +++ b/lib/input.dart @@ -66,19 +66,30 @@ class _InputListener extends State { ), contentPadding: EdgeInsets.symmetric(vertical: 1.0, horizontal: 5.0), actions: [ - - ElevatedButton.icon(icon: Icon(Icons.label, color: literal,), onPressed: () { - controller.text = "[edit]${controller.text}"; - callback(controller.text); - Navigator.of(context).pop(); - }, label: Text("Edit"),style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs), foregroundColor: MaterialStateProperty.all(foreground))), - - - ElevatedButton.icon(icon: Icon(Icons.label, color: constant,), onPressed: () { - controller.text = "[incomplete]${controller.text}"; - callback(controller.text); - Navigator.of(context).pop(); - }, label: Text("Incomplete"),style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs), foregroundColor: MaterialStateProperty.all(foreground))), + ElevatedButton.icon( + icon: Icon( + Icons.label, + color: literal, + ), + onPressed: () { + controller.text = "[edit]${controller.text}"; + callback(controller.text); + Navigator.of(context).pop(); + }, + label: Text("Edit"), + style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs), foregroundColor: MaterialStateProperty.all(foreground))), + ElevatedButton.icon( + icon: Icon( + Icons.label, + color: constant, + ), + onPressed: () { + controller.text = "[incomplete]${controller.text}"; + callback(controller.text); + Navigator.of(context).pop(); + }, + label: Text("Incomplete"), + style: ButtonStyle(backgroundColor: MaterialStateProperty.all(tabs), foregroundColor: MaterialStateProperty.all(foreground))), ], ); }, diff --git a/lib/line_info.dart b/lib/line_info.dart index 30ceee4..1af0117 100644 --- a/lib/line_info.dart +++ b/lib/line_info.dart @@ -19,7 +19,6 @@ class LineInfo extends ChangeNotifier { bool lineSelected = false; List annotations = List.empty(growable: true); - LineInfo(this.path, this.lineNumber, this.text); Widget build(BuildContext context) { diff --git a/lib/main.dart b/lib/main.dart index 405f07d..8780892 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,7 +11,6 @@ void main(List args) { docfile.openFile("./example.md", 0); var doc = ChangeNotifierProvider.value(value: docfile); - runApp(MultiProvider( providers: [doc], builder: (context, child) { diff --git a/lib/outline.dart b/lib/outline.dart index fba3d84..8384c97 100644 --- a/lib/outline.dart +++ b/lib/outline.dart @@ -20,13 +20,18 @@ class _Outline extends State { child: ReorderableListView.builder( header: Padding( padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0), - child: Column(children: [Row(mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( - Icons.edit, - color: foreground, - ), - Text("subwrite", style: TextStyle(fontSize: 16.0, color: foreground, fontWeight: FontWeight.bold, fontFamily: "Iosevka")) - ]), Divider(color: foreground,)])), + child: Column(children: [ + Row(mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ + Icon( + Icons.edit, + color: foreground, + ), + Text("subwrite", style: TextStyle(fontSize: 16.0, color: foreground, fontWeight: FontWeight.bold, fontFamily: "Iosevka")) + ]), + Divider( + color: foreground, + ) + ])), footer: Padding(padding: const EdgeInsets.symmetric(vertical: 3.0, horizontal: 10.0), child: Divider(color: foreground, thickness: 4.0)), onReorder: (int oldIndex, int newIndex) { var doc = Provider.of(context, listen: false); diff --git a/lib/suggestion.dart b/lib/suggestion.dart deleted file mode 100644 index 032550f..0000000 --- a/lib/suggestion.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:subwrite/theme.dart'; - -class Suggestion { - String classType; - String name; - String typeSignature; - int partialLen; - - Suggestion(this.classType, this.name, this.partialLen, this.typeSignature); - - @override - bool operator ==(Object other) { - return other is Suggestion && hashCode == other.hashCode; - } - - @override - int get hashCode => classType.hashCode + name.hashCode + typeSignature.hashCode; - - Widget getWidget() { - var color = function; - switch (classType) { - case "const": - color = constant; - break; - case "var": - color = variable; - break; - case "package": - color = keyword; - break; - case "type": - color = header; - break; - } - - return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - RichText(text: TextSpan(text: name, style: TextStyle(color: color, fontFamily: "Iosevka", fontSize: 11.0, fontWeight: FontWeight.bold))), - RichText(text: TextSpan(text: typeSignature, style: const TextStyle(fontFamily: "Iosevka", fontSize: 10.0))), - ]); - } -}