Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Add Selection/Range methods based on anchestor element

Đang mở
#102 13 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
html
Lĩnh vực
web-dev

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
HTML
Star
49
Fork
30
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của w3c/selection-api

Tất cả issue của w3c/selection-api

Issue tương tự

Thêm issue về Web Dev

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.