Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Draft.js - Stop links after pasting at end of block
Browse files Browse the repository at this point in the history
Summary: Currently in Draft when you paste a linkt the link continues and you have to manually unset it.

Reviewed By: sophiebits

Differential Revision: D5273910

fbshipit-source-id: 7fcda63f542a538692d016eb49395bb27fad73c9
  • Loading branch information
Ian Jones authored and facebook-github-bot committed Nov 20, 2017
1 parent 19fb3e7 commit d16833b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`must not return key if immutable 1`] = `null`;

exports[`must not return key if immutable with collapsed selection 1`] = `null`;

exports[`must not return key if mutable with collapsed selection at end of an entity 1`] = `null`;

exports[`must not return key if segmented 1`] = `null`;

exports[`must not return key if segmented with collapsed selection 1`] = `null`;
Expand Down
14 changes: 14 additions & 0 deletions src/model/entity/__tests__/getEntityKeyForSelection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const COLLAPSED_SELECTION = initialSelectionState.merge({
focusOffset: 2,
});

const COLLAPSED_SELECTION_ENTITY_END = initialSelectionState.merge({
anchorOffset: 5,
focusOffset: 5,
});

const NON_COLLAPSED_SELECTION = initialSelectionState.merge({
anchorOffset: 2,
focusKey: 'c',
Expand All @@ -50,6 +55,15 @@ test('must return key if mutable with collapsed selection', () => {
expect(key).toMatchSnapshot();
});

test('must not return key if mutable with collapsed selection at end of an entity', () => {
setEntityMutability('MUTABLE');
const key = getEntityKeyForSelection(
contentState,
COLLAPSED_SELECTION_ENTITY_END,
);
expect(key).toMatchSnapshot();
});

test('must not return key if immutable with collapsed selection', () => {
setEntityMutability('IMMUTABLE');
const key = getEntityKeyForSelection(contentState, COLLAPSED_SELECTION);
Expand Down
3 changes: 3 additions & 0 deletions src/model/entity/getEntityKeyForSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function getEntityKeyForSelection(
var offset = targetSelection.getAnchorOffset();
if (offset > 0) {
entityKey = contentState.getBlockForKey(key).getEntityAt(offset - 1);
if (entityKey !== contentState.getBlockForKey(key).getEntityAt(offset)) {
return null;
}
return filterKey(contentState.getEntityMap(), entityKey);
}
return null;
Expand Down

0 comments on commit d16833b

Please sign in to comment.