@@ -229,6 +229,7 @@ export class OdooEditor extends EventTarget {
229
229
230
230
this . addDomListener ( this . editable , 'keydown' , this . _onKeyDown ) ;
231
231
this . addDomListener ( this . editable , 'input' , this . _onInput ) ;
232
+ this . addDomListener ( this . editable , 'beforeinput' , this . _onBeforeInput ) ;
232
233
this . addDomListener ( this . editable , 'mousedown' , this . _onMouseDown ) ;
233
234
this . addDomListener ( this . editable , 'mouseup' , this . _onMouseup ) ;
234
235
this . addDomListener ( this . editable , 'paste' , this . _onPaste ) ;
@@ -1652,6 +1653,10 @@ export class OdooEditor extends EventTarget {
1652
1653
// Handlers
1653
1654
//--------------------------------------------------------------------------
1654
1655
1656
+ _onBeforeInput ( ev ) {
1657
+ this . _lastBeforeInputType = ev . inputType ;
1658
+ }
1659
+
1655
1660
/**
1656
1661
* If backspace/delete input, rollback the operation and handle the
1657
1662
* operation ourself. Needed for mobile, used for desktop for consistency.
@@ -1665,21 +1670,28 @@ export class OdooEditor extends EventTarget {
1665
1670
const cursor = this . _historySteps [ this . _historySteps . length - 1 ] . cursor ;
1666
1671
const { focusOffset, focusNode, anchorNode, anchorOffset } = cursor || { } ;
1667
1672
const wasCollapsed = ! cursor || ( focusNode === anchorNode && focusOffset === anchorOffset ) ;
1673
+
1674
+ // Sometimes google chrome wrongly triggers an input event with `data`
1675
+ // being `null` on `deleteContentForward` `insertParagraph`. Luckily,
1676
+ // chrome provide the proper signal with the event `beforeinput`.
1677
+ const isChromeDeleteforward =
1678
+ ev . inputType === 'insertText' &&
1679
+ ev . data === null &&
1680
+ this . _lastBeforeInputType === 'deleteContentForward' ;
1681
+ const isChromeInsertParagraph =
1682
+ ev . inputType === 'insertText' &&
1683
+ ev . data === null &&
1684
+ this . _lastBeforeInputType === 'insertParagraph' ;
1668
1685
if ( this . keyboardType === KEYBOARD_TYPES . PHYSICAL || ! wasCollapsed ) {
1669
1686
if ( ev . inputType === 'deleteContentBackward' ) {
1670
1687
this . historyRollback ( ) ;
1671
1688
ev . preventDefault ( ) ;
1672
1689
this . _applyCommand ( 'oDeleteBackward' ) ;
1673
- } else if ( ev . inputType === 'deleteContentForward' ) {
1690
+ } else if ( ev . inputType === 'deleteContentForward' || isChromeDeleteforward ) {
1674
1691
this . historyRollback ( ) ;
1675
1692
ev . preventDefault ( ) ;
1676
1693
this . _applyCommand ( 'oDeleteForward' ) ;
1677
- } else if (
1678
- ev . inputType === 'insertParagraph' ||
1679
- ( ev . inputType === 'insertText' && ev . data === null )
1680
- ) {
1681
- // Sometimes the browser wrongly triggers an insertText
1682
- // input event with null data on enter.
1694
+ } else if ( ev . inputType === 'insertParagraph' || isChromeInsertParagraph ) {
1683
1695
this . historyRollback ( ) ;
1684
1696
ev . preventDefault ( ) ;
1685
1697
if ( this . _applyCommand ( 'oEnter' ) === UNBREAKABLE_ROLLBACK_CODE ) {
0 commit comments