-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathNodeSelectionMarkers.svelte
More file actions
64 lines (58 loc) · 2.24 KB
/
Copy pathNodeSelectionMarkers.svelte
File metadata and controls
64 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script lang="ts">
import { getContext } from 'svelte';
import { serialize_path } from './utils.js';
import type { DocumentPath, SveditContext } from './types.js';
const svedit = getContext<SveditContext>('svedit');
let selected_node_paths = $derived(get_selected_node_paths());
function get_selected_node_paths(): DocumentPath[] | undefined {
const paths: DocumentPath[] = [];
const selection = svedit.session.selection;
if (!selection) return;
if (selection.type !== 'node' || selection.anchor_offset === selection.focus_offset) return;
const start = Math.min(selection.anchor_offset, selection.focus_offset);
const end = Math.max(selection.anchor_offset, selection.focus_offset);
for (let index = start; index < end; index++) {
paths.push([...selection.path, index]);
}
return paths;
}
</script>
{#if svedit.session.selection?.type === 'property'}
<div
class="selected-property-overlay"
style="position-anchor: --{serialize_path(svedit.session.selection.path)};"
></div>
{/if}
{#if selected_node_paths}
{#each selected_node_paths as path (serialize_path(path))}
<div class="selected-node-overlay" style="position-anchor: --{serialize_path(path)};"></div>
{/each}
{/if}
<style>
.selected-node-overlay,
.selected-property-overlay {
/* Selection frame: a single 1px outline, offset -0.5px so the
hairline centers on the node's edge and neighboring frames merge
into one shared line. Alternatives tried and rejected:
- Plain 1px border: adjacent selected nodes stack their borders
into a 2px seam between them, which looks ugly.
- Thick translucent frame (8px border) plus an inner hairline
outline: multiple nested lines take more cognitive effort to
parse than a single line.
- Inset box-shadow rings (1px stroke + 8px translucent): same
layered-frame look, same objection.
Performance note: outlines don't participate in layout, so
selection changes can't trigger reflows. */
position: absolute;
background: var(--svedit-editing-fill);
outline: 1px solid var(--svedit-editing-stroke);
outline-offset: -0.5px;
border-radius: 1px;
top: anchor(top);
left: anchor(left);
bottom: anchor(bottom);
right: anchor(right);
pointer-events: none;
z-index: 12;
}
</style>