Skip to content

Commit 6568162

Browse files
committed
Fix formula bar bottom placement on iOS
1 parent b38aa50 commit 6568162

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Created by Jacob Strieb.
3-
October 2024 - January 2025
3+
Fall 2024 - Spring 2025
44
-->
55
<!doctype html>
66
<html lang="en">

src/App.svelte

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,19 @@
233233
window.visualViewport.addEventListener("resize", () => {
234234
visualBottom = window.visualViewport.height;
235235
});
236-
237-
function insertText(s) {
238-
return;
239-
}
236+
let showInputButtons = $derived(
237+
navigator.maxTouchPoints > 1 && Math.abs(innerHeight - visualBottom) > 5,
238+
);
239+
$effect(() => {
240+
// iOS scrolls the formula bar to the middle on focus, this counteracts that
241+
// (if it happens to run after the keyboard is up - inconsistent)
242+
if (showInputButtons) {
243+
window.scrollTo({
244+
top: 0,
245+
behavior: "instant",
246+
});
247+
}
248+
});
240249
</script>
241250
242251
{#snippet printKey(key)}
@@ -414,12 +423,10 @@
414423
>
415424
{/snippet}
416425
{#if navigator.maxTouchPoints > 1}
417-
<div
418-
class="keyboardbar"
419-
style:bottom="max(calc(2.75em + 1px), {innerHeight - visualBottom}px)"
420-
>
426+
<!-- Must set top instead of bottom for correct placement on iOS -->
427+
<div class="keyboardbar" style:top="calc({visualBottom}px - 2.5em * 2)">
421428
<FormulaBar bind:globals bind:editor={globals.elements.formulaBar} />
422-
{#if Math.abs(innerHeight - visualBottom) > 5}
429+
{#if showInputButtons}
423430
<div class="buttonbar">
424431
{@render insertTextButton("=")}
425432
{@render insertTextButton("(")}

src/FormulaBar.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</style>
4343

4444
<script>
45-
let { globals, editor = $bindable() } = $props();
45+
let { globals, editor = $bindable(), ...rest } = $props();
4646
let selection = $derived(globals.selected);
4747
let sheet = $derived(globals.currentSheet);
4848
@@ -137,5 +137,6 @@
137137
autocapitalization="none"
138138
autocomplete="off"
139139
spellcheck="false"
140+
{...rest}
140141
></textarea>
141142
</label>

0 commit comments

Comments
 (0)