Skip to content

Commit 3aaa193

Browse files
committed
Adjust percentage calculation
1 parent 0057b64 commit 3aaa193

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/components/repl.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,28 @@ export const Repl: Component<ReplProps> = (props) => {
205205
* Upcomming 2 blocks before the slice of view is used for horizontal and vertical resizers.
206206
* This first block controls the horizontal resizer.
207207
*/
208+
const adjustPercentage = (percentage: number, lowerBound: number, upperBound: number) => {
209+
if (percentage < lowerBound) {
210+
return lowerBound;
211+
} else if (percentage > upperBound) {
212+
return upperBound;
213+
} else {
214+
return percentage;
215+
}
216+
};
217+
208218
const [horizontalResizer, setHorizontalResizer] = createSignal<HTMLElement>();
209219
const [left, setLeft] = createSignal(1.25);
210220

211221
const changeLeft = (clientX: number, _clientY: number) => {
212222
// Adjust the reading according to the width of the resizable panes
213223
const clientXAdjusted = clientX - horizontalResizer()!.offsetWidth / 2;
214224
const widthAdjusted = document.body.offsetWidth - horizontalResizer()!.offsetWidth;
225+
215226
const percentage = clientXAdjusted / (widthAdjusted / 2);
216-
if (percentage < 0.5 || percentage > 1.5) return;
227+
const percentageAdjusted = adjustPercentage(percentage, 0.5, 1.5);
217228

218-
setLeft(percentage);
229+
setLeft(percentageAdjusted);
219230
};
220231

221232
/**
@@ -240,9 +251,9 @@ export const Repl: Component<ReplProps> = (props) => {
240251
resultTabs()!.offsetHeight;
241252

242253
const percentage = clientYAdjusted / (heightAdjusted / 2);
243-
if (percentage < 0.5 || percentage > 1.5) return;
254+
const percentageAdjusted = adjustPercentage(percentage, 0.5, 1.5);
244255

245-
setTop(percentage);
256+
setTop(percentageAdjusted);
246257
};
247258

248259
return (

0 commit comments

Comments
 (0)