| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ve.ui.SequenceRegistry = function VeUiSequenceRegistry() { |
| 15 |
|
| 16 |
ve.ui.SequenceRegistry.super.call( this ); |
| 17 |
}; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
OO.inheritClass( ve.ui.SequenceRegistry, OO.Registry ); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
ve.ui.SequenceRegistry.prototype.register = function ( sequence ) { |
| 30 |
|
| 31 |
if ( !( sequence instanceof ve.ui.Sequence ) ) { |
| 32 |
throw new Error( |
| 33 |
'sequence must be an instance of ve.ui.Sequence, cannot be a ' + typeof sequence |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
ve.ui.SequenceRegistry.super.prototype.register.call( this, sequence.getName(), sequence ); |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
ve.ui.SequenceRegistry.prototype.findMatching = function ( data, offset, isPaste, isDelete ) { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
let textStart; |
| 72 |
let state = 0; |
| 73 |
for ( textStart = offset - 1; textStart >= 0 && ( offset - textStart ) <= 256; textStart-- ) { |
| 74 |
if ( state === 0 && !data.isOpenElementData( textStart ) ) { |
| 75 |
state++; |
| 76 |
} |
| 77 |
if ( state === 1 && !data.isCloseElementData( textStart ) ) { |
| 78 |
state++; |
| 79 |
} |
| 80 |
if ( state === 2 && data.isElementData( textStart ) ) { |
| 81 |
break; |
| 82 |
} |
| 83 |
} |
| 84 |
const sequences = []; |
| 85 |
const plaintext = data.getText( true, new ve.Range( textStart + 1, offset ) ); |
| 86 |
|
| 87 |
for ( const name in this.registry ) { |
| 88 |
const sequence = this.registry[ name ]; |
| 89 |
if ( isPaste && !sequence.checkOnPaste ) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
if ( isDelete && !sequence.checkOnDelete ) { |
| 93 |
continue; |
| 94 |
} |
| 95 |
const range = sequence.match( data, offset, plaintext ); |
| 96 |
if ( range !== null ) { |
| 97 |
sequences.push( { |
| 98 |
sequence: sequence, |
| 99 |
range: range |
| 100 |
} ); |
| 101 |
} |
| 102 |
} |
| 103 |
return sequences; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.sequenceRegistry = new ve.ui.SequenceRegistry(); |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
ve.ui.sequenceRegistry.register( |
| 113 |
new ve.ui.Sequence( 'bulletStar', 'bulletWrapOnce', [ { type: 'paragraph' }, '*', ' ' ], 2 ) |
| 114 |
); |
| 115 |
ve.ui.sequenceRegistry.register( |
| 116 |
new ve.ui.Sequence( 'numberDot', 'numberWrapOnce', [ { type: 'paragraph' }, '1', '.', ' ' ], 3 ) |
| 117 |
); |
| 118 |
ve.ui.sequenceRegistry.register( |
| 119 |
new ve.ui.Sequence( 'horizontalRule', 'insertHorizontalRule', [ { type: 'paragraph' }, '-', '-', '-', '-' ], 4 ) |
| 120 |
); |