Compare commits
3 Commits
b5bb5dc1ff
...
8c0c478847
Author | SHA1 | Date |
---|---|---|
Filip Krawczyk | 8c0c478847 | |
Filip Krawczyk | cab4aeebb7 | |
Filip Krawczyk | 7db538084a |
|
@ -37,18 +37,44 @@ class MarkdownFormatter extends TextInputFormatter {
|
|||
TextEditingValue oldValue, TextEditingValue newValue) {
|
||||
if (oldValue.text.length > newValue.text.length) return newValue;
|
||||
|
||||
var newVal = newValue;
|
||||
|
||||
final char = newValue.text[newValue.selection.baseOffset - 1];
|
||||
|
||||
if (char == '\n') {
|
||||
final lineBefore =
|
||||
newValue.text.lineBefore(newValue.selection.baseOffset - 2);
|
||||
if (lineBefore.startsWith('- ')) {
|
||||
return newValue.append('- ');
|
||||
}
|
||||
if (lineBefore.startsWith('* ')) {
|
||||
return newValue.append('* ');
|
||||
|
||||
TextEditingValue listContinuation(String listChar, TextEditingValue tev) {
|
||||
final regex = RegExp('(\\s*)${RegExp.escape(listChar)} ');
|
||||
final match = regex.matchAsPrefix(lineBefore);
|
||||
if (match == null) {
|
||||
return tev;
|
||||
}
|
||||
final indent = match.group(1);
|
||||
|
||||
return tev.append('$indent$listChar ');
|
||||
}
|
||||
|
||||
return newValue;
|
||||
TextEditingValue numberedListContinuation(
|
||||
String afterNumberChar, TextEditingValue tev) {
|
||||
final regex = RegExp('(\\s*)(\\d+)${RegExp.escape(afterNumberChar)} ');
|
||||
final match = regex.matchAsPrefix(lineBefore);
|
||||
if (match == null) {
|
||||
return tev;
|
||||
}
|
||||
final indent = match.group(1);
|
||||
final number = int.parse(match.group(2)!) + 1;
|
||||
|
||||
return tev.append('$indent$number$afterNumberChar ');
|
||||
}
|
||||
|
||||
newVal = listContinuation('-', newVal);
|
||||
newVal = listContinuation('*', newVal);
|
||||
newVal = numberedListContinuation('.', newVal);
|
||||
newVal = numberedListContinuation(')', newVal);
|
||||
}
|
||||
|
||||
return newVal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,6 +134,7 @@ class CreatePostPage extends HookWidget {
|
|||
)
|
||||
],
|
||||
),
|
||||
Toolbar.safeArea,
|
||||
].spaced(6),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -62,12 +62,13 @@ extension on TextEditingController {
|
|||
class Toolbar extends HookWidget {
|
||||
final TextEditingController controller;
|
||||
|
||||
static const _height = 50.0;
|
||||
const Toolbar(this.controller);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 50,
|
||||
height: _height,
|
||||
width: double.infinity,
|
||||
color: Theme.of(context).cardColor,
|
||||
child: Material(
|
||||
|
@ -144,6 +145,8 @@ class Toolbar extends HookWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Widget safeArea = const SizedBox(height: _height);
|
||||
}
|
||||
|
||||
class AddLinkDialog extends HookWidget {
|
||||
|
@ -151,9 +154,11 @@ class AddLinkDialog extends HookWidget {
|
|||
final String url;
|
||||
final String selection;
|
||||
|
||||
static final _websiteRegex = RegExp(r'https?:\/\/', caseSensitive: false);
|
||||
|
||||
AddLinkDialog(this.selection)
|
||||
: title = selection.startsWith('https?://') ? '' : selection,
|
||||
url = selection.startsWith('https?://') ? selection : '';
|
||||
: title = selection.startsWith(_websiteRegex) ? '' : selection,
|
||||
url = selection.startsWith(_websiteRegex) ? selection : '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
Loading…
Reference in New Issue