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

Commit

Permalink
Change remaining vars to let/const
Browse files Browse the repository at this point in the history
Summary: `var` was triggering my OCD while reading these files, so went through and fixed all remaining ones in Draft.js, also added Prettier to a couple of files that raised lint errors.

Reviewed By: flarnie

Differential Revision: D7803975

fbshipit-source-id: 2642f3801c096ef5e8a3952d7b13c672f68b15b6
  • Loading branch information
niveditc authored and facebook-github-bot committed Apr 29, 2018
1 parent 3e9ff8e commit 8de2db9
Show file tree
Hide file tree
Showing 85 changed files with 734 additions and 727 deletions.
6 changes: 3 additions & 3 deletions src/component/contents/DraftEditorLeaf.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import type {DraftInlineStyle} from 'DraftInlineStyle';
import type SelectionState from 'SelectionState';

const DraftEditorTextNode = require('DraftEditorTextNode.react');
var React = require('React');
var ReactDOM = require('ReactDOM');
const React = require('React');
const ReactDOM = require('ReactDOM');

const invariant = require('invariant');
var setDraftEditorSelection = require('setDraftEditorSelection');
const setDraftEditorSelection = require('setDraftEditorSelection');

type Props = {
// The block that contains this leaf.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let resolved = false;
let stillComposing = false;
let textInputData = '';

var DraftEditorCompositionHandler = {
const DraftEditorCompositionHandler = {
onBeforeInput: function(editor: DraftEditor, e: SyntheticInputEvent<>): void {
textInputData = (textInputData || '') + e.data;
},
Expand Down
4 changes: 2 additions & 2 deletions src/component/handlers/drag/DraftEditorDragHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function getSelectionForEvent(
* found when Flow v0.68 was deployed. To see the error delete this comment
* and run Flow. */
if (typeof document.caretRangeFromPoint === 'function') {
var dropRange = document.caretRangeFromPoint(event.x, event.y);
const dropRange = document.caretRangeFromPoint(event.x, event.y);
node = dropRange.startContainer;
offset = dropRange.startOffset;
} else if (event.rangeParent) {
Expand All @@ -62,7 +62,7 @@ function getSelectionForEvent(
);
}

var DraftEditorDragHandler = {
const DraftEditorDragHandler = {
/**
* Drag originating from input terminated.
*/
Expand Down
26 changes: 13 additions & 13 deletions src/component/handlers/edit/commands/SecondaryClipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
import type {BlockMap} from 'BlockMap';
import type SelectionState from 'SelectionState';

var DraftModifier = require('DraftModifier');
var EditorState = require('EditorState');
const DraftModifier = require('DraftModifier');
const EditorState = require('EditorState');

var getContentStateFragment = require('getContentStateFragment');
var nullthrows = require('nullthrows');
const getContentStateFragment = require('getContentStateFragment');
const nullthrows = require('nullthrows');

var clipboard: ?BlockMap = null;
let clipboard: ?BlockMap = null;

/**
* Some systems offer a "secondary" clipboard to allow quick internal cut
* and paste behavior. For instance, Ctrl+K (cut) and Ctrl+Y (paste).
*/
var SecondaryClipboard = {
const SecondaryClipboard = {
cut: function(editorState: EditorState): EditorState {
var content = editorState.getCurrentContent();
var selection = editorState.getSelection();
var targetRange: ?SelectionState = null;
const content = editorState.getCurrentContent();
const selection = editorState.getSelection();
let targetRange: ?SelectionState = null;

if (selection.isCollapsed()) {
var anchorKey = selection.getAnchorKey();
var blockEnd = content.getBlockForKey(anchorKey).getLength();
const anchorKey = selection.getAnchorKey();
const blockEnd = content.getBlockForKey(anchorKey).getLength();

if (blockEnd === selection.getAnchorOffset()) {
return editorState;
Expand All @@ -49,7 +49,7 @@ var SecondaryClipboard = {
targetRange = nullthrows(targetRange);
clipboard = getContentStateFragment(content, targetRange);

var afterRemoval = DraftModifier.removeRange(
const afterRemoval = DraftModifier.removeRange(
content,
targetRange,
'forward',
Expand All @@ -67,7 +67,7 @@ var SecondaryClipboard = {
return editorState;
}

var newContent = DraftModifier.replaceWithFragment(
const newContent = DraftModifier.replaceWithFragment(
editorState.getCurrentContent(),
editorState.getSelection(),
clipboard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@

'use strict';

var EditorState = require('EditorState');
const EditorState = require('EditorState');

var expandRangeToStartOfLine = require('expandRangeToStartOfLine');
var getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes');
var moveSelectionBackward = require('moveSelectionBackward');
var removeTextWithStrategy = require('removeTextWithStrategy');
const expandRangeToStartOfLine = require('expandRangeToStartOfLine');
const getDraftEditorSelectionWithNodes = require('getDraftEditorSelectionWithNodes');
const moveSelectionBackward = require('moveSelectionBackward');
const removeTextWithStrategy = require('removeTextWithStrategy');

function keyCommandBackspaceToStartOfLine(
editorState: EditorState,
): EditorState {
var afterRemoval = removeTextWithStrategy(
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
const selection = strategyState.getSelection();
if (selection.isCollapsed() && selection.getAnchorOffset() === 0) {
return moveSelectionBackward(strategyState, 1);
}

var domSelection = global.getSelection();
var range = domSelection.getRangeAt(0);
const domSelection = global.getSelection();
let range = domSelection.getRangeAt(0);
range = expandRangeToStartOfLine(range);

return getDraftEditorSelectionWithNodes(
Expand Down
22 changes: 11 additions & 11 deletions src/component/handlers/edit/commands/keyCommandBackspaceWord.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@

'use strict';

var DraftRemovableWord = require('DraftRemovableWord');
var EditorState = require('EditorState');
const DraftRemovableWord = require('DraftRemovableWord');
const EditorState = require('EditorState');

var moveSelectionBackward = require('moveSelectionBackward');
var removeTextWithStrategy = require('removeTextWithStrategy');
const moveSelectionBackward = require('moveSelectionBackward');
const removeTextWithStrategy = require('removeTextWithStrategy');

/**
* Delete the word that is left of the cursor, as well as any spaces or
* punctuation after the word.
*/
function keyCommandBackspaceWord(editorState: EditorState): EditorState {
var afterRemoval = removeTextWithStrategy(
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
var selection = strategyState.getSelection();
var offset = selection.getStartOffset();
const selection = strategyState.getSelection();
const offset = selection.getStartOffset();
// If there are no words before the cursor, remove the preceding newline.
if (offset === 0) {
return moveSelectionBackward(strategyState, 1);
}
var key = selection.getStartKey();
var content = strategyState.getCurrentContent();
var text = content
const key = selection.getStartKey();
const content = strategyState.getCurrentContent();
const text = content
.getBlockForKey(key)
.getText()
.slice(0, offset);
var toRemove = DraftRemovableWord.getBackward(text);
const toRemove = DraftRemovableWord.getBackward(text);
return moveSelectionBackward(strategyState, toRemove.length || 1);
},
'backward',
Expand Down
22 changes: 11 additions & 11 deletions src/component/handlers/edit/commands/keyCommandDeleteWord.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@

'use strict';

var DraftRemovableWord = require('DraftRemovableWord');
var EditorState = require('EditorState');
const DraftRemovableWord = require('DraftRemovableWord');
const EditorState = require('EditorState');

var moveSelectionForward = require('moveSelectionForward');
var removeTextWithStrategy = require('removeTextWithStrategy');
const moveSelectionForward = require('moveSelectionForward');
const removeTextWithStrategy = require('removeTextWithStrategy');

/**
* Delete the word that is right of the cursor, as well as any spaces or
* punctuation before the word.
*/
function keyCommandDeleteWord(editorState: EditorState): EditorState {
var afterRemoval = removeTextWithStrategy(
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
var selection = strategyState.getSelection();
var offset = selection.getStartOffset();
var key = selection.getStartKey();
var content = strategyState.getCurrentContent();
var text = content
const selection = strategyState.getSelection();
const offset = selection.getStartOffset();
const key = selection.getStartKey();
const content = strategyState.getCurrentContent();
const text = content
.getBlockForKey(key)
.getText()
.slice(offset);
var toRemove = DraftRemovableWord.getForward(text);
const toRemove = DraftRemovableWord.getForward(text);

// If there are no words in front of the cursor, remove the newline.
return moveSelectionForward(strategyState, toRemove.length || 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

'use strict';

var DraftModifier = require('DraftModifier');
var EditorState = require('EditorState');
const DraftModifier = require('DraftModifier');
const EditorState = require('EditorState');

function keyCommandInsertNewline(editorState: EditorState): EditorState {
var contentState = DraftModifier.splitBlock(
const contentState = DraftModifier.splitBlock(
editorState.getCurrentContent(),
editorState.getSelection(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

'use strict';

var EditorState = require('EditorState');
const EditorState = require('EditorState');

/**
* See comment for `moveSelectionToStartOfBlock`.
*/
function keyCommandMoveSelectionToEndOfBlock(
editorState: EditorState,
): EditorState {
var selection = editorState.getSelection();
var endKey = selection.getEndKey();
var content = editorState.getCurrentContent();
var textLength = content.getBlockForKey(endKey).getLength();
const selection = editorState.getSelection();
const endKey = selection.getEndKey();
const content = editorState.getCurrentContent();
const textLength = content.getBlockForKey(endKey).getLength();
return EditorState.set(editorState, {
selection: selection.merge({
anchorKey: endKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

'use strict';

var EditorState = require('EditorState');
const EditorState = require('EditorState');

/**
* Collapse selection at the start of the first selected block. This is used
Expand All @@ -22,8 +22,8 @@ var EditorState = require('EditorState');
function keyCommandMoveSelectionToStartOfBlock(
editorState: EditorState,
): EditorState {
var selection = editorState.getSelection();
var startKey = selection.getStartKey();
const selection = editorState.getSelection();
const startKey = selection.getStartKey();
return EditorState.set(editorState, {
selection: selection.merge({
anchorKey: startKey,
Expand Down
22 changes: 11 additions & 11 deletions src/component/handlers/edit/commands/keyCommandPlainBackspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@

'use strict';

var EditorState = require('EditorState');
var UnicodeUtils = require('UnicodeUtils');
const EditorState = require('EditorState');
const UnicodeUtils = require('UnicodeUtils');

var moveSelectionBackward = require('moveSelectionBackward');
var removeTextWithStrategy = require('removeTextWithStrategy');
const moveSelectionBackward = require('moveSelectionBackward');
const removeTextWithStrategy = require('removeTextWithStrategy');

/**
* Remove the selected range. If the cursor is collapsed, remove the preceding
* character. This operation is Unicode-aware, so removing a single character
* will remove a surrogate pair properly as well.
*/
function keyCommandPlainBackspace(editorState: EditorState): EditorState {
var afterRemoval = removeTextWithStrategy(
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
var selection = strategyState.getSelection();
var content = strategyState.getCurrentContent();
var key = selection.getAnchorKey();
var offset = selection.getAnchorOffset();
var charBehind = content.getBlockForKey(key).getText()[offset - 1];
const selection = strategyState.getSelection();
const content = strategyState.getCurrentContent();
const key = selection.getAnchorKey();
const offset = selection.getAnchorOffset();
const charBehind = content.getBlockForKey(key).getText()[offset - 1];
return moveSelectionBackward(
strategyState,
charBehind ? UnicodeUtils.getUTF16Length(charBehind, 0) : 1,
Expand All @@ -44,7 +44,7 @@ function keyCommandPlainBackspace(editorState: EditorState): EditorState {
return editorState;
}

var selection = editorState.getSelection();
const selection = editorState.getSelection();
return EditorState.push(
editorState,
afterRemoval.set('selectionBefore', selection),
Expand Down
22 changes: 11 additions & 11 deletions src/component/handlers/edit/commands/keyCommandPlainDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@

'use strict';

var EditorState = require('EditorState');
var UnicodeUtils = require('UnicodeUtils');
const EditorState = require('EditorState');
const UnicodeUtils = require('UnicodeUtils');

var moveSelectionForward = require('moveSelectionForward');
var removeTextWithStrategy = require('removeTextWithStrategy');
const moveSelectionForward = require('moveSelectionForward');
const removeTextWithStrategy = require('removeTextWithStrategy');

/**
* Remove the selected range. If the cursor is collapsed, remove the following
* character. This operation is Unicode-aware, so removing a single character
* will remove a surrogate pair properly as well.
*/
function keyCommandPlainDelete(editorState: EditorState): EditorState {
var afterRemoval = removeTextWithStrategy(
const afterRemoval = removeTextWithStrategy(
editorState,
strategyState => {
var selection = strategyState.getSelection();
var content = strategyState.getCurrentContent();
var key = selection.getAnchorKey();
var offset = selection.getAnchorOffset();
var charAhead = content.getBlockForKey(key).getText()[offset];
const selection = strategyState.getSelection();
const content = strategyState.getCurrentContent();
const key = selection.getAnchorKey();
const offset = selection.getAnchorOffset();
const charAhead = content.getBlockForKey(key).getText()[offset];
return moveSelectionForward(
strategyState,
charAhead ? UnicodeUtils.getUTF16Length(charAhead, 0) : 1,
Expand All @@ -44,7 +44,7 @@ function keyCommandPlainDelete(editorState: EditorState): EditorState {
return editorState;
}

var selection = editorState.getSelection();
const selection = editorState.getSelection();

return EditorState.push(
editorState,
Expand Down
Loading

0 comments on commit 8de2db9

Please sign in to comment.