Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Apr 12, 2018
1 parent 36d29f7 commit e4b538a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/client/core/utils/content-editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,23 @@ function getElementOffset (target) {
return firstBreakElement ? offset : 0;
}

function isNodeSelectable (node, includeDescendants = false) {
function isNodeSelectable (node, includeDescendants) {
if (styleUtils.isNotVisibleNode(node))
return false;

if (domUtils.isTextNode(node))
return true;

if (!domUtils.isElementNode(node))
return false;

const visibleChildren = getVisibleChildren(node);
if (hasSelectableChildren(node))
return includeDescendants;

const isContentEditableRoot = !domUtils.isContentEditableElement(node.parentNode);
const selectableChildren = arrayUtils.filter(visibleChildren, child => isNodeSelectable(child));
const visibleChildren = getVisibleChildren(node);
const hasBreakLineElements = arrayUtils.some(visibleChildren, child => domUtils.getTagName(child) === 'br');

if (selectableChildren.length)
return includeDescendants;

return isContentEditableRoot || hasBreakLineElements;
}

Expand Down Expand Up @@ -439,7 +441,7 @@ export function calculateNodeAndOffsetByPosition (el, offset) {
if (!isVisibleNode(target))
return point;

if (point.offset === 0 && isNodeSelectable(target)) {
if (point.offset === 0 && isNodeSelectable(target, false)) {
point.node = target;
point.offset = getElementOffset(target);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Selector } from 'testcafe';

fixture `GH-2205 - Should type in div if it has an invisible child with contententeditable=false`
.page `http://localhost:3000/fixtures/regression/gh-2205/pages/index.html`;
.page `../pages/index.html`;

async function typeAndCheck (t, editorId) {
const editor = Selector(editorId);
Expand Down

0 comments on commit e4b538a

Please sign in to comment.