Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/common/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,10 @@ const Composer: FC<OwnProps & StateProps> = ({
});

const removeSymbol = useLastCallback((inInputId = editableInputId) => {
const selection = window.getSelection()!;
const html = getHtml();
if (!html) return;

const selection = window.getSelection()!;
if (selection.rangeCount) {
const selectionRange = selection.getRangeAt(0);
if (isSelectionInsideInput(selectionRange, inInputId)) {
Expand All @@ -1281,7 +1283,7 @@ const Composer: FC<OwnProps & StateProps> = ({
}
}

setHtml(deleteLastCharacterOutsideSelection(getHtml()));
setHtml(deleteLastCharacterOutsideSelection(html));
});

const removeSymbolAttachmentModal = useLastCallback(() => {
Expand Down
15 changes: 10 additions & 5 deletions src/util/deleteLastCharacterOutsideSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ export default function deleteLastCharacterOutsideSelection(html: string) {
}
}

// Gets length of the element's content.
const textLength = element.textContent!.length;
const range = document.createRange();
const selection = window.getSelection()!;

// Sets selection position to the end of the element.
range.setStart(element, textLength);
range.setEnd(element, textLength);
if (element.textContent === "") {
range.selectNode(element);
} else {
// Gets length of the element's content.
const textLength = element.textContent!.length;
// Sets selection position to the end of the element.
range.setStart(element, textLength);
range.setEnd(element, textLength);
}

selection.removeAllRanges();
selection.addRange(range);
document.execCommand('delete', false);
Expand Down