@@ -163,23 +163,23 @@ namespace BitBlazorUI {
163
163
this . textArea . focus ( ) ;
164
164
}
165
165
166
- add ( content : Content ) {
167
- const end = this . end ;
168
- const start = this . start ;
166
+ add ( content : Content , start ?: number , end ?: number ) {
167
+ const s = start || this . start ;
168
+ const e = end || this . end ;
169
169
170
- this . insert ( content , start , end ) ;
171
- this . setCaret ( content . value , start , end ) ;
170
+ this . insert ( content , s , e ) ;
171
+ this . setCaret ( content . value , s , e ) ;
172
172
}
173
173
174
- getLists ( str : string | undefined ) {
174
+ getRepeat ( str : string | undefined ) {
175
175
if ( ! str ) return ;
176
176
177
177
if ( startsWithDash ( str ) ) {
178
178
return '- ' ;
179
179
}
180
180
181
- const listNum = startsWithNumber ( str ) ;
182
- if ( listNum ) return `${ listNum } . ` ;
181
+ const n = startsWithNumber ( str ) ;
182
+ if ( n ) return `${ n } . ` ;
183
183
}
184
184
185
185
correct ( cur : number , isDec = false ) {
@@ -188,31 +188,21 @@ namespace BitBlazorUI {
188
188
const l = total [ i ] ;
189
189
if ( ! l ) continue ;
190
190
191
- if ( startsWithDash ( l ) ) {
192
- if ( l . length > 2 ) {
193
- total [ i ] = l ;
191
+ const number = startsWithNumber ( l ) ;
192
+ if ( ! number ) break ;
193
+
194
+ let newNumber : number ;
195
+ if ( isDec ) {
196
+ if ( number > 1 ) {
197
+ newNumber = number - 1 ;
194
198
} else {
195
- continue ;
196
- }
197
- } else {
198
- const number = startsWithNumber ( l ) ;
199
- if ( ! number ) {
200
199
break ;
201
- } else {
202
- let newNumber : number ;
203
- if ( isDec ) {
204
- if ( number > 1 ) {
205
- newNumber = number - 1 ;
206
- } else {
207
- break ;
208
- }
209
- } else {
210
- newNumber = number + 1 ;
211
- }
212
- total [ i ] = l . slice ( String ( number ) . length ) ;
213
- total [ i ] = String ( newNumber ) + total [ i ] ;
214
200
}
201
+ } else {
202
+ newNumber = number + 1 ;
215
203
}
204
+ total [ i ] = l . slice ( String ( number ) . length ) ;
205
+ total [ i ] = String ( newNumber ) + total [ i ] ;
216
206
}
217
207
this . value = total . join ( '\n' ) ;
218
208
}
@@ -269,16 +259,19 @@ namespace BitBlazorUI {
269
259
} else if ( e . key === 'Enter' ) {
270
260
const { total, num, col } = this . getLine ( ) ;
271
261
const line = total . at ( num ) ;
272
- let rep = this . getLists ( line ) ;
262
+ let rep = this . getRepeat ( line ) ;
273
263
const orig = rep ;
274
264
275
265
const n = startsWithNumber ( rep ) ;
276
266
if ( n ) rep = `${ n + 1 } . ` ;
277
267
278
268
if ( rep && ( orig && orig . length < col ) ) {
279
269
e . preventDefault ( ) ;
270
+ const start = this . start ;
271
+ const end = this . end ;
272
+
280
273
if ( n ) this . correct ( num ) ;
281
- this . add ( { type : 'inline' , value : `\n${ rep } ` } ) ;
274
+ this . add ( { type : 'inline' , value : `\n${ rep } ` } , start , end ) ;
282
275
} else if ( rep && ( orig && orig . length === col ) ) {
283
276
e . preventDefault ( ) ;
284
277
0 commit comments