Skip to content

Commit b5b97f1

Browse files
committed
Show latest window or context menu on top
Update a global "latest z-index" every time a dialog or context menu pops up to guarantee it is on top, and allow changing the z-order (while implicitly maintaining the order of the stack of previous ones). @lsnow99 came up with the good idea to have the value come from a function that closes over a variable and increments it after returning.
1 parent 091e15a commit b5b97f1

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/App.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
gap: 0.5ch;
5151
overflow-x: auto;
5252
background-color: var(--bg-color);
53-
z-index: 19;
5453
}
5554
5655
.bottombar {
@@ -117,7 +116,7 @@
117116
import { State, Sheet } from "./classes.svelte.js";
118117
import { compressText } from "./compress.js";
119118
import { evalDebounced, functions } from "./formula-functions.svelte.js";
120-
import { debounce, replaceValues } from "./helpers.js";
119+
import { debounce, replaceValues, nextZIndex } from "./helpers.js";
121120
import { actions, keyboardHandler, keybindings } from "./keyboard.js";
122121
123122
let { urlData } = $props();
@@ -292,6 +291,7 @@
292291
bind:innerHeight
293292
/>
294293
294+
<!-- TODO: Better heuristic that doesn't trigger on touchscreen laptops -->
295295
{#if navigator.maxTouchPoints <= 1}
296296
<!-- Else float the bar above the virtual keyboard -->
297297
<div>
@@ -442,7 +442,7 @@
442442
<div class="keyboardbar" style:top="calc({visualBottom}px - 2.5em * 2)">
443443
<FormulaBar bind:globals bind:editor={globals.elements.formulaBar} />
444444
{#if showInputButtons}
445-
<div class="buttonbar">
445+
<div class="buttonbar" style:z-index={nextZIndex()}>
446446
{@render insertTextButton("=")}
447447
{@render insertTextButton("(")}
448448
{@render insertTextButton(")")}
@@ -471,6 +471,7 @@
471471
<div
472472
class="startmenu"
473473
bind:offsetHeight={startHeight}
474+
style:z-index={nextZIndex()}
474475
style:--height="{startHeight}px"
475476
>
476477
{@render builder([

src/ContextMenu.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<style>
3838
.menu {
3939
position: absolute;
40-
z-index: 20;
4140
background: none;
4241
/* TODO: Keep? Adjust? */
4342
width: 300px;
@@ -47,7 +46,7 @@
4746

4847
<script>
4948
import ShyMenu from "./ShyMenu.svelte";
50-
49+
import { nextZIndex } from "./helpers.js";
5150
import { tick } from "svelte";
5251
5352
const {
@@ -93,6 +92,7 @@
9392
class="menu"
9493
style:left="{menuX}px"
9594
style:top="{menuY}px"
95+
style:z-index={nextZIndex()}
9696
bind:offsetWidth={menuWidth}
9797
bind:offsetHeight={menuHeight}
9898
>

src/Dialog.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
<script>
8787
import Button from "./Button.svelte";
88-
import { randomId } from "./helpers.js";
88+
import { randomId, nextZIndex } from "./helpers.js";
8989
9090
const minDimension = Math.min(window.innerWidth, window.innerHeight);
9191
@@ -102,6 +102,13 @@
102102
let pointerStart = $state();
103103
let dragging = $state(false);
104104
105+
let zindex = $state(nextZIndex());
106+
$effect(() => {
107+
if (open) {
108+
zindex = nextZIndex();
109+
}
110+
});
111+
105112
// If the dots pattern is redeclared (when there are multiple <Dialog>
106113
// components, for example), and the first one is inside of a `display:
107114
// none` element, then they will not render. Giving each a unique ID
@@ -168,6 +175,8 @@
168175
style:left="max(0px, {left}px)"
169176
style:--width="min(calc(100% - {left}px), {width}px)"
170177
style:--height="min(calc(100% - {top}px), {height}px)"
178+
style:z-index={zindex}
179+
onpointerdown={() => (zindex = nextZIndex())}
171180
>
172181
<div class="top">
173182
<svg class="drag" onpointerdown={topPointerDown} onpointerup={topPointerUp}>

src/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ export function replaceValues(k, v) {
7474
// TODO: Do other things to make the data URL smaller
7575
return v;
7676
}
77+
78+
let nextIndex = 10;
79+
export function nextZIndex(increment = 1) {
80+
const result = nextIndex;
81+
nextIndex += increment;
82+
return result;
83+
}

0 commit comments

Comments
 (0)