From a3de6add7185f2a852e381a3221eb6693ef52c0d Mon Sep 17 00:00:00 2001 From: Nicholas Wylie Date: Thu, 25 Jun 2020 16:00:06 +1000 Subject: [PATCH] Update shortcuts to toggle lists Previously ctrl+shift+{7,8} would make an (un)ordered list but hitting the shortcut again would have no effect. This change causes the list to be removed when triggering the shortcut while inside the list. --- source/KeyHandlers.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/KeyHandlers.js b/source/KeyHandlers.js index 69e0ddd..02cbc1d 100644 --- a/source/KeyHandlers.js +++ b/source/KeyHandlers.js @@ -591,14 +591,28 @@ const changeIndentationLevel = function ( methodIfInQuote, methodIfInList ) { }; }; +const toggleList = function ( listRegex, methodIfNotInList ) { + return function ( self, event ) { + event.preventDefault(); + var path = self.getPath(); + if ( !listRegex.test( path ) ) { + self[ methodIfNotInList ](); + } else { + self.removeList(); + } + }; +}; + keyHandlers[ ctrlKey + 'b' ] = mapKeyToFormat( 'B' ); keyHandlers[ ctrlKey + 'i' ] = mapKeyToFormat( 'I' ); keyHandlers[ ctrlKey + 'u' ] = mapKeyToFormat( 'U' ); keyHandlers[ ctrlKey + 'shift-7' ] = mapKeyToFormat( 'S' ); keyHandlers[ ctrlKey + 'shift-5' ] = mapKeyToFormat( 'SUB', { tag: 'SUP' } ); keyHandlers[ ctrlKey + 'shift-6' ] = mapKeyToFormat( 'SUP', { tag: 'SUB' } ); -keyHandlers[ ctrlKey + 'shift-8' ] = mapKeyTo( 'makeUnorderedList' ); -keyHandlers[ ctrlKey + 'shift-9' ] = mapKeyTo( 'makeOrderedList' ); +keyHandlers[ ctrlKey + 'shift-8' ] = + toggleList( /(?:^|>)UL/, 'makeUnorderedList' ); +keyHandlers[ ctrlKey + 'shift-9' ] = + toggleList( /(?:^|>)OL/, 'makeOrderedList' ); keyHandlers[ ctrlKey + '[' ] = changeIndentationLevel( 'decreaseQuoteLevel', 'decreaseListLevel' ); keyHandlers[ ctrlKey + ']' ] =