11import * as Types from "../Types"
22import methods from "./methods"
3- import NumberEnum from "lib/enums/NumberEnum"
43import queryCollection from "./queryCollection"
54
6- // Enumerates how to apply a format.
7- const enumerated = new NumberEnum (
8- "plaintext" ,
9- "shouldNotApply" ,
10- "shouldApply" ,
11- )
12-
135// Tests whether to apply a format.
146const testShouldApply = collection => ( T , P = { } ) => {
157 if ( T === "plaintext" ) {
16- return enumerated . plaintext
8+ return " plaintext"
179 }
18- const didApply = collection . every ( each => each . spans . every ( each => each . types . indexOf ( T ) >= 0 ) )
19- return didApply ? enumerated . shouldNotApply : enumerated . shouldApply
10+ const didApply = collection . every ( each => each . refs . spans . every ( each => each . types . indexOf ( T ) >= 0 ) )
11+ return didApply ? "should-not-apply" : "should-apply"
2012}
2113
2214// Applies a format to the current range.
@@ -26,34 +18,34 @@ const applyFormat = state => (T, P = {}) => {
2618 const shouldApply = testShouldApply ( collection ) ( T , P )
2719 switch ( shouldApply ) {
2820 // Plaintext:
29- case enumerated . plaintext :
21+ case " plaintext" :
3022 for ( const c of collection ) {
31- for ( const s of c . spans ) {
23+ for ( const s of c . refs . spans ) {
3224 for ( const T of s . types ) {
3325 s [ T ] = undefined
3426 }
3527 s . types . splice ( 0 )
3628 }
37- c . spans . map ( each => Types . sort ( each ) )
29+ c . refs . spans . map ( each => Types . sort ( each ) )
3830 }
3931 break
40- // Should not apply:
41- case enumerated . shouldNotApply :
32+ // Should not apply a format :
33+ case "should-not-apply" :
4234 for ( const c of collection ) {
43- for ( const s of c . spans ) {
35+ for ( const s of c . refs . spans ) {
4436 const x = s . types . indexOf ( T )
4537 if ( x >= 0 ) {
4638 s . types . splice ( x , 1 )
4739 s [ T ] = undefined
4840 }
4941 }
50- c . spans . map ( each => Types . sort ( each ) )
42+ c . refs . spans . map ( each => Types . sort ( each ) )
5143 }
5244 break
53- // Should apply:
54- case enumerated . shouldApply :
45+ // Should apply a format :
46+ case "should-apply" :
5547 for ( const c of collection ) {
56- for ( const s of c . spans ) {
48+ for ( const s of c . refs . spans ) {
5749 const x = s . types . indexOf ( T )
5850 if ( x === - 1 ) {
5951 s . types . push ( T )
@@ -62,7 +54,7 @@ const applyFormat = state => (T, P = {}) => {
6254 }
6355 }
6456 }
65- c . spans . map ( each => Types . sort ( each ) )
57+ c . refs . spans . map ( each => Types . sort ( each ) )
6658 }
6759 break
6860 default :
0 commit comments