Skip to content

Commit

Permalink
Making sure that text selection bounds are from lower to upper
Browse files Browse the repository at this point in the history
Making sure that text selection bounds are from lower to upper
  • Loading branch information
BastiennM authored Oct 13, 2023
2 parents 241e45f + 583c002 commit f239f43
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/markdown_text_input.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math';
import 'dart:ui';

import 'package:expandable/expandable.dart';
Expand Down Expand Up @@ -98,8 +99,8 @@ class _MarkdownTextInputState extends State<MarkdownTextInput> {
final basePosition = textSelection.baseOffset;
var noTextSelected = (textSelection.baseOffset - textSelection.extentOffset) == 0;

var fromIndex = textSelection.baseOffset;
var toIndex = textSelection.extentOffset;
var fromIndex = min(textSelection.baseOffset, textSelection.extentOffset);
var toIndex = max(textSelection.extentOffset, textSelection.baseOffset);

final result =
FormatMarkdown.convertToMarkdown(type, _controller.text, fromIndex, toIndex, titleSize: titleSize, link: link, selectedText: selectedText ?? _controller.text.substring(fromIndex, toIndex));
Expand Down

0 comments on commit f239f43

Please sign in to comment.