@@ -11,14 +11,14 @@ import {
1111 type ModelEvents ,
1212 TextAddedEvent ,
1313 TextRemovedEvent ,
14- Index
14+ type Index
1515} from '@editorjs/model' ;
1616import type {
1717 EventBus ,
1818 BlockToolAdapter as BlockToolAdapterInterface ,
1919 CoreConfig ,
2020 BeforeInputUIEvent ,
21- BeforeInputUIEventPayload ,
21+ BeforeInputUIEventPayload
2222} from '@editorjs/sdk' ;
2323import { BeforeInputUIEventName } from '@editorjs/sdk' ;
2424import type { CaretAdapter } from '../CaretAdapter/index.js' ;
@@ -306,6 +306,7 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
306306 */
307307 if ( start !== end ) {
308308 this . #model. removeText ( this . #config. userId , this . #blockIndex, key , start , end ) ;
309+
309310 return ;
310311 }
311312
@@ -359,18 +360,42 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
359360 this . #model. removeText ( this . #config. userId , this . #blockIndex, key , start , end ) ;
360361 }
361362
363+ /**
364+ * True if input contains only the start of the cross-input selection
365+ *
366+ * @param input - input element
367+ * @param range - selection range
368+ */
362369 #isInputContainsOnlyStartOfSelection( input : HTMLElement , range : StaticRange ) : boolean {
363370 return input . contains ( range . startContainer ) && ! input . contains ( range . endContainer ) ;
364371 }
365372
373+ /**
374+ * True if input contains only the end of the cross-input selection
375+ *
376+ * @param input - input element
377+ * @param range - selection range
378+ */
366379 #isInputContainsOnlyEndOfSelection( input : HTMLElement , range : StaticRange ) : boolean {
367380 return input . contains ( range . endContainer ) && ! input . contains ( range . startContainer ) ;
368381 }
369382
383+ /**
384+ * True if input contains the whole selection (not cross-input)
385+ *
386+ * @param input - input element
387+ * @param range - selection range
388+ */
370389 #isInputContainsWholeSelection( input : HTMLElement , range : StaticRange ) : boolean {
371390 return input . contains ( range . startContainer ) && input . contains ( range . endContainer ) ;
372391 }
373392
393+ /**
394+ * True if input is in between cross-input selection
395+ *
396+ * @param input - input element
397+ * @param range - selection range
398+ */
374399 #isInputInBetweenSelection( input : HTMLElement , range : StaticRange ) : boolean {
375400 return ! this . #isInputContainsWholeSelection( input , range ) &&
376401 ! this . #isInputContainsOnlyStartOfSelection( input , range ) &&
@@ -397,22 +422,15 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
397422 let end : number ;
398423 let newCaretIndex : number | null = null ;
399424
400- // console.log('delete in input', input);
401-
402425 /**
403426 * If range is fully contained within this input
404427 */
405428 if ( this . #isInputContainsWholeSelection( input , range ) ) {
406- // console.log('range is fully contained within this input');
407-
408429 start = getAbsoluteRangeOffset ( input , range . startContainer , range . startOffset ) ;
409430 end = getAbsoluteRangeOffset ( input , range . endContainer , range . endOffset ) ;
410431
411432 this . #model. removeText ( this . #config. userId , this . #blockIndex, key , start , end ) ;
412-
413- // newCaretIndex = start;
414433 } else if ( this . #isInputContainsOnlyStartOfSelection( input , range ) ) {
415- // console.log('only start is in this input');
416434 /**
417435 * If only start is in this input, delete from start to end of input
418436 */
@@ -425,20 +443,18 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
425443 newCaretIndex = start ;
426444 }
427445 } else if ( this . #isInputContainsOnlyEndOfSelection( input , range ) ) {
428- // console.log('only end is in this input');
429446 /**
430447 * If only end is in this input, delete from start of input to end
431- */
432- start = 0 ;
433- end = getAbsoluteRangeOffset ( input , range . endContainer , range . endOffset ) ;
448+ */
449+ start = 0 ;
450+ end = getAbsoluteRangeOffset ( input , range . endContainer , range . endOffset ) ;
434451
452+ const removedText = this . #model. removeText ( this . #config. userId , this . #blockIndex, key , start , end ) ;
435453
436- const removedText = this . #model. removeText ( this . #config. userId , this . #blockIndex, key , start , end ) ;
437- if ( isRestoreCaretToTheEnd ) {
438- newCaretIndex = end - removedText . length ;
439- }
454+ if ( isRestoreCaretToTheEnd ) {
455+ newCaretIndex = end - removedText . length ;
456+ }
440457 } else if ( this . #isInputInBetweenSelection( input , range ) ) {
441- // console.log('range spans across this input');
442458 /**
443459 * If range spans across this input, delete everything
444460 */
@@ -448,7 +464,6 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
448464 }
449465
450466 if ( newCaretIndex !== null ) {
451- console . info ( 'restore caret: block %o index %o caret %o' , this . #blockIndex, newCaretIndex ) ;
452467 this . #caretAdapter. updateIndex (
453468 new IndexBuilder ( )
454469 . addBlockIndex ( this . #blockIndex)
@@ -544,7 +559,7 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
544559 ( this . #isInputContainsOnlyStartOfSelection( input , range ) || this . #isInputContainsWholeSelection( input , range ) ) &&
545560 ! payload . isCrossInputSelection
546561 ) {
547- const start = isInputNative ?
562+ start = isInputNative ?
548563 ( input as HTMLInputElement | HTMLTextAreaElement ) . selectionStart as number :
549564 getAbsoluteRangeOffset ( input , range . startContainer , range . startOffset ) ;
550565
@@ -783,6 +798,8 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
783798
784799 /**
785800 * Allows access to a particular input by key
801+ *
802+ * @param key - data key of the input
786803 */
787804 public getInput ( key : DataKey ) : HTMLElement | undefined {
788805 return this . #attachedInputs. get ( key ) ;
0 commit comments