Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix (tabulator): caret saving works unexpectedly in safare #86

Merged
merged 10 commits into from
Oct 9, 2024
Merged
29 changes: 3 additions & 26 deletions src/ListTabulator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NestedListConfig, ListData, ListDataStyle } from '../types/ListPar
import type { ListItem } from '../types/ListParams';
import type { ItemElement, ItemChildWrapperElement } from '../types/Elements';
import { isHtmlElement } from '../utils/type-guards';
import { getContenteditableSlice, getCaretNodeAndOffset, focus, isCaretAtStartOfInput, save as saveCaret } from '@editorjs/caret';
import { getContenteditableSlice, getCaretNodeAndOffset, focus, isCaretAtStartOfInput } from '@editorjs/caret';
import { DefaultListCssClasses } from '../ListRenderer';
import type { PasteEvent } from '../types';
import type { API, BlockAPI, PasteConfig } from '@editorjs/editorjs';
Expand Down Expand Up @@ -227,15 +227,11 @@ export default class ListTabulator<Renderer extends ListRenderer> {

focus(deepestBlockItemContentElement);

const restore = saveCaret();

/**
* Insert trailing html to the deepest block item content
*/
deepestBlockItemContentElement.insertAdjacentHTML('beforeend', data.items[0].content);

restore();

if (this.listWrapper === undefined) {
return;
}
Expand Down Expand Up @@ -527,11 +523,9 @@ export default class ListTabulator<Renderer extends ListRenderer> {
item.appendChild(currentItemChildWrapper);
}

const restore = saveCaret();

parentItem.after(item);

restore();
focusItem(item, false);

/**
* If previous parent's children list is now empty, remove it.
Expand Down Expand Up @@ -747,11 +741,6 @@ export default class ListTabulator<Renderer extends ListRenderer> {
}
focus(targetItemContentElement, false);

/**
* Save the caret position
*/
const restore = saveCaret();

/**
* Update target item content by merging with current item html content
*/
Expand All @@ -771,11 +760,6 @@ export default class ListTabulator<Renderer extends ListRenderer> {
*/
item.remove();

/**
* Restore the caret position
*/
restore();

return;
}

Expand Down Expand Up @@ -812,11 +796,6 @@ export default class ListTabulator<Renderer extends ListRenderer> {
* Remove current item element
*/
item.remove();

/**
* Restore the caret position
*/
restore();
}

/**
Expand Down Expand Up @@ -856,8 +835,6 @@ export default class ListTabulator<Renderer extends ListRenderer> {

const prevItemChildrenList = getItemChildWrapper(prevItem);

const restore = saveCaret();

/**
* If prev item has child items, just append current to them
* Else render new child wrapper for previous item
Expand Down Expand Up @@ -904,7 +881,7 @@ export default class ListTabulator<Renderer extends ListRenderer> {
prevItem.appendChild(prevItemChildrenListWrapper);
}

restore();
focusItem(currentItem, false);
}

/**
Expand Down
Loading