(done, value)
| 223 | } |
| 224 | |
| 225 | function typeAction (done, value) { |
| 226 | let actor = getCurrentActor() |
| 227 | |
| 228 | let locale = props.options.locale |
| 229 | let minSpeed = props.options.minSpeed.type |
| 230 | let maxSpeed = props.options.maxSpeed.type |
| 231 | let initialValue = actor.displayValue |
| 232 | let cursor = -1 |
| 233 | let isFixing = false |
| 234 | let previousMistakeCursor = null |
| 235 | let previousFixCursor = null |
| 236 | |
| 237 | let htmlMap = html.map(value) |
| 238 | value = html.strip(value) |
| 239 | |
| 240 | ;(function type () { |
| 241 | let actual = html.strip(actor.displayValue.substr(initialValue.length)) |
| 242 | |
| 243 | if (actual === value) return done() |
| 244 | |
| 245 | let expected = value.substr(0, cursor + 1) |
| 246 | |
| 247 | let isMistaking = actual !== expected |
| 248 | let shouldBeMistaken = actor.shouldBeMistaken(actual, value, previousMistakeCursor, previousFixCursor) |
| 249 | let shouldFix = isFixing || !shouldBeMistaken |
| 250 | |
| 251 | if (isMistaking && shouldFix) { |
| 252 | isFixing = true |
| 253 | previousMistakeCursor = null |
| 254 | actor.displayValue = initialValue + html.inject(actual.substr(0, actual.length - 1), htmlMap) |
| 255 | cursor-- |
| 256 | previousFixCursor = cursor |
| 257 | } else { |
| 258 | isFixing = false |
| 259 | let nextChar = value.charAt(++cursor) |
| 260 | |
| 261 | if (shouldBeMistaken) { |
| 262 | nextChar = keyboard.randomCharNear(nextChar, locale) |
| 263 | |
| 264 | if (previousMistakeCursor == null) { |
| 265 | previousMistakeCursor = cursor |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | actor.displayValue = initialValue + html.inject(actual + nextChar, htmlMap) |
| 270 | } |
| 271 | |
| 272 | return setTimeout(type, actor.getTypingSpeed(minSpeed, maxSpeed)) |
| 273 | })() |
| 274 | |
| 275 | return this |
| 276 | } |
| 277 | |
| 278 | function eraseAction (done, arg) { |
| 279 | let actor = getCurrentActor() |
no test coverage detected