@@ -177,6 +177,7 @@ test('an input handler will trigger anywhere in the text', (assert) => {
177177 let expandCount = 0 ;
178178 let lastMatches ;
179179 editor . onTextInput ( {
180+ name : 'at' ,
180181 text : '@' ,
181182 run : ( editor , matches ) => {
182183 expandCount ++ ;
@@ -210,6 +211,7 @@ test('an input handler can provide a `match` instead of `text`', (assert) => {
210211 let lastMatches ;
211212 let regex = / .( .) X $ / ;
212213 editor . onTextInput ( {
214+ name : 'test' ,
213215 match : regex ,
214216 run : ( editor , matches ) => {
215217 expandCount ++ ;
@@ -243,6 +245,7 @@ test('an input handler can provide a `match` that matches at start and end', (as
243245 let lastMatches ;
244246 let regex = / ^ \d \d \d $ / ;
245247 editor . onTextInput ( {
248+ name : 'test' ,
246249 match : regex ,
247250 run : ( editor , matches ) => {
248251 expandCount ++ ;
@@ -273,6 +276,7 @@ test('input handler can be triggered by TAB', (assert) => {
273276
274277 let didMatch ;
275278 editor . onTextInput ( {
279+ name : 'test' ,
276280 match : / a b c \t / ,
277281 run ( ) {
278282 didMatch = true ;
@@ -283,3 +287,46 @@ test('input handler can be triggered by TAB', (assert) => {
283287
284288 assert . ok ( didMatch ) ;
285289} ) ;
290+
291+ test ( 'can unregister all handlers' , ( assert ) => {
292+ editor = Helpers . editor . buildFromText ( '' ) ;
293+ // there are 3 default helpers
294+ assert . equal ( editor . _eventManager . _textInputHandler . _handlers . length , 3 ) ;
295+ editor . onTextInput ( {
296+ name : 'first' ,
297+ match : / a b c \t / ,
298+ run ( ) { }
299+ } ) ;
300+ editor . onTextInput ( {
301+ name : 'second' ,
302+ match : / a b c \t / ,
303+ run ( ) { }
304+ } ) ;
305+ assert . equal ( editor . _eventManager . _textInputHandler . _handlers . length , 5 ) ;
306+ editor . unregisterAllTextInputHandlers ( ) ;
307+ assert . equal ( editor . _eventManager . _textInputHandler . _handlers . length , 0 ) ;
308+ } ) ;
309+
310+ test ( 'can unregister handler by name' , ( assert ) => {
311+ editor = Helpers . editor . buildFromText ( '' ) ;
312+ const handlerName = 'ul' ;
313+ let handlers = editor . _eventManager . _textInputHandler . _handlers ;
314+ assert . ok ( handlers . filter ( handler => handler . name === handlerName ) . length ) ;
315+ editor . unregisterTextInputHandler ( handlerName ) ;
316+ assert . notOk ( handlers . filter ( handler => handler . name === handlerName ) . length ) ;
317+ } ) ;
318+
319+ test ( 'can unregister handlers by duplicate name' , ( assert ) => {
320+ editor = Helpers . editor . buildFromText ( '' ) ;
321+ const handlerName = 'ul' ;
322+ editor . onTextInput ( {
323+ name : handlerName ,
324+ match : / a b c / ,
325+ run ( ) { }
326+ } ) ;
327+ let handlers = editor . _eventManager . _textInputHandler . _handlers ;
328+ assert . equal ( handlers . length , 4 ) ; // 3 default + 1 custom handlers
329+ editor . unregisterTextInputHandler ( handlerName ) ;
330+ assert . equal ( handlers . length , 2 ) ;
331+ assert . notOk ( handlers . filter ( handler => handler . name === handlerName ) . length ) ;
332+ } ) ;
0 commit comments