From 123bcd4040a39820f201eeb773d2d9a036cd7da8 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Tue, 26 Dec 2023 18:59:37 +0100 Subject: [PATCH] Fix more label issues --- api/lib/src/models/text.dart | 2 +- app/lib/handlers/label.dart | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/api/lib/src/models/text.dart b/api/lib/src/models/text.dart index 205a317dcf46..d804961575c8 100644 --- a/api/lib/src/models/text.dart +++ b/api/lib/src/models/text.dart @@ -167,7 +167,7 @@ sealed class TextParagraph with _$TextParagraph { } firstIndex ??= currentLength; spans.add(cut - ? span.subSpan(start - currentLength, end - start - currentLength) + ? span.subSpan(start - currentLength, end - currentLength) : span); } currentLength += span.length; diff --git a/app/lib/handlers/label.dart b/app/lib/handlers/label.dart index 59af7aef3318..92e850ba03f7 100644 --- a/app/lib/handlers/label.dart +++ b/app/lib/handlers/label.dart @@ -115,6 +115,7 @@ class LabelHandler extends Handler extentOffset: position.offset, ), ); + _refreshToolbar(context.getDocumentBloc()); context.refresh(); } } @@ -262,12 +263,8 @@ class LabelHandler extends Handler _updateEditingState(); } - void _refreshToolbar(DocumentBloc bloc) { - final state = bloc.state; - if (state is DocumentLoaded) { - state.currentIndexCubit.refreshToolbar(bloc); - } - } + void _refreshToolbar(DocumentBloc bloc) => + bloc.state.currentIndexCubit?.refreshToolbar(bloc); @override void dispose(DocumentBloc bloc) { @@ -434,8 +431,6 @@ class LabelHandler extends Handler lastValue.selection.end - lastValue.text.length + value.length; final currentText = value.substring( start, value.length - lastValue.text.length + lastValue.composing.end); - print( - 'Text: $currentText, currentText: $currentText, start: ${lastValue.composing.start}, end: ${lastValue.composing.end}, value: $value, lastValue: ${lastValue.text}}'); _context = _context?.map(text: (e) { final old = e.element; if (old != null) { @@ -587,6 +582,7 @@ class LabelHandler extends Handler ); bloc.refresh(); _updateEditingState(); + _refreshToolbar(bloc); return null; }, ), @@ -643,6 +639,7 @@ class LabelHandler extends Handler ), ); _updateEditingState(); + _refreshToolbar(bloc); return null; }, ),