fix navigating history downwards on tall messages; remove obsolete code

This commit is contained in:
Matthew Hodgson 2018-05-13 21:17:43 +01:00
parent 721410b710
commit dd0726f068
2 changed files with 1 additions and 67 deletions

View File

@ -223,42 +223,6 @@ export function selectionStateToTextOffsets(selectionState: SelectionState,
}; };
} }
export function textOffsetsToSelectionState({start, end}: SelectionRange,
contentBlocks: Array<ContentBlock>): SelectionState {
let selectionState = SelectionState.createEmpty();
// Subtract block lengths from `start` and `end` until they are less than the current
// block length (accounting for the NL at the end of each block). Set them to -1 to
// indicate that the corresponding selection state has been determined.
for (const block of contentBlocks) {
const blockLength = block.getLength();
// -1 indicating that the position start position has been found
if (start !== -1) {
if (start < blockLength + 1) {
selectionState = selectionState.merge({
anchorKey: block.getKey(),
anchorOffset: start,
});
start = -1; // selection state for the start calculated
} else {
start -= blockLength + 1; // +1 to account for newline between blocks
}
}
// -1 indicating that the position end position has been found
if (end !== -1) {
if (end < blockLength + 1) {
selectionState = selectionState.merge({
focusKey: block.getKey(),
focusOffset: end,
});
end = -1; // selection state for the end calculated
} else {
end -= blockLength + 1; // +1 to account for newline between blocks
}
}
}
return selectionState;
}
// modified version of https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-emoji-plugin/src/modifiers/attachImmutableEntitiesToEmojis.js // modified version of https://github.com/draft-js-plugins/draft-js-plugins/blob/master/draft-js-emoji-plugin/src/modifiers/attachImmutableEntitiesToEmojis.js
export function attachImmutableEntitiesToEmoji(editorState: EditorState): EditorState { export function attachImmutableEntitiesToEmoji(editorState: EditorState): EditorState {
const contentState = editorState.getCurrentContent(); const contentState = editorState.getCurrentContent();

View File

@ -494,14 +494,6 @@ export default class MessageComposerInput extends React.Component {
if (this.props.onContentChanged) { if (this.props.onContentChanged) {
this.props.onContentChanged(textContent, selection); this.props.onContentChanged(textContent, selection);
} }
// Scroll to the bottom of the editor if the cursor is on the last line of the
// composer. For some reason the editor won't scroll automatically if we paste
// blocks of text in or insert newlines.
if (textContent.slice(selection.start).indexOf("\n") === -1) {
let editorRoot = this.refs.editor.refs.editor.parentNode.parentNode;
editorRoot.scrollTop = editorRoot.scrollHeight;
}
*/ */
}); });
} }
@ -933,7 +925,7 @@ export default class MessageComposerInput extends React.Component {
else { else {
const scrollCorrection = const scrollCorrection =
editorNode.scrollHeight - editorNode.clientHeight - editorNode.scrollTop; editorNode.scrollHeight - editorNode.clientHeight - editorNode.scrollTop;
const distanceFromBottom = cursorRect.bottom - editorRect.bottom + scrollCorrection; const distanceFromBottom = editorRect.bottom - cursorRect.bottom + scrollCorrection;
console.log(`Cursor distance from editor bottom is ${distanceFromBottom}`); console.log(`Cursor distance from editor bottom is ${distanceFromBottom}`);
if (distanceFromBottom < EDGE_THRESHOLD) { if (distanceFromBottom < EDGE_THRESHOLD) {
navigateHistory = true; navigateHistory = true;
@ -1082,28 +1074,6 @@ export default class MessageComposerInput extends React.Component {
// this.refs.editor.focus(); // this.refs.editor.focus();
}); });
/*
let selection;
if (range) {
selection = RichText.textOffsetsToSelectionState(
range, contentState.getBlocksAsArray(),
);
} else {
selection = activeEditorState.getSelection();
}
contentState = Modifier.replaceText(contentState, selection, completion, null, entityKey);
// Move the selection to the end of the block
const afterSelection = contentState.getSelectionAfter();
if (suffix) {
contentState = Modifier.replaceText(contentState, afterSelection, suffix);
}
let editorState = EditorState.push(activeEditorState, contentState, 'insert-characters');
editorState = EditorState.forceSelection(editorState, contentState.getSelectionAfter());
this.setState({editorState, originalEditorState: activeEditorState});
*/
return true; return true;
}; };