UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

45 lines (43 loc) 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInlineCodeCursorSide = getInlineCodeCursorSide; var _marksSide = require("../marks-side"); /** * Given the marks on the left and right side of the current selection, and the stored * marks being updated during a transaction, this function returns the side (-1 = left, * 1 = right) for which node the mark boundary cursor decoration should be added * * This is intended to correct an issue where the default cursor does not render in the * expected location when navigating via arrow keys past the boundary of an inline code * node */ function getInlineCodeCursorSide(_ref) { var leftMarks = _ref.leftMarks, rightMarks = _ref.rightMarks, storedMarks = _ref.storedMarks; var isInlineCodeToLeft = leftMarks.some(function (mark) { return mark.type.name === 'code'; }); var isInlineCodeToRight = rightMarks.some(function (mark) { return mark.type.name === 'code'; }); var isInlineCodeBeingStored = !!storedMarks && (storedMarks === null || storedMarks === void 0 ? void 0 : storedMarks.some(function (mark) { return mark.type.name === 'code'; })); var isStoredMarksBeingCleared = !!storedMarks && storedMarks.length === 0; // This condition covers two scenarios: // a) When the cursor is on the left side of the inline code, and is expected to be // positioned within the inline code after pressing arrow right // b) When the cursor is on the right side of the inline code, and is expected to be // positioned outside of the inline code after pressing arrow right // in both of these cases the cursor needs to be corrected to be positioned inline // with the node to the right // NOTE: In editor-plugin-text-formatting there is logic on left/right key press // which dispatches a transaction to update the stored marks if (isInlineCodeToRight && isInlineCodeBeingStored || isInlineCodeToLeft && isStoredMarksBeingCleared) { return _marksSide.MarksSide.Right; } return _marksSide.MarksSide.None; }