|
|
|
|
@ -54,6 +54,35 @@ Widget markdownContextBuilder(
|
|
|
|
|
ContextMenuController.removeAny();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ContextMenuButtonItem(
|
|
|
|
|
label: l10n.checkList,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
final text = controller.text;
|
|
|
|
|
final selection = controller.selection;
|
|
|
|
|
|
|
|
|
|
var start = selection.textBefore(text).lastIndexOf('\n');
|
|
|
|
|
if (start == -1) start = 0;
|
|
|
|
|
final end = selection.end;
|
|
|
|
|
|
|
|
|
|
final fullLineSelection =
|
|
|
|
|
TextSelection(baseOffset: start, extentOffset: end);
|
|
|
|
|
|
|
|
|
|
const checkBox = '- [ ]';
|
|
|
|
|
|
|
|
|
|
final replacedRange = fullLineSelection
|
|
|
|
|
.textInside(text)
|
|
|
|
|
.split('\n')
|
|
|
|
|
.map(
|
|
|
|
|
(line) => line.startsWith(checkBox) || line.isEmpty
|
|
|
|
|
? line
|
|
|
|
|
: '$checkBox $line',
|
|
|
|
|
)
|
|
|
|
|
.join('\n');
|
|
|
|
|
controller.text =
|
|
|
|
|
controller.text.replaceRange(start, end, replacedRange);
|
|
|
|
|
ContextMenuController.removeAny();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
ContextMenuButtonItem(
|
|
|
|
|
label: l10n.boldText,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|