Skip to content

Commit bf3adc8

Browse files
committed
fix: awkward pausing issues due to how deletions were being handled.
1 parent 2894f0f commit bf3adc8

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

packages/typeit/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/typeit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typeit",
3-
"version": "8.5.3",
3+
"version": "8.5.4",
44
"description": "The most versatile animated typing utility on the planet.",
55
"author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)",
66
"license": "GPL-3.0",

packages/typeit/src/Queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let Queue = function (initialItems: QueueItem[]) {
2020
* Given an index, set an item in the queue.
2121
*/
2222
let set = function (index: number, item: QueueItem): void {
23-
let keys = _q.keys();
23+
let keys = [..._q.keys()];
2424

2525
_q.set(keys[index], item);
2626
};

packages/typeit/src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ const TypeIt: TypeItInstance = function (element, options = {}) {
184184
let derivedCursorPosition = _getDerivedCursorPosition();
185185
derivedCursorPosition && (await _move({ value: derivedCursorPosition }));
186186

187-
for (let _i of _queue.getTypeable()) {
187+
// Grab all characters currently mounted to the DOM,
188+
// in order to wipe the slate clean before restarting.
189+
for (let _i of _getAllChars()) {
188190
await _wait(_delete, _getPace(1));
189191
}
190192

191193
_queue.reset();
192-
193194
_queue.set(0, { delay });
194195
};
195196

@@ -246,7 +247,13 @@ const TypeIt: TypeItInstance = function (element, options = {}) {
246247

247248
if (queueItem.typeable && !_statuses.frozen) _disableCursorBlink(true);
248249

249-
await fireItem(queueItem, _wait);
250+
// Because calling .delete() with no parameters will attempt to
251+
// delete all "typeable" characters, we may overfetch, since some characters
252+
// in the queue may already be deleted. This ensures that we do not attempt to
253+
// delete a character that isn't actually mounted to the DOM.
254+
if (!queueItem.deletable || (queueItem.deletable && _getAllChars().length)) {
255+
await fireItem(queueItem, _wait);
256+
}
250257

251258
_disableCursorBlink(false);
252259

@@ -366,6 +373,7 @@ const TypeIt: TypeItInstance = function (element, options = {}) {
366373
{
367374
func: _delete,
368375
delay: instant ? 0 : _getPace(1),
376+
deletable: true
369377
},
370378
rounds
371379
),

packages/typeit/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type QueueItem = {
4343
delay?: number;
4444
char?: any;
4545
typeable?: boolean;
46+
deletable?: boolean;
4647
};
4748

4849
export type Element = HTMLElement &

0 commit comments

Comments
 (0)