Skip to content

Commit

Permalink
Fixed editor content not loading without front matter data
Browse files Browse the repository at this point in the history
  • Loading branch information
redsolver committed Jul 9, 2020
1 parent f98006f commit 9ff6095
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Also I decided to drop support for syncing notes directly via the app because th

I recommend using an external data directory and a third-party sync app for Android like [Syncthing](https://syncthing.net/), Nextcloud Sync or FolderSync for other cloud services.

## 0.3.1

- Fixed editor content not loading without front matter data

## 0.3.0

- Fully reworked editor with syntax highlighting and a new keyboard toolbar to help with common Markdown operations
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ I recommend using an external data directory and a third-party sync app for Andr

## Changelog

### 0.3.1

- Fixed editor content not loading without front matter data

### 0.3.0

- Fully reworked editor with syntax highlighting and a new keyboard toolbar to help with common Markdown operations
Expand Down
14 changes: 7 additions & 7 deletions lib/page/edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class EditPage extends StatefulWidget {
class _EditPageState extends State<EditPage> {
NotesStore get store => widget.store;
RichCodeEditingController _rec;
NotelessSyntaxHighlighter _syntaxHighlighterBase;
NotelessSyntaxHighlighter _syntaxHighlighterBase =
NotelessSyntaxHighlighter();

GlobalKey _richTextFieldState = GlobalKey();

Expand All @@ -57,15 +58,13 @@ class _EditPageState extends State<EditPage> {
}

_loadContent() async {
String content = note.file.readAsStringSync();
/* String content = note.file.readAsStringSync();
var doc = fm.parse(content);
var doc = fm.parse(content); */
final content = await PersistentStore.readContent(note.file);

_syntaxHighlighterBase = NotelessSyntaxHighlighter(
/* accentColor: Theme.of(context).accentColor, */
);
_rec = RichCodeEditingController(_syntaxHighlighterBase,
text: doc.content.trimLeft());
text: content.trimLeft());

_rec.addListener(() {
if (_rec.text == currentData) return;
Expand Down Expand Up @@ -106,6 +105,7 @@ class _EditPageState extends State<EditPage> {
});
}
}
if (mounted) setState(() {});
}

GlobalKey<ScaffoldState> _scaffold = GlobalKey();
Expand Down
19 changes: 17 additions & 2 deletions lib/store/persistent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@ import 'package:front_matter/front_matter.dart' as fm;
import 'package:app/model/note.dart';

class PersistentStore {
static Future<String> readContent(File file) async {
if (!file.existsSync()) return null;

String fileContent = await file.readAsString();

if (fileContent.trimLeft().startsWith('---')) {
var doc = fm.parse(fileContent);
if (doc.content != null) return doc.content.trimLeft();
}

return fileContent.trimLeft();
}

static Future saveNote(Note note, [String content]) async {
// print('PersistentStore.saveNote');

if (content == null) {
content = fm.parse(note.file.readAsStringSync()).content;
content = await readContent(note.file);
}

String header = '---\n';
Expand All @@ -36,7 +49,9 @@ class PersistentStore {

header += toYamlString(data);

header += '\n---\n\n';
if (!header.endsWith('\n')) header += '\n';

header += '---\n\n';

// print(header);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A markdown note-taking app for mobile devices.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.3.0+30
version: 0.3.1+31

environment:
sdk: ">=2.5.0 <3.0.0"
Expand Down

0 comments on commit 9ff6095

Please sign in to comment.