Merge pull request #539 from esteemapp/bugfix/#468

Fixed #468
This commit is contained in:
uğur erdal 2019-02-07 11:13:17 +03:00 committed by GitHub
commit 537cc5e877
5 changed files with 21 additions and 17 deletions

View File

@ -26,7 +26,7 @@ export default ({ getState, item, setState }) => {
setState({ text: newText }, () => { setState({ text: newText }, () => {
setTimeout(() => { setTimeout(() => {
setState({ selection: newSelection }); setState({ newSelection });
}, 300); }, 300);
}); });
}; };

View File

@ -36,6 +36,6 @@ export default ({
}; };
} }
setState({ text: newText }, () => { setState({ text: newText }, () => {
setState({ selection: newSelection }); setState({ newSelection });
}); });
}; };

View File

@ -13,15 +13,14 @@ export default ({ getState, item, setState }) => {
} else { } else {
newPosition = selection.end + item.wrapper.length * 2; newPosition = selection.end + item.wrapper.length * 2;
} }
const extra = { const extra = {
selection: { newSelection: {
start: newPosition, start: newPosition,
end: newPosition, end: newPosition,
}, },
}; };
setState({ text: newText }, () => { setState({ text: newText }, () => {
setTimeout(() => { setState({ ...extra });
setState({ ...extra });
}, 25);
}); });
}; };

View File

@ -42,7 +42,7 @@ export default ({ getState, item, setState }) => {
); );
} }
const extra = { const extra = {
selection: { newSelection: {
start: newPosition, start: newPosition,
end: newPosition, end: newPosition,
}, },

View File

@ -24,6 +24,7 @@ export default class MarkdownEditorView extends Component {
this.state = { this.state = {
text: props.draftBody || '', text: props.draftBody || '',
selection: { start: 0, end: 0 }, selection: { start: 0, end: 0 },
newSelection: null,
}; };
} }
@ -79,21 +80,25 @@ export default class MarkdownEditorView extends Component {
}; };
_handleOnSelectionChange = (event) => { _handleOnSelectionChange = (event) => {
this.setState({ const { newSelection } = this.state;
selection: event.nativeEvent.selection,
}); if (newSelection) {
this.setState({
selection: newSelection,
newSelection: null,
});
} else {
this.setState({
selection: event.nativeEvent.selection,
});
}
}; };
_getState = () => { _getState = () => {
this.setState({
selection: {
start: 1,
end: 1,
},
});
return this.state; return this.state;
}; };
_renderPreview = () => { _renderPreview = () => {
const { text } = this.state; const { text } = this.state;
@ -180,7 +185,7 @@ export default class MarkdownEditorView extends Component {
id: isReply ? 'editor.reply_placeholder' : 'editor.default_placeholder', id: isReply ? 'editor.reply_placeholder' : 'editor.default_placeholder',
})} })}
placeholderTextColor="#c1c5c7" placeholderTextColor="#c1c5c7"
selection={Platform.OS === 'ios' ? selection : undefined} selection={selection}
selectionColor="#357ce6" selectionColor="#357ce6"
style={styles.textWrapper} style={styles.textWrapper}
underlineColorAndroid="transparent" underlineColorAndroid="transparent"