Skip to content

Commit 2a4acaa

Browse files
committed
Check the selection and boundaries and throw an exception by invalid values
1 parent 23379aa commit 2a4acaa

File tree

2 files changed

+6
-6
lines changed
  • ts/WoltLabSuite/Core/Component/Quote
  • wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote

2 files changed

+6
-6
lines changed

ts/WoltLabSuite/Core/Component/Quote/Message.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ function removeSelection(): void {
500500
}
501501

502502
function alignQuoteButtons(content: HTMLElement): void {
503-
const coordinates = getElementBoundaries(window.getSelection())!;
503+
const coordinates = getElementBoundaries(window.getSelection());
504504
const dimensions = { height: copyQuote.offsetHeight, width: copyQuote.offsetWidth };
505505
let left = (coordinates.right - coordinates.left) / 2 - dimensions.width / 2 + coordinates.left;
506506

@@ -516,13 +516,13 @@ function alignQuoteButtons(content: HTMLElement): void {
516516
copyQuote.style.setProperty("left", `${left}px`);
517517
}
518518

519-
function getElementBoundaries(selection: Selection | null): ElementBoundaries | null {
519+
function getElementBoundaries(selection: Selection | null): ElementBoundaries {
520520
if (!selection) {
521-
return null;
521+
throw new Error("Nothing is selected");
522522
}
523523

524524
if (selection.rangeCount <= 0) {
525-
return null;
525+
throw new Error("Selection has no range");
526526
}
527527

528528
// The coordinates returned by getBoundingClientRect() are relative to the

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Quote/Message.js

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

0 commit comments

Comments
 (0)