@@ -19,15 +19,22 @@ export function toggle_format_with_data(editor, format, data, event) {
1919 if ( event ) event . preventDefault ( )
2020 let selection = get_selection ( editor )
2121 selection_edge ( editor , selection )
22+ selection = get_selection ( editor )
2223 if ( data ) apply_data ( editor , selection , data )
23- let apply = false
24- selection_each_text ( editor , selection , function ( node , index ) {
25- if ( ! u ( node ) . parent ( ) . hasClass ( format ) ) apply = true
26- } )
24+ let apply = should_apply_format ( editor , selection , format )
2725 if ( apply ) apply_format ( editor , selection , format )
2826 else remove_format ( editor , selection , format )
2927}
3028
29+ function should_apply_format ( editor , selection , format ) {
30+
31+ let result = false
32+ selection_each_text ( editor , selection , function ( node , index ) {
33+ if ( ! u ( node ) . parent ( ) . hasClass ( format ) ) result = true
34+ } )
35+ return result
36+ }
37+
3138function apply_data ( editor , selection , data ) {
3239
3340 selection_each_text ( editor , selection , function ( node , index ) {
0 commit comments