Re: [w3c/editing] Update spec draft, explainer, examples for EditContext (PR #355)

@travisleithead requested changes on this pull request.

Just a few minor changes. Looks excellent. Great update!

> +        }
+
+        updateTextFormats(textFormats) {
+            this.textFormats = textFormats
+        }
+    }
+
+    class EditingView {
+        render() {
+            // render the text (implementation omitted for brevity)
+
+            // render the selection (implementation omitted for brevity)
+
+            // render the IME decoration
+            this.model.textFormats.forEach( textFormat => {
+                let lineStartX = anchorX + textFormat.rangeStart * charWidth;

A few of these variables are used, but not defined. Might be good to note what they are in comments? (I understand that this is example code and that these variables are largely self-explanatory...)

> +            this.editContext.updateCharacterBounds(rangeStart, characterBounds);
+        }
+    }
+
+    // When user typing, EditContext will receive textupdate events,
+    // which can be used to update the editor's model.
+    editContext.addEventListener("textupdate", e => {
+        editingController.handleTextUpdate(e.updateRangeStart, e.updateRangeEnd, e.updatetext,
+                                        e.newSelectionStart, e.newSelectionEnd,
+                                        e.compositionStart, e.compositionEnd)
+    });
+
+    // EditContext will also receive textformatupdate event for IME decoration.
+    // Ex. thin/thick underline for the "phrase mode" in Japanese IME.
+    editContext.addEventListener("textformatupdate", e => {
+        editingcontroller.updateTextFormatsUpdate(e.getTextFormats());

```suggestion
        editingcontroller.handleTextFormatUpdate(e.getTextFormats());
```

> +        computeControlBound() { 
+            // implementation omitted for brevity 
+        } 
+
+        computeCharacterBounds(rangeStart, rangeEnd) {
+            // implementation omitted for brevity
+        }
+    }
+
+    class EditingController {
+        handleSelectionChange() {
+            // Authors are responsible to map the selection from the DOM space to the
+            // plain text space. One approach is to use range.toString() to get the plain text
+            // before the selection start/end, and use the text length as the selection index.
+            let s = document.getSelection()
+            let range = document.createRange()

```suggestion
            let range = new Range()
```

> +        }
+
+        updateTextFormats(textFormats) {
+            this.textFormats = textFormats
+        }
+    }
+
+    class EditingView {
+        render() {
+            // render the text (implementation omitted for brevity)
+
+            // render the selection (implementation omitted for brevity)
+
+            // render the IME decoration
+            this.model.textFormats.forEach( textFormat => {
+                let lineStartX = anchorX + textFormat.rangeStart * charWidth;

e.g., `anchorX`, `charWidth`, `thickWidth`, `lineY`...

> +        computeControlBound() { 
+            // implementation omitted for brevity 
+        } 
+
+        computeCharacterBounds(rangeStart, rangeEnd) {
+            // implementation omitted for brevity
+        }
+    }
+
+    class EditingController {
+        handleSelectionChange() {
+            // Authors are responsible to map the selection from the DOM space to the
+            // plain text space. One approach is to use range.toString() to get the plain text
+            // before the selection start/end, and use the text length as the selection index.
+            let s = document.getSelection()
+            let range = document.createRange()

(Just a more modern approach...)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/editing/pull/355#pullrequestreview-788666993

Received on Monday, 25 October 2021 22:15:21 UTC