From 377075baa228b4f9ddf8b8b9873ccbeaed85e517 Mon Sep 17 00:00:00 2001 From: "vicky_primathon.in" Date: Fri, 22 May 2020 12:59:15 +0530 Subject: [PATCH] cursor positioning fixed --- .../DynamicAutocompleteInput.tsx | 6 +++-- .../editorComponents/LightningMenu/index.tsx | 27 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx b/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx index 105b651c58..f58fd88bf9 100644 --- a/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx +++ b/app/client/src/components/editorComponents/DynamicAutocompleteInput.tsx @@ -531,10 +531,12 @@ class DynamicAutocompleteInput extends Component { } }; - updatePropertyValue = (value: string, cursor: number) => { + updatePropertyValue = (value: string, cursor?: number) => { this.editor.setValue(value); this.editor.focus(); - console.log(value, cursor); + if (cursor === undefined) { + cursor = value.length - 2; + } this.editor.setCursor({ line: 0, ch: cursor, diff --git a/app/client/src/components/editorComponents/LightningMenu/index.tsx b/app/client/src/components/editorComponents/LightningMenu/index.tsx index 9ffe10d9fd..b218194120 100644 --- a/app/client/src/components/editorComponents/LightningMenu/index.tsx +++ b/app/client/src/components/editorComponents/LightningMenu/index.tsx @@ -13,7 +13,7 @@ import { noop } from "lodash"; const getApiOptions = ( themeType: string, apis: RestAction[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -26,6 +26,7 @@ const getApiOptions = ( icon="plus" iconAlignment="left" themeType={themeType} + type="button" /> ), }, @@ -35,8 +36,7 @@ const getApiOptions = ( options: apis.map(api => ({ content: api.name, onSelect: () => { - const value = `{{${api.name}.data}}`; - updatePropertyValue(value, value.length + 1); + updatePropertyValue(`{{${api.name}.data}}`); }, })), }, @@ -52,7 +52,7 @@ const getApiOptions = ( const getQueryOptions = ( themeType: string, queries: RestAction[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -65,6 +65,7 @@ const getQueryOptions = ( icon="plus" iconAlignment="left" themeType={themeType} + type="button" /> ), }, @@ -74,8 +75,7 @@ const getQueryOptions = ( options: queries.map(query => ({ content: query.name, onSelect: () => { - const value = `{{${query.name}.data}}`; - updatePropertyValue(value, value.length + 1); + updatePropertyValue(`{{${query.name}.data}}`); }, })), }, @@ -91,7 +91,7 @@ const getQueryOptions = ( const getWidgetOptions = ( themeType: string, widgets: WidgetProps[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { @@ -117,15 +117,14 @@ const getWidgetOptions = ( const getWidgetData = ( themeType: string, widget: WidgetProps, - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ) => ({ sections: [ { options: Object.keys(widget).map(widgetProp => ({ content: widgetProp, onSelect: () => { - const value = `{{${widget.widgetName}.${widgetProp}}}`; - updatePropertyValue(value, value.length); + updatePropertyValue(`{{${widget.widgetName}.${widgetProp}}}`); }, })), }, @@ -143,7 +142,7 @@ const lightningMenuOptions = ( apis: RestAction[], queries: RestAction[], widgets: WidgetProps[], - updatePropertyValue: (value: string, cursor: number) => void, + updatePropertyValue: (value: string, cursor?: number) => void, ): CustomizedDropdownProps => ({ sections: [ { @@ -153,7 +152,7 @@ const lightningMenuOptions = ( disabled: false, shouldCloseDropdown: true, onSelect: () => { - updatePropertyValue("", 0); + updatePropertyValue(""); }, }, { @@ -188,7 +187,7 @@ const lightningMenuOptions = ( disabled: false, shouldCloseDropdown: true, onSelect: () => { - updatePropertyValue("{{}}", 2); + updatePropertyValue("{{}}"); }, }, { @@ -212,7 +211,7 @@ const lightningMenuOptions = ( type LightningMenuProps = { onSelect?: (value: string) => void; - updatePropertyValue: (value: string, cursor: number) => void; + updatePropertyValue: (value: string, cursor?: number) => void; themeType: string; };