Inline Images / Small bugfixes

This commit is contained in:
Sarah Jamie Lewis 2022-10-10 12:17:58 -07:00
parent fccc925740
commit 394929861d
6 changed files with 81 additions and 12 deletions

View File

@ -1,6 +1,23 @@
![](subwrite-logo.png)
# subwrite
A Ridiculously Personalized Markdown Editor
A Ridiculously Personalized Markdown Editor by Sarah Jamie Lewis.
## Screenshots
![](subwrite.png)
![](subwrite-spellcheck.png)
## Features
- Reorderable Table of Contents / Section View
- Spellchecking / Custom Dictionary
- Inline Image Previews
## Contributing
Open an issue or submit a PR!

View File

@ -7,6 +7,7 @@ enum AnnotationType {
error,
todo,
note,
image,
}
class LineAnnotation {

View File

@ -44,6 +44,15 @@ class LineFile extends ChangeNotifier {
(value) {
spellchecker = value;
status = "dictionary loaded";
status = "spellchecking document";
updateStatus(0.0);
notifyListeners();
spellCheckAll().then((value) {
status = "spellchecking complete";
updateStatus(1.0);
notifyListeners();
});
notifyListeners();
},
);
@ -227,6 +236,7 @@ class LineFile extends ChangeNotifier {
status = "spellchecking document";
notifyListeners();
updateStatus(0.0);
spellCheckAll().then((value) {
status = "spellcheck complete";
notifyListeners();
@ -259,6 +269,9 @@ class LineFile extends ChangeNotifier {
}
parse();
spellcheck(cursor.line - 1).then((value) {
notifyListeners();
});
return KeyEventResult.handled;
}
@ -413,6 +426,12 @@ class LineFile extends ChangeNotifier {
dotAll: true,
);
final _imageRegex = RegExp(
r'!\[([^\[]*)\]\((.*)\)',
caseSensitive: false,
dotAll: true,
);
List<Section> sections = List.empty(growable: true);
Future<void> spellcheck(int i) async {
@ -555,6 +574,11 @@ class LineFile extends ChangeNotifier {
.add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, colStart: 0, colEnd: line.text.length + 1, lineEnd: i), "markdown", AnnotationType.highlight, "code"));
}
var imageMatch = _imageRegex.matchAsPrefix(line.text);
if (imageMatch != null) {
backingLines[i].annotations.add(LineAnnotation(SourceLink(path, lineStart: backingLines[i].lineNumber, lineEnd: i), "markdown", AnnotationType.image, imageMatch.group(2)!));
}
_boldRegex.allMatches(backingLines[i].text).forEach((match) {
backingLines[i]
.annotations

View File

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:math';
import 'package:flutter/gestures.dart';
@ -54,6 +55,11 @@ class LineInfo extends ChangeNotifier {
sidebarContent.addAll(icons);
LineAnnotation? image;
if (annotations.any((element) => element.annotationType == AnnotationType.image)) {
image = annotations.firstWhere((element) => element.annotationType == AnnotationType.image);
}
return LayoutBuilder(
builder: (context, constraints) {
var usableSize = (constraints.maxWidth - gutterWidth - rightMargin - leftMargin).floorToDouble();
@ -79,6 +85,7 @@ class LineInfo extends ChangeNotifier {
var idealHeight = (lineHeight * (1.0 + ((text.length * charWidth) / usableSize).floorToDouble())).ceilToDouble();
if (cursorStart != null || image == null) {
var highlightedLineContainer = Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.only(right: rightMargin, top: 0, bottom: 0, left: leftMargin),
@ -91,6 +98,26 @@ class LineInfo extends ChangeNotifier {
);
stackElements.add(highlightedLineContainer);
} else {
var file = File(image.type);
idealHeight = 250;
var imageContainer = Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.only(right: rightMargin, top: 0, bottom: 0, left: leftMargin),
decoration: BoxDecoration(
color: backgroundStyle.backgroundColor,
),
width: usableSize,
child: Image.file(
file,
height: idealHeight,
width: usableSize / 2.0,
fit: BoxFit.contain,
filterQuality: FilterQuality.high,
cacheHeight: idealHeight.floor(),
));
stackElements.add(imageContainer);
}
if (cursorStart != null) {
var maxCharsBeforeWrapping = (usableSize / charWidth).floorToDouble();

BIN
subwrite-spellcheck.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 129 KiB