@@ -8,11 +8,11 @@ export const shouldApplySmartQuotes = (config, target) => {
8
8
const isDoubleQuote = ( char ) => / ^ [ « » " “ ” „ ] $ / . test ( char )
9
9
const isSingleQuote = ( char ) => / ^ [ ‘ ’ ‹ › ‚ ' ] $ / . test ( char )
10
10
const isApostrophe = ( char ) => / ^ [ ’ ' ] $ / . test ( char )
11
+ const isWhitespace = ( char ) => / ^ \s $ / . test ( char )
11
12
12
- // TODO: Test with: '>', ' ', no space & all kinds of dashes dash
13
- // edge case: applied tooltip quotes and then inserted single quote after space
14
13
const shouldBeOpeningQuote = ( text , indexCharBefore ) => indexCharBefore < 0 || / \s | [ > \- – — ] / . test ( text [ indexCharBefore ] )
15
- const shouldBeClosingQuote = ( text , indexCharBefore ) => text [ indexCharBefore ] && ! / \s / . test ( text [ indexCharBefore ] )
14
+ const shouldBeClosingQuote = ( text , indexCharBefore ) => ! ! text [ indexCharBefore ] && ! isWhitespace ( text [ indexCharBefore ] )
15
+ const hasCharAfter = ( textArr , indexCharAfter ) => ! ! textArr [ indexCharAfter ] && ! isWhitespace ( textArr [ indexCharAfter ] )
16
16
17
17
const replaceQuote = ( range , index , quoteType ) => {
18
18
const startContainer = range . startContainer
@@ -24,24 +24,13 @@ const replaceQuote = (range, index, quoteType) => {
24
24
return textNode
25
25
}
26
26
27
- // TODO: Fix ‹Didn’t› case -> only works with timeout
28
- const hasCharAfter = ( textArr , offset ) => {
29
- console . log ( 'textArr :>> ' , textArr )
30
- console . log ( 'offset :>> ' , offset )
31
- return false
32
- }
33
-
34
27
const hasSingleOpeningQuote = ( textArr , offset , singleOpeningQuote ) => {
35
28
if ( offset <= 0 ) {
36
29
return false
37
30
}
38
31
for ( let i = offset - 1 ; i >= 0 ; i -- ) {
39
32
if ( isSingleQuote ( textArr [ i ] ) && ( ! isApostrophe ( singleOpeningQuote ) && ! isApostrophe ( textArr [ i ] ) ) ) {
40
33
return textArr [ i ] === singleOpeningQuote
41
- // TODO: keep on looking for an unclosed single opening quote -> need to save single opening and closing quotes
42
- // if (textArr[i] === singleOpeningQuote) {
43
- // return true
44
- // }
45
34
}
46
35
}
47
36
return false
@@ -82,10 +71,9 @@ export const applySmartQuotes = (range, config, char, target, carretOffset) => {
82
71
return
83
72
}
84
73
85
- // Resets the cursor
74
+ // Resets the cursor to the currentPosition after applying the smart-quote
86
75
const window = target . ownerDocument . defaultView
87
76
const selection = window . getSelection ( )
88
77
selection . collapse ( newTextNode , carretOffset ?? offset )
89
78
}
90
79
91
- // TODO: fix special case when quickly typing two quotes after each other
0 commit comments