From 43fb2a8ceb82400f6eb3db56f23d8ab61d3c1700 Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Sun, 21 Aug 2022 23:49:03 +0200 Subject: [PATCH] add placeholder text to l10n --- assets/l10n/intl_en.arb | 4 +++ lib/widgets/editor/editor_toolbar.dart | 38 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/assets/l10n/intl_en.arb b/assets/l10n/intl_en.arb index 098ea82..9034a2b 100644 --- a/assets/l10n/intl_en.arb +++ b/assets/l10n/intl_en.arb @@ -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." } } diff --git a/lib/widgets/editor/editor_toolbar.dart b/lib/widgets/editor/editor_toolbar.dart index 614f348..9fad3c6 100644 --- a/lib/widgets/editor/editor_toolbar.dart +++ b/lib/widgets/editor/editor_toolbar.dart @@ -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, ),