Skip to content

Commit d0c8399

Browse files
author
Zaydek Michels-Gualtieri
committed
2 parents cff0113 + 6b04457 commit d0c8399

File tree

2 files changed

+5
-87
lines changed

2 files changed

+5
-87
lines changed

src/Editor/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const Editor = ({
283283
dedupedFirefoxCompositionEnd.current = true
284284

285285
const data = readCurrentDocumentNode(state)
286-
const [pos1] = readCurrentPos(state)
286+
let [pos1] = readCurrentPos(state)
287287

288288
// COMPAT (FF): Backspace during a composition
289289
// event can create an empty text node; **REMOVE

src/Editor/useEditor.js

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import * as ascii from "lib/encoding/ascii"
1+
import * as emojiTrie from "emoji-trie"
22
import * as posIterators from "./posIterators"
33
import LRUCache from "lib/LRUCache"
44
import parseElements from "./parser/parseElements"
5-
import parseInlineElements from "./parser/parseInlineElements"
65
import UndoManager from "lib/UndoManager"
76
import useMethods from "use-methods"
87
import uuidv4 from "uuid/v4"
@@ -370,100 +369,19 @@ const methods = state => ({
370369
const range = selection.getRangeAt(0)
371370
rerenderNeeded = (
372371
(range.startContainer.nodeType === Node.TEXT_NODE && range.startOffset <= 1) ||
373-
// TODO: Add data-codex-rerender?
374372
ascendToElement(range.startContainer).getAttribute("data-codex-markdown") ||
375-
ascendToElement(range.startContainer).getAttribute("aria-label")
373+
(range.startContainer.nodeType === Node.TEXT_NODE && emojiTrie.atEnd(range.startContainer.nodeValue))
376374
)
377375
const root = ascendToElement(range.startContainer).closest("[data-codex-editor] > *")
378376
id = root.id || root.querySelector("[id]").id
379377
}
380-
381-
// if (rerenderNeeded) {
378+
if (rerenderNeeded) {
382379
const nextElement = nextElements.find(each => each.id === id)
383380
if (nextElement) {
384381
nextElement.reactKey = uuidv4().slice(0, 8)
385382
}
386-
// }
387-
388-
// const elements = parseInlineElements(state.nodes[state.pos1.y].data)
389-
// console.log(elements)
383+
}
390384

391-
// // Compares whether two children are equal. Character
392-
// // data is not compared in order to preserve
393-
// // spellcheck highlighting.
394-
// const isString = value => {
395-
// return typeof value === "string"
396-
// }
397-
// const isObject = value => {
398-
// const ok = (
399-
// typeof value === "object" &&
400-
// !Array.isArray(value)
401-
// )
402-
// return ok
403-
// }
404-
// const isArray = value => {
405-
// const ok = (
406-
// typeof value === "object" &&
407-
// Array.isArray(value)
408-
// )
409-
// return ok
410-
// }
411-
// const areEqualChildren = (childrenA, childrenB) => {
412-
// if (childrenA === null || childrenB === null) {
413-
// return childrenA === childrenB
414-
// }
415-
// if (isString(childrenA) && isString(childrenB)) {
416-
// return true
417-
// } else if (isObject(childrenA) && isObject(childrenB)) {
418-
// const ok = (
419-
// childrenA.type === childrenB.type &&
420-
// JSON.stringify(childrenA.syntax) === JSON.stringify(childrenB.syntax) &&
421-
// areEqualChildren(childrenA.children, childrenB.children)
422-
// )
423-
// return ok
424-
// }
425-
// if (!isArray(childrenA) || !isArray(childrenB) || childrenA.length !== childrenB.length) {
426-
// return false
427-
// }
428-
// for (let x = 0; x < childrenA.length; x++) {
429-
// if (!areEqualChildren(childrenA[x], childrenB[x])) {
430-
// return false
431-
// }
432-
// }
433-
// return true
434-
// }
435-
// // Compares whether two elements are equal. Elements
436-
// // are considered to be equal if their types, ID, and
437-
// // children are equal.
438-
// const areEqualElements = (elementA, elementB) => {
439-
// const ok = (
440-
// elementA.type === elementB.type &&
441-
// elementA.id === elementB.id &&
442-
// JSON.stringify(elementA.syntax) === JSON.stringify(elementB.syntax) &&
443-
// areEqualChildren(elementA.children, elementB.children)
444-
// )
445-
// return ok
446-
// }
447-
// let id = ""
448-
// const selection = document.getSelection()
449-
// if (selection.rangeCount) {
450-
// const range = selection.getRangeAt(0)
451-
// const root = ascendToElement(range.startContainer).closest("[data-codex-editor] > *")
452-
// id = root.id || root.querySelector("[id]").id
453-
// }
454-
// const substr = state.nodes[state.pos1.y].data.slice(state.pos1.x - 2, state.pos1.x + 1)
455-
// const mustRerender = false // substr
456-
// // .split("")
457-
// // .some(each => ascii.isPunctuation(each))
458-
// const prevElement = state.elements.find(each => each.id === id)
459-
// const nextElement = nextElements.find(each => each.id === id)
460-
// if (prevElement && nextElement) {
461-
// if (areEqualElements(prevElement, nextElement)) {
462-
// // No-op
463-
// return
464-
// }
465-
// nextElement.reactKey = uuidv4().slice(0, 8)
466-
// }
467385
}
468386

469387
Object.assign(state, {

0 commit comments

Comments
 (0)