|
1 | | -import * as ascii from "lib/encoding/ascii" |
| 1 | +import * as emojiTrie from "emoji-trie" |
2 | 2 | import * as posIterators from "./posIterators" |
3 | 3 | import LRUCache from "lib/LRUCache" |
4 | 4 | import parseElements from "./parser/parseElements" |
5 | | -import parseInlineElements from "./parser/parseInlineElements" |
6 | 5 | import UndoManager from "lib/UndoManager" |
7 | 6 | import useMethods from "use-methods" |
8 | 7 | import uuidv4 from "uuid/v4" |
@@ -370,100 +369,19 @@ const methods = state => ({ |
370 | 369 | const range = selection.getRangeAt(0) |
371 | 370 | rerenderNeeded = ( |
372 | 371 | (range.startContainer.nodeType === Node.TEXT_NODE && range.startOffset <= 1) || |
373 | | - // TODO: Add data-codex-rerender? |
374 | 372 | 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)) |
376 | 374 | ) |
377 | 375 | const root = ascendToElement(range.startContainer).closest("[data-codex-editor] > *") |
378 | 376 | id = root.id || root.querySelector("[id]").id |
379 | 377 | } |
380 | | - |
381 | | - // if (rerenderNeeded) { |
| 378 | + if (rerenderNeeded) { |
382 | 379 | const nextElement = nextElements.find(each => each.id === id) |
383 | 380 | if (nextElement) { |
384 | 381 | nextElement.reactKey = uuidv4().slice(0, 8) |
385 | 382 | } |
386 | | - // } |
387 | | - |
388 | | - // const elements = parseInlineElements(state.nodes[state.pos1.y].data) |
389 | | - // console.log(elements) |
| 383 | + } |
390 | 384 |
|
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 | | - // } |
467 | 385 | } |
468 | 386 |
|
469 | 387 | Object.assign(state, { |
|
0 commit comments