From f7a1837d31d3445cf8867fc2357f36489f1c10b7 Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 17 Jul 2021 20:29:52 +0530 Subject: [PATCH 1/2] fix: paste and Ctrl+z --- src/components/TextInputFocusable/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/TextInputFocusable/index.js b/src/components/TextInputFocusable/index.js index 1ee3da703a2b..5e03db2856bb 100755 --- a/src/components/TextInputFocusable/index.js +++ b/src/components/TextInputFocusable/index.js @@ -252,13 +252,11 @@ class TextInputFocusable extends React.Component { handlePastedHTML(html) { const parser = new ExpensiMark(); const markdownText = parser.htmlToMarkdown(html); - const beforeCursorText = this.textInput.value.substring(0, this.selection.start); - const afterCursorText = this.textInput.value.substring(this.selection.end); - this.textInput.value = beforeCursorText + markdownText + afterCursorText; - const newCursorPosition = beforeCursorText.length + markdownText.length; - this.setState({selection: {start: newCursorPosition, end: newCursorPosition}}); - this.updateNumberOfLines(); - this.props.onChangeText(this.textInput.value); + try { + document.execCommand('insertText', false, markdownText); + this.updateNumberOfLines(); + // eslint-disable-next-line no-empty + } catch (e) { } } /** From 87b17dc99a15ca8da052140444e110807ad0521c Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Sat, 17 Jul 2021 21:13:16 +0530 Subject: [PATCH 2/2] remove extra selection --- src/components/TextInputFocusable/index.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/components/TextInputFocusable/index.js b/src/components/TextInputFocusable/index.js index 5e03db2856bb..5ace8e0e8d9a 100755 --- a/src/components/TextInputFocusable/index.js +++ b/src/components/TextInputFocusable/index.js @@ -115,11 +115,6 @@ class TextInputFocusable extends React.Component { end: initialValue.length, }, }; - this.selection = { - start: initialValue.length, - end: initialValue.length, - }; - this.saveSelection = this.saveSelection.bind(this); this.dragNDropListener = this.dragNDropListener.bind(this); this.handlePaste = this.handlePaste.bind(this); this.handlePastedHTML = this.handlePastedHTML.bind(this); @@ -232,17 +227,6 @@ class TextInputFocusable extends React.Component { } } - /** - * Keeps track of user cursor position on the Composer - * - * @param {{nativeEvent: {selection: any}}} event - * @memberof TextInputFocusable - */ - saveSelection(event) { - this.selection = event.nativeEvent.selection; - this.props.onSelectionChange(event); - } - /** * Manually place the pasted HTML into Composer * @@ -256,7 +240,7 @@ class TextInputFocusable extends React.Component { document.execCommand('insertText', false, markdownText); this.updateNumberOfLines(); // eslint-disable-next-line no-empty - } catch (e) { } + } catch (e) {} } /** @@ -351,7 +335,7 @@ class TextInputFocusable extends React.Component { onChange={() => { this.updateNumberOfLines(); }} - onSelectionChange={this.saveSelection} + onSelectionChange={this.onSelectionChange} numberOfLines={this.state.numberOfLines} style={propStyles} /* eslint-disable-next-line react/jsx-props-no-spreading */