@@ -82,7 +82,7 @@ const methods = state => ({
8282 [ iter . ltr . word ] : "ltr" ,
8383 } ) ) [ iterator ]
8484 if ( ! state . cursors . collapsed ) {
85- return 0
85+ return countBytesBetweenCursors ( state )
8686 }
8787 const { uuid, offset } = state . cursors [ 0 ]
8888 const x = state . elements . findIndex ( each => each . uuid === uuid )
@@ -94,10 +94,10 @@ const methods = state => ({
9494 } ,
9595 // Removes a number of bytes (countL and countR).
9696 removeByteCounts ( countL , countR ) {
97-
98- // Get the current UUID element:
99- let { uuid , offset } = state . cursors [ 0 ] // TODO: Change to state.cursors[1]?
100- const uuidElement = state . elements . find ( each => each . uuid === uuid )
97+ // NOTE: Uses state.cursors[1] because of
98+ // !state.cursors.collapsed case.
99+ const uuidElement = state . elements . find ( each => each . uuid === state . cursors [ 1 ] . uuid )
100+ let offset = state . cursors [ 1 ] . offset
101101
102102 // Get the span (x) and character offset (offset):
103103 let x = 0
@@ -136,47 +136,29 @@ const methods = state => ({
136136
137137 mergeRedundantSpans ( uuidElement . spans )
138138
139- state . cursors [ 0 ] . offset -= decremented
139+ if ( state . cursors . collapsed ) {
140+ state . cursors [ 0 ] . offset -= decremented
141+ }
140142 this . collapse ( )
141143
142144 } ,
143145 backspaceRune ( ) {
144- if ( ! state . cursors . collapsed ) {
145- console . log ( countBytesBetweenCursors ( state ) )
146- return
147- }
148146 const count = this . countBytesToBoundary ( state , iter . rtl . rune )
149147 this . removeByteCounts ( count , 0 )
150148 } ,
151149 backspaceWord ( ) {
152- if ( ! state . cursors . collapsed ) {
153- // TODO: Compute the number of bytes needed
154- return
155- }
156150 const count = this . countBytesToBoundary ( state , iter . rtl . word )
157151 this . removeByteCounts ( count , 0 )
158152 } ,
159153 backspaceParagraph ( ) {
160- if ( ! state . cursors . collapsed ) {
161- // TODO: Compute the number of bytes needed
162- return
163- }
164154 const count = this . countBytesToBoundary ( state , iter . rtl . line )
165155 this . removeByteCounts ( count , 0 )
166156 } ,
167157 forwardBackspaceRune ( ) {
168- if ( ! state . cursors . collapsed ) {
169- // TODO: Compute the number of bytes needed
170- return
171- }
172158 const count = this . countBytesToBoundary ( state , iter . ltr . rune )
173159 this . removeByteCounts ( 0 , count )
174160 } ,
175161 forwardBackspaceWord ( ) {
176- if ( ! state . cursors . collapsed ) {
177- // TODO: Compute the number of bytes needed
178- return
179- }
180162 const count = this . countBytesToBoundary ( state , iter . ltr . word )
181163 this . removeByteCounts ( 0 , count )
182164 } ,
0 commit comments