make end indice exclusive
This commit is contained in:
parent
8aefdfbf27
commit
87726f283b
|
@ -14,10 +14,10 @@ extension Utilities on String {
|
|||
|
||||
int getEndOfTheLine(int from) {
|
||||
for (var i = from; i < length; i++) {
|
||||
if (this[i] == '\n') return i;
|
||||
if (this[i] == '\n') return i + 1;
|
||||
}
|
||||
|
||||
return length - 1;
|
||||
return length;
|
||||
}
|
||||
|
||||
/// returns the line that ends at endingIndex
|
||||
|
|
|
@ -57,9 +57,9 @@ class EditorToolbar extends HookWidget {
|
|||
|
||||
return MobxProvider(
|
||||
create: (context) => EditorToolbarStore(instanceHost),
|
||||
child: ObserverBuilder<EditorToolbarStore>(builder: (context, store) {
|
||||
child: Builder(builder: (context) {
|
||||
return AsyncStoreListener(
|
||||
asyncStore: store.imageUploadState,
|
||||
asyncStore: context.read<EditorToolbarStore>().imageUploadState,
|
||||
child: AnimatedSwitcher(
|
||||
duration: kThemeAnimationDuration,
|
||||
transitionBuilder: (child, animation) {
|
||||
|
@ -214,15 +214,15 @@ class _ToolbarBody extends HookWidget {
|
|||
PopupMenuItem(
|
||||
value: h,
|
||||
child: Text(h.name.toUpperCase()),
|
||||
onTap: () {
|
||||
final header = '${'#' * h.value} ';
|
||||
|
||||
if (!controller.firstSelectedLine.startsWith(header)) {
|
||||
controller.insertAtBeginningOfFirstSelectedLine(header);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
onSelected: (val) {
|
||||
final header = '${'#' * val.value} ';
|
||||
|
||||
if (!controller.firstSelectedLine.startsWith(header)) {
|
||||
controller.insertAtBeginningOfFirstSelectedLine(header);
|
||||
}
|
||||
},
|
||||
tooltip: L10n.of(context).editor_header,
|
||||
child: const Icon(Icons.h_mobiledata),
|
||||
),
|
||||
|
@ -424,9 +424,12 @@ extension on TextEditingController {
|
|||
}
|
||||
|
||||
String get firstSelectedLine {
|
||||
if (text.isEmpty) return '';
|
||||
return text.substring(text.getBeginningOfTheLine(selection.start - 1),
|
||||
text.getEndOfTheLine(selection.end));
|
||||
if (text.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
final val = text.substring(text.getBeginningOfTheLine(selection.start - 1),
|
||||
text.getEndOfTheLine(selection.end) - 1);
|
||||
return val;
|
||||
}
|
||||
|
||||
void insertAtBeginningOfFirstSelectedLine(String s) {
|
||||
|
|
Loading…
Reference in New Issue