Sha256: 3a1c7af020ed0ed4aa1a67b2ed7d3ef9ec0e0704809ec87acaa10d01746216ca

Contents?: true

Size: 1.94 KB

Versions: 26

Compression:

Stored size: 1.94 KB

Contents

'use strict';

require('../../utils/click/isClickableInput.js');
require('../../utils/dataTransfer/Clipboard.js');
var isContentEditable = require('../../utils/edit/isContentEditable.js');
require('../../utils/edit/isEditable.js');
require('../../utils/edit/maxLength.js');
var selection = require('../../utils/focus/selection.js');
require('../../utils/keyDef/readNextDescriptor.js');
require('../../utils/misc/level.js');
require('../../options.js');

/**
 * Reset the Document Selection when moving focus into an element
 * with own selection implementation.
 */ function updateSelectionOnFocus(element) {
    const selection$1 = element.ownerDocument.getSelection();
    /* istanbul ignore if */ if (!(selection$1 === null || selection$1 === void 0 ? void 0 : selection$1.focusNode)) {
        return;
    }
    // If the focus moves inside an element with own selection implementation,
    // the document selection will be this element.
    // But if the focused element is inside a contenteditable,
    // 1) a collapsed selection will be retained.
    // 2) other selections will be replaced by a cursor
    //  2.a) at the start of the first child if it is a text node
    //  2.b) at the start of the contenteditable.
    if (selection.hasOwnSelection(element)) {
        const contenteditable = isContentEditable.getContentEditable(selection$1.focusNode);
        if (contenteditable) {
            if (!selection$1.isCollapsed) {
                var _contenteditable_firstChild;
                const focusNode = ((_contenteditable_firstChild = contenteditable.firstChild) === null || _contenteditable_firstChild === void 0 ? void 0 : _contenteditable_firstChild.nodeType) === 3 ? contenteditable.firstChild : contenteditable;
                selection$1.setBaseAndExtent(focusNode, 0, focusNode, 0);
            }
        } else {
            selection$1.setBaseAndExtent(element, 0, element, 0);
        }
    }
}

exports.updateSelectionOnFocus = updateSelectionOnFocus;

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/@testing-library/user-event/dist/cjs/event/selection/updateSelectionOnFocus.js