From 81817309d3f1e19636fdc310ca3b393ccabe254a Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 14 Aug 2017 17:55:30 -0700 Subject: [PATCH] [sql lab] fix sluggish backspace in editor (#3286) Somehow Ace's "changeSelection" event is triggered when hitting backspace (and shouldn't!). changeSelection on our side triggers enough work to make the holding backspace sluggish and laggy. This fix ignores selection with a length of 1, avoiding mutating the state altogether when hitting/holding backspace. --- .../javascripts/SqlLab/components/AceEditorWrapper.jsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx index 37b884a6f6b..15adf0b80d9 100644 --- a/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx +++ b/superset/assets/javascripts/SqlLab/components/AceEditorWrapper.jsx @@ -45,6 +45,7 @@ class AceEditorWrapper extends React.PureComponent { super(props); this.state = { sql: props.sql, + selectedText: '', }; } componentDidMount() { @@ -77,8 +78,13 @@ class AceEditorWrapper extends React.PureComponent { }); editor.$blockScrolling = Infinity; // eslint-disable-line no-param-reassign editor.selection.on('changeSelection', () => { - this.props.actions.queryEditorSetSelectedText( - this.props.queryEditor, editor.getSelectedText()); + const selectedText = editor.getSelectedText(); + // Backspace trigger 1 character selection, ignoring + if (selectedText !== this.state.selectedText && selectedText.length !== 1) { + this.setState({ selectedText }); + this.props.actions.queryEditorSetSelectedText( + this.props.queryEditor, selectedText); + } }); } getCompletions(aceEditor, session, pos, prefix, callback) {