Super editor

This commit is contained in:
Hillel Coren 2022-03-23 16:45:33 +02:00
parent add5e2431e
commit 0dfef542f8
2 changed files with 26 additions and 16 deletions

View File

@ -148,12 +148,15 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
_subjectPreview = subject.trim();
_bodyPreview = body.trim();
_emailPreview = email.trim();
_rawBodyPreview = rawBody.trim();
final company = widget.viewModel.state.company;
if (company.markdownEmailEnabled &&
_rawBodyPreview.startsWith('<p>')) {
_rawBodyPreview = html2md.convert(_rawBodyPreview);
if (_rawBodyPreview.isEmpty) {
_rawBodyPreview = rawBody.trim();
final company = widget.viewModel.state.company;
if (company.markdownEmailEnabled &&
_rawBodyPreview.startsWith('<p>')) {
_rawBodyPreview = html2md.convert(_rawBodyPreview);
}
}
if (origSubject.isEmpty && origBody.isEmpty) {
@ -197,6 +200,7 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
setState(() {
_subjectController.text = '';
_bodyController.text = '';
_rawBodyPreview = '';
selectedTemplate = template;
_loadTemplate();
});
@ -258,7 +262,7 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
body: _emailPreview,
)
else
AbsorbPointer(
IgnorePointer(
child: ExampleEditor(
value: html2md.convert(_bodyPreview),
),
@ -297,7 +301,7 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
? Colors.white
: null,
child: Padding(
padding: const EdgeInsets.only(left: 24, right: 10),
padding: const EdgeInsets.only(left: 24, right: 10, bottom: 16),
child: DecoratedFormField(
controller: _subjectController,
label: localization.subject,

View File

@ -63,16 +63,20 @@ class _ExampleEditorState extends State<ExampleEditor> {
super.didUpdateWidget(oldWidget);
if (widget.value != oldWidget.value) {
_doc.removeListener(_hideOrShowToolbar);
_doc.removeListener(_onChanged);
_doc = deserializeMarkdownToDocument(widget.value)
..addListener(_hideOrShowToolbar)
..addListener(_onChanged);
_docEditor = DocumentEditor(document: _doc as MutableDocument);
_editorFocusNode = FocusNode();
_setValue(widget.value);
}
}
void _setValue(String value) {
_doc.removeListener(_hideOrShowToolbar);
_doc.removeListener(_onChanged);
_doc = deserializeMarkdownToDocument(value)
..addListener(_hideOrShowToolbar)
..addListener(_onChanged);
_docEditor = DocumentEditor(document: _doc as MutableDocument);
_editorFocusNode = FocusNode();
}
@override
void dispose() {
if (_textFormatBarOverlayEntry != null) {
@ -91,8 +95,10 @@ class _ExampleEditorState extends State<ExampleEditor> {
}
void _onChanged() {
final value = serializeDocumentToMarkdown(_docEditor.document);
widget.onChanged(value);
if (widget.onChanged != null) {
final value = serializeDocumentToMarkdown(_docEditor.document);
widget.onChanged(value);
}
}
void _hideOrShowToolbar() {