Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions client/src/containers/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default function Editor({

const [editorInstance, setEditorInstance] = useState(undefined)
const [keywords, setKeywords] = useState([])
const getValue = () => editorInstance?.getValue() || ''

const lastSetValueRef = useRef('')
const isSettingContent = useRef(false)

const allState = useSelector((state) => state)

Expand Down Expand Up @@ -145,8 +147,15 @@ export default function Editor({

// Every time editor is created or callback for onUpdateQuery is updated
useEditorEffect(() => {
if (!editorInstance) {
return
}

const onChangeHandler = (cm) => {
if (isSettingContent.current) return
const value = editorInstance.getValue()
lastSetValueRef.current = value

const isJsonValue = isJSON()

if (editorInstance.getMode().name === 'graphql') {
Expand Down Expand Up @@ -180,8 +189,17 @@ export default function Editor({

// Every time query changes
useEditorEffect(() => {
if (query !== getValue()) {
if (query !== lastSetValueRef.current) {
isSettingContent.current = true
const cursor = editorInstance.getCursor()

editorInstance.setValue(query)

lastSetValueRef.current = query
editorInstance.setCursor(cursor)
setTimeout(() => {
isSettingContent.current = false
}, 0)
}
}, [query])

Expand Down
Loading