Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add Selection/Range methods based on anchestor element

Abierto
#102 13 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
html
Área
web-dev

Línea de trabajo

Start by reading the suggested Selection and Window IDL interfaces and the requirements for contextElement, character offsets, and innerText-style line breaks. Determine the intended API behavior, error cases, and AddRange integration before implementation; done requires an agreed specification and corresponding tests.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

NewAPI

Add function prototypes for getting/setting anchorNode/anchorOffset and focusNode/focusOffset as character offsets based on a given anchestor node.

The suggested functionality is necessary to track and regain a selection in an editing host when DOM manipulation takes place.


Suggested IDL Interfaces
partial interface Selection {
  [Throws]
  Range? getRangeAt(unsigned long index, Element contextElement);
};


partial interface Window {
  [Throws] Selection? getSelection(Element contextElement);
};

Details
1.
const selObj = window.getSelection(contextElement: HTMLElement);

Should yield:

selObj.anchorNode === selObj.focusNode === contextElement;

selObj.anchorOffset = AnchorCharacterOffsetFromContextElement(contextElement);
selObj.focusOffset = FocusCharacterOffsetFromContextElement(contextElement);

2.
const rngObj = window.getSelection().getRangeAt(index: number, contextElement: HTMLElement);

Should yield:

rngObj.commonAncestorContainer === rngObj.startContainer === rngObj.endContainer === contextElement;

rngObj.startOffset = AnchorCharacterOffsetFromContextElement(contextElement);
rngObj.endOffset = FocusCharacterOffsetFromContextElement(contextElement);

Both suggested functions are supposed to either throw an ReferenceError or yield void 0 when contextElement is not an anchestor of both, selObj.anchorNode/selObj.focusNode and rngObj.startOffset/rngObj.endOffset, resp.

selObj.AddRange() should take above Range object, recognize that it is based on a context element and put the cursor selection according to the character offsets given in a Range object; based on contextElement.

Character count should mimic the behaviour of the Element.innerText property, i.e. considering <br/> elements, <p> elements and block elements following inline elements as new-line characters (= \n).

Lenguaje dominante
HTML
Estrellas
49
Forks
30
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de w3c/selection-api

Todos los issues de w3c/selection-api

Issues similares

Más issues de Web Dev

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.