Fix: Properly setting selection range when KCL editor is not mounted. (#4960)
* fix: fixed selection range issue when doing a constraint when the KCL editor is closed * fix: linter and tsc errors * fix: trying to reuse logic instead? * fix: removed console log
This commit is contained in:
@ -388,7 +388,16 @@ export const ModelingMachineProvider = ({
|
||||
}
|
||||
|
||||
if (setSelections.selectionType === 'completeSelection') {
|
||||
editorManager.selectRange(setSelections.selection)
|
||||
const codeMirrorSelection = editorManager.createEditorSelection(
|
||||
setSelections.selection
|
||||
)
|
||||
kclEditorActor.send({
|
||||
type: 'setLastSelectionEvent',
|
||||
data: {
|
||||
codeMirrorSelection,
|
||||
scrollIntoView: false,
|
||||
},
|
||||
})
|
||||
if (!sketchDetails)
|
||||
return {
|
||||
selectionRanges: setSelections.selection,
|
||||
|
@ -315,6 +315,21 @@ export default class EditorManager {
|
||||
if (selections?.graphSelections?.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this._editorView) {
|
||||
return
|
||||
}
|
||||
const codeBaseSelections = this.createEditorSelection(selections)
|
||||
this._editorView.dispatch({
|
||||
selection: codeBaseSelections,
|
||||
annotations: [
|
||||
updateOutsideEditorEvent,
|
||||
Transaction.addToHistory.of(false),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
createEditorSelection(selections: Selections) {
|
||||
let codeBasedSelections = []
|
||||
for (const selection of selections.graphSelections) {
|
||||
const safeEnd = Math.min(
|
||||
@ -331,18 +346,7 @@ export default class EditorManager {
|
||||
.range[1]
|
||||
const safeEnd = Math.min(end, this._editorView?.state.doc.length || end)
|
||||
codeBasedSelections.push(EditorSelection.cursor(safeEnd))
|
||||
|
||||
if (!this._editorView) {
|
||||
return
|
||||
}
|
||||
|
||||
this._editorView.dispatch({
|
||||
selection: EditorSelection.create(codeBasedSelections, 1),
|
||||
annotations: [
|
||||
updateOutsideEditorEvent,
|
||||
Transaction.addToHistory.of(false),
|
||||
],
|
||||
})
|
||||
return EditorSelection.create(codeBasedSelections, 1)
|
||||
}
|
||||
|
||||
// We will ONLY get here if the user called a select event.
|
||||
|
Reference in New Issue
Block a user