Expose text selection bounds as CSS anchors

Aperta
#299 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
css, typescript
Ambito
frontend

Direzione di ricerca

Inizia individuando il punto di ingresso del rendering delle selezioni di Svedit e il percorso DOM esistente per le annotazioni descritto nell’issue. Aggiungi marcatori di confine per le selezioni attive senza racchiudere il contenuto selezionato, stabilisci se compaiono solo quando il contenuto è modificabile oppure anche in modalità visualizzazione e verifica che gli ancoraggi generati supportino il caso d’uso di posizionamento CSS mostrato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

Annotation overlays like LinkTool need to position themselves relative to the current text selection. Today, every consumer has to build this measurement logic themselves — even though Svedit already knows the selection range.

Proposal

When there is an active text selection, render two zero-width <span> elements at the selection boundaries, each carrying a CSS anchor-name:

text before the selection
<span class="text-selection-start" style="anchor-name: --text-selection-start"></span>
some <strong>text</strong> that is <em>selected</em>
<span class="text-selection-end" style="anchor-name: --text-selection-end"></span>
more text after the selection

Two separate point markers (rather than one span wrapping the selected text) is the only shape that composes with the existing annotation DOM: a selection routinely spans across multiple annotation spans (bold, link, etc.), and Svedit's data model doesn't allow overlapping annotations — so a single wrapper would have to fragment itself across them or produce an invalid nesting. Point anchors slot in cleanly as siblings at the boundaries regardless of what's between them.

Benefit

Any overlay component can position itself declaratively against the selection using CSS anchor positioning — no getBoundingClientRect, no selection-change listeners, no manual math:

.link-tool {
  position: absolute;
  position-anchor: --text-selection-start;
  top: anchor(bottom);
  left: anchor(left);
}

A recurring per-consumer concern moves down into the framework, where the selection model already lives.


Questions:
  • only when editable is true? or also in view mode?

@michael what do you think? Happy to turn this into a PR

Lingua principale
TypeScript
Stelle
691
Fork
20
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di michael/svedit

Tutte le issue di michael/svedit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.