@ -327,7 +327,7 @@ class QuillController extends ChangeNotifier {
if ( textSelection ! = null ) {
if ( textSelection ! = null ) {
if ( delta = = null | | delta . isEmpty ) {
if ( delta = = null | | delta . isEmpty ) {
_updateSelection ( textSelection , ChangeSource . local ) ;
_updateSelection ( textSelection ) ;
} else {
} else {
final user = Delta ( )
final user = Delta ( )
. . retain ( index )
. . retain ( index )
@ -335,12 +335,11 @@ class QuillController extends ChangeNotifier {
. . delete ( len ) ;
. . delete ( len ) ;
final positionDelta = getPositionDelta ( user , delta ) ;
final positionDelta = getPositionDelta ( user , delta ) ;
_updateSelection (
_updateSelection (
textSelection . copyWith (
textSelection . copyWith (
baseOffset: textSelection . baseOffset + positionDelta ,
baseOffset: textSelection . baseOffset + positionDelta ,
extentOffset: textSelection . extentOffset + positionDelta ,
extentOffset: textSelection . extentOffset + positionDelta ,
) ,
) ,
ChangeSource . local ,
insertNewline: data = = ' \n ' ) ;
) ;
}
}
}
}
@ -389,7 +388,7 @@ class QuillController extends ChangeNotifier {
baseOffset: change . transformPosition ( selection . baseOffset ) ,
baseOffset: change . transformPosition ( selection . baseOffset ) ,
extentOffset: change . transformPosition ( selection . extentOffset ) ) ;
extentOffset: change . transformPosition ( selection . extentOffset ) ) ;
if ( selection ! = adjustedSelection ) {
if ( selection ! = adjustedSelection ) {
_updateSelection ( adjustedSelection , ChangeSource . local ) ;
_updateSelection ( adjustedSelection ) ;
}
}
if ( shouldNotifyListeners ) {
if ( shouldNotifyListeners ) {
notifyListeners ( ) ;
notifyListeners ( ) ;
@ -428,7 +427,7 @@ class QuillController extends ChangeNotifier {
}
}
void updateSelection ( TextSelection textSelection , ChangeSource source ) {
void updateSelection ( TextSelection textSelection , ChangeSource source ) {
_updateSelection ( textSelection , source ) ;
_updateSelection ( textSelection ) ;
notifyListeners ( ) ;
notifyListeners ( ) ;
}
}
@ -445,7 +444,7 @@ class QuillController extends ChangeNotifier {
) ,
) ,
) ;
) ;
if ( selection ! = textSelection ) {
if ( selection ! = textSelection ) {
_updateSelection ( textSelection , source ) ;
_updateSelection ( textSelection ) ;
}
}
notifyListeners ( ) ;
notifyListeners ( ) ;
@ -479,18 +478,23 @@ class QuillController extends ChangeNotifier {
super . dispose ( ) ;
super . dispose ( ) ;
}
}
void _updateSelection ( TextSelection textSelection , ChangeSource source ) {
void _updateSelection ( TextSelection textSelection ,
{ bool insertNewline = false } ) {
_selection = textSelection ;
_selection = textSelection ;
final end = document . length - 1 ;
final end = document . length - 1 ;
_selection = selection . copyWith (
_selection = selection . copyWith (
baseOffset: math . min ( selection . baseOffset , end ) ,
baseOffset: math . min ( selection . baseOffset , end ) ,
extentOffset: math . min ( selection . extentOffset , end ) ) ;
extentOffset: math . min ( selection . extentOffset , end ) ) ;
if ( keepStyleOnNewLine ) {
if ( keepStyleOnNewLine ) {
final style = getSelectionStyle ( ) ;
if ( insertNewline & & selection . start > 0 ) {
final ignoredStyles = style . attributes . values . where (
final style = document . collectStyle ( selection . start - 1 , 0 ) ;
( s ) = > ! s . isInline | | s . key = = Attribute . link . key ,
final ignoredStyles = style . attributes . values . where (
) ;
( s ) = > ! s . isInline | | s . key = = Attribute . link . key ,
toggledStyle = style . removeAll ( ignoredStyles . toSet ( ) ) ;
) ;
toggledStyle = style . removeAll ( ignoredStyles . toSet ( ) ) ;
} else {
toggledStyle = const Style ( ) ;
}
} else {
} else {
toggledStyle = const Style ( ) ;
toggledStyle = const Style ( ) ;
}
}