Remove unused code

This commit is contained in:
Sarah Jamie Lewis 2022-10-08 13:58:41 -07:00
parent 4e34e9e1d8
commit a5d326b8c3
7 changed files with 71 additions and 162 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
# Miscellaneous
*.class
example.md
*.log
*.pyc
*.swp

View File

@ -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<Suggestion> suggestions = List.empty();
// Future<List<Suggestion>> 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();
}
}

View File

@ -66,19 +66,30 @@ class _InputListener extends State<InputListener> {
),
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))),
],
);
},

View File

@ -19,7 +19,6 @@ class LineInfo extends ChangeNotifier {
bool lineSelected = false;
List<LineAnnotation> annotations = List.empty(growable: true);
LineInfo(this.path, this.lineNumber, this.text);
Widget build(BuildContext context) {

View File

@ -11,7 +11,6 @@ void main(List<String> args) {
docfile.openFile("./example.md", 0);
var doc = ChangeNotifierProvider.value(value: docfile);
runApp(MultiProvider(
providers: [doc],
builder: (context, child) {

View File

@ -20,13 +20,18 @@ class _Outline extends State<Outline> {
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<LineFile>(context, listen: false);

View File

@ -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))),
]);
}
}