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

Commit 594a14f

Browse files
mrkevfacebook-github-bot
authored andcommitted
Flowify editOnInput.js
Summary: Involved fixing two sketchy null checks. Nothing huge. NOTE: There's lots of non flow-strict code that makes checks on keys. Empty string is an invalid key. This is the behavior right now, so I left it unchanged. I extracted it to another module because I'll be using it to check the existence of keys in other parts of the code too. Reviewed By: kedromelon Differential Revision: D16595680 fbshipit-source-id: 13a08e3b2477ba46ba2a2c66089afe47edccb20a
1 parent 6972278 commit 594a14f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/component/handlers/edit/editOnInput.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8-
* @flow
8+
* @flow strict-local
99
* @emails oncall+draft_js
1010
*/
1111

@@ -18,6 +18,7 @@ const DraftOffsetKey = require('DraftOffsetKey');
1818
const EditorState = require('EditorState');
1919
const UserAgent = require('UserAgent');
2020

21+
const {notEmptyKey} = require('draftKeyUtils');
2122
const findAncestorOffsetKey = require('findAncestorOffsetKey');
2223
const gkx = require('gkx');
2324
const keyCommandPlainBackspace = require('keyCommandPlainBackspace');
@@ -158,8 +159,8 @@ function editOnInput(editor: DraftEditor, e: SyntheticInputEvent<>): void {
158159
});
159160

160161
const entityKey = block.getEntityAt(start);
161-
const entity = entityKey && content.getEntity(entityKey);
162-
const entityType = entity && entity.getMutability();
162+
const entity = notEmptyKey(entityKey) ? content.getEntity(entityKey) : null;
163+
const entityType = entity != null ? entity.getMutability() : null;
163164
const preserveEntity = entityType === 'MUTABLE';
164165

165166
// Immutable or segmented entities cannot properly be handled by the

src/component/utils/draftKeyUtils.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* Provides utilities for handling draftjs keys.
8+
*
9+
* @emails oncall+draft_js
10+
* @flow strict-local
11+
* @format
12+
*/
13+
14+
'use strict';
15+
16+
function notEmptyKey(key: ?string): boolean %checks {
17+
return key != null && key != '';
18+
}
19+
20+
module.exports = {
21+
notEmptyKey,
22+
};

0 commit comments

Comments
 (0)