@@ -6,7 +6,7 @@ import config from './config.js'
6
6
import Keyboard from './keyboard.js'
7
7
import { closest } from './util/dom.js'
8
8
import { replaceLast , endsWithSingleSpace } from './util/string.js'
9
- import { shouldApplySmartQuotes , isQuote , isOpeningQuote , isClosingQuote } from './smartQuotes.js'
9
+ import { applySmartQuotes , shouldApplySmartQuotes } from './smartQuotes.js'
10
10
11
11
/**
12
12
* The Dispatcher module is responsible for dealing with events and their handlers.
@@ -147,36 +147,14 @@ export default class Dispatcher {
147
147
if ( ! block ) return
148
148
149
149
const target = evt . target
150
- const currentChar = evt . data
151
-
152
-
153
- if ( target . isContentEditable && shouldApplySmartQuotes ( config ) ) {
154
- if ( isQuote ( currentChar ) ) {
155
- const selection = this . selectionWatcher . getFreshSelection ( )
156
- const wholeText = selection . range . startContainer . wholeText
157
- // const firstPart = selection.range.startContainer.textContent
158
- const offset = selection . range . startOffset
159
- if ( isClosingQuote ( [ ...wholeText ] , offset - 2 ) ) {
160
- const textArr = [ ...target . innerText ]
161
- const index = offset - 1
162
- if ( index >= 0 && index < textArr . length ) {
163
- textArr [ index ] = '»'
164
- target . innerText = textArr . join ( '' )
165
- }
166
- this . editable . createCursorAtCharacterOffset ( { element : block , offset} )
167
- }
168
-
169
- if ( isOpeningQuote ( [ ...wholeText ] , offset - 2 ) ) {
170
- const textArr = [ ...target . innerText ]
171
- const index = offset - 1
172
- if ( index >= 0 && index < textArr . length ) {
173
- textArr [ index ] = '«'
174
- target . innerText = textArr . join ( '' )
175
- }
176
- this . editable . createCursorAtCharacterOffset ( { element : block , offset} )
177
- }
178
- }
179
150
151
+ if ( shouldApplySmartQuotes ( config , target ) ) {
152
+ const currentChar = evt . data
153
+ const selection = this . selectionWatcher . getFreshSelection ( )
154
+ const offset = selection . range . startOffset
155
+ const wholeText = [ ...target . innerText ]
156
+ const resetCursor = ( ) => this . editable . createCursorAtCharacterOffset ( { element : block , offset} )
157
+ applySmartQuotes ( config , currentChar , wholeText , offset , target , resetCursor )
180
158
}
181
159
this . notify ( 'change' , block )
182
160
} )
0 commit comments