add placeholder text to l10n

This commit is contained in:
Filip Krawczyk 2022-08-21 23:49:03 +02:00
parent 4cd8b9855c
commit 43fb2a8ceb
2 changed files with 32 additions and 10 deletions

View File

@ -411,5 +411,9 @@
"editor_help": "markdown guide",
"@editor_help": {
"description": "tooltip for button that goes to page containing a guide for markdown"
},
"insert_text_here_placeholder": "[write text here]",
"@insert_text_here_placeholder": {
"description": "placeholder for text in markdown editor when inserting stuff like * for italics or ** for bold, etc."
}
}

View File

@ -36,11 +36,13 @@ extension on TextEditingController {
String get afterSelectionText => text.substring(selection.extentOffset);
/// surroungs selection with given strings. If nothing is selected, placeholder is used in the middle
void surround(
String before, [
void surround({
required String before,
required String placeholder,
/// after = before if null
String? after,
String placeholder = '[write text here]',
]) {
}) {
after ??= before;
final beg = text.substring(0, selection.baseOffset);
final mid = () {
@ -202,12 +204,16 @@ class _ToolbarBody extends HookWidget {
return Row(
children: [
IconButton(
onPressed: () => controller.surround('**'),
onPressed: () => controller.surround(
before: '**',
placeholder: L10n.of(context).insert_text_here_placeholder),
icon: const Icon(Icons.format_bold),
tooltip: L10n.of(context).editor_bold,
),
IconButton(
onPressed: () => controller.surround('*'),
onPressed: () => controller.surround(
before: '*',
placeholder: L10n.of(context).insert_text_here_placeholder),
icon: const Icon(Icons.format_italic),
tooltip: L10n.of(context).editor_italics,
),
@ -302,7 +308,10 @@ class _ToolbarBody extends HookWidget {
child: const Icon(Icons.h_mobiledata),
),
IconButton(
onPressed: () => controller.surround('~~'),
onPressed: () => controller.surround(
before: '~~',
placeholder: L10n.of(context).insert_text_here_placeholder,
),
icon: const Icon(Icons.format_strikethrough),
tooltip: L10n.of(context).editor_strikethrough,
),
@ -329,17 +338,26 @@ class _ToolbarBody extends HookWidget {
tooltip: L10n.of(context).editor_list,
),
IconButton(
onPressed: () => controller.surround('`'),
onPressed: () => controller.surround(
before: '`',
placeholder: L10n.of(context).insert_text_here_placeholder,
),
icon: const Icon(Icons.code),
tooltip: L10n.of(context).editor_code,
),
IconButton(
onPressed: () => controller.surround('~'),
onPressed: () => controller.surround(
before: '~',
placeholder: L10n.of(context).insert_text_here_placeholder,
),
icon: const Icon(Icons.subscript),
tooltip: L10n.of(context).editor_subscript,
),
IconButton(
onPressed: () => controller.surround('^'),
onPressed: () => controller.surround(
before: '^',
placeholder: L10n.of(context).insert_text_here_placeholder,
),
icon: const Icon(Icons.superscript),
tooltip: L10n.of(context).editor_superscript,
),