| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ce.RangeState = function VeCeRangeState( old, root, selectionOnly ) { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
this.branchNodeChanged = false; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
this.selectionChanged = false; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
this.contentChanged = false; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
this.veRange = null; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
this.node = null; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
this.text = null; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
this.hash = null; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
this.textState = null; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
this.focusIsAfterAnnotationBoundary = null; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
this.misleadingSelection = null; |
| 74 |
|
| 75 |
this.saveState( old, root, selectionOnly ); |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
OO.initClass( ve.ce.RangeState ); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ve.ce.RangeState.prototype.saveState = function ( old, root, selectionOnly ) { |
| 92 |
const oldSelection = old ? old.misleadingSelection : ve.SelectionState.static.newNullSelection(), |
| 93 |
nativeSelection = root.getElementDocument().getSelection(); |
| 94 |
|
| 95 |
let selection; |
| 96 |
if ( |
| 97 |
nativeSelection.rangeCount && |
| 98 |
OO.ui.contains( root.$element[ 0 ], nativeSelection.focusNode, true ) |
| 99 |
) { |
| 100 |
|
| 101 |
selection = new ve.SelectionState( nativeSelection ); |
| 102 |
} else { |
| 103 |
|
| 104 |
selection = ve.SelectionState.static.newNullSelection(); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
if ( selection.equalsSelection( oldSelection ) ) { |
| 109 |
|
| 110 |
this.selectionChanged = false; |
| 111 |
this.veRange = old && old.veRange; |
| 112 |
} else { |
| 113 |
this.selectionChanged = true; |
| 114 |
this.veRange = ve.ce.veRangeFromSelection( selection ); |
| 115 |
} |
| 116 |
|
| 117 |
const focusNodeChanged = oldSelection.focusNode !== selection.focusNode; |
| 118 |
|
| 119 |
if ( !focusNodeChanged ) { |
| 120 |
this.node = old && old.node; |
| 121 |
} else { |
| 122 |
const $node = $( selection.focusNode ).closest( '.ve-ce-branchNode' ); |
| 123 |
if ( $node.length === 0 ) { |
| 124 |
this.node = null; |
| 125 |
} else { |
| 126 |
this.node = $node.data( 'view' ); |
| 127 |
|
| 128 |
if ( this.node && this.node.root !== root.root ) { |
| 129 |
this.node = null; |
| 130 |
this.veRange = null; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
this.branchNodeChanged = ( old && old.node ) !== this.node; |
| 136 |
|
| 137 |
|
| 138 |
if ( !this.node ) { |
| 139 |
this.text = null; |
| 140 |
this.hash = null; |
| 141 |
this.textState = null; |
| 142 |
} else if ( selectionOnly && !focusNodeChanged ) { |
| 143 |
this.text = old.text; |
| 144 |
this.hash = old.hash; |
| 145 |
this.textState = old.textState; |
| 146 |
} else { |
| 147 |
this.text = ve.ce.getDomText( this.node.$element[ 0 ] ); |
| 148 |
this.hash = ve.ce.getDomHash( this.node.$element[ 0 ] ); |
| 149 |
this.textState = new ve.ce.TextState( this.node.$element[ 0 ] ); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
this.contentChanged = |
| 154 |
!selectionOnly && |
| 155 |
!this.branchNodeChanged && ( |
| 156 |
( old && old.hash ) !== this.hash || |
| 157 |
( old && old.text ) !== this.text || |
| 158 |
( !this.textState && old && old.textState ) || |
| 159 |
( !!this.textState && !this.textState.isEqual( old && old.textState ) ) |
| 160 |
); |
| 161 |
|
| 162 |
if ( old && !this.selectionChanged && !this.contentChanged ) { |
| 163 |
this.focusIsAfterAnnotationBoundary = old.focusIsAfterAnnotationBoundary; |
| 164 |
} else { |
| 165 |
|
| 166 |
this.focusIsAfterAnnotationBoundary = selection.focusNode && |
| 167 |
ve.ce.isAfterAnnotationBoundary( |
| 168 |
selection.focusNode, |
| 169 |
selection.focusOffset |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
this.misleadingSelection = selection; |
| 177 |
}; |