From e3b561835be49d9f71316e1dafc8a1d0d837ffba Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Thu, 25 Aug 2022 17:50:06 +0200 Subject: [PATCH] remove magic number in favor of calculating it on the fly --- lib/widgets/editor/editor_toolbar.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/widgets/editor/editor_toolbar.dart b/lib/widgets/editor/editor_toolbar.dart index 95b8a39..4a34967 100644 --- a/lib/widgets/editor/editor_toolbar.dart +++ b/lib/widgets/editor/editor_toolbar.dart @@ -282,11 +282,15 @@ class _ToolbarBody extends HookWidget { IconButton( onPressed: () { controller.reformat((selection) { - final insides = selection.isNotEmpty ? selection : '___'; + const textBeg = '\n::: spoiler spoiler\n'; + final textMid = selection.isNotEmpty ? selection : '___'; + const textEnd = '\n:::\n'; + return _Reformat( - text: '\n::: spoiler spoiler\n$insides\n:::\n', - selectionBeginningShift: 21, - selectionEndingShift: 21 + insides.length - selection.length, + text: textBeg + textMid + textEnd, + selectionBeginningShift: textBeg.length, + selectionEndingShift: + textBeg.length + textMid.length - selection.length, ); }); },