mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(editor): implement missing methods, fix cursor position clearing (#38603)
(cherry picked from commit 1867336907)
This commit is contained in:
committed by
Michael S. Molina
parent
e42f6c3a1c
commit
33b0b6b3bb
@@ -55,6 +55,8 @@ type Range = editors.Range;
|
||||
type Selection = editors.Selection;
|
||||
type EditorAnnotation = editors.EditorAnnotation;
|
||||
type CompletionProvider = editors.CompletionProvider;
|
||||
type ContentChange = editors.ContentChange;
|
||||
type ContentChangeEvent = editors.ContentChangeEvent;
|
||||
|
||||
/**
|
||||
* Maps EditorLanguage to the corresponding Ace editor component.
|
||||
@@ -117,10 +119,14 @@ const createAceEditorHandle = (
|
||||
},
|
||||
|
||||
moveCursorToPosition: (position: Position) => {
|
||||
aceEditorRef.current?.editor?.moveCursorToPosition({
|
||||
row: position.line,
|
||||
column: position.column,
|
||||
});
|
||||
const editor = aceEditorRef.current?.editor;
|
||||
if (editor) {
|
||||
editor.clearSelection();
|
||||
editor.moveCursorToPosition({
|
||||
row: position.line,
|
||||
column: position.column,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getSelections: (): Selection[] => {
|
||||
@@ -186,6 +192,33 @@ const createAceEditorHandle = (
|
||||
resize: () => {
|
||||
aceEditorRef.current?.editor?.resize();
|
||||
},
|
||||
|
||||
onDidChangeContent: (listener, thisArgs?) => {
|
||||
const editor = aceEditorRef.current?.editor;
|
||||
if (!editor) return new Disposable(() => {});
|
||||
const bound = (thisArgs ? listener.bind(thisArgs) : listener) as (
|
||||
e: ContentChangeEvent,
|
||||
) => void;
|
||||
const handler = (delta: {
|
||||
action: 'insert' | 'remove';
|
||||
start: { row: number; column: number };
|
||||
lines: string[];
|
||||
}) => {
|
||||
const rangeOffset = editor.session.doc.positionToIndex(delta.start);
|
||||
const changeText = delta.lines.join(
|
||||
editor.session.doc.getNewLineCharacter(),
|
||||
);
|
||||
const change: ContentChange =
|
||||
delta.action === 'insert'
|
||||
? { rangeOffset, rangeLength: 0, text: changeText }
|
||||
: { rangeOffset, rangeLength: changeText.length, text: '' };
|
||||
bound({ getValue: () => editor.getValue(), changes: [change] });
|
||||
};
|
||||
editor.session.on('change', handler);
|
||||
return new Disposable(() => {
|
||||
editor.session.off('change', handler);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -694,6 +694,12 @@ const setSchema: typeof sqlLabApi.setSchema = async (schema: string | null) => {
|
||||
store.dispatch(queryEditorSetSchema(queryEditor ?? null, schema));
|
||||
};
|
||||
|
||||
const setActivePanel: typeof sqlLabApi.setActivePanel = async (
|
||||
panelId: string,
|
||||
) => {
|
||||
store.dispatch({ type: SET_ACTIVE_SOUTHPANE_TAB, tabId: panelId });
|
||||
};
|
||||
|
||||
export const sqlLab: typeof sqlLabApi = {
|
||||
CTASMethod,
|
||||
getActivePanel,
|
||||
@@ -719,6 +725,7 @@ export const sqlLab: typeof sqlLabApi = {
|
||||
setDatabase,
|
||||
setCatalog,
|
||||
setSchema,
|
||||
setActivePanel,
|
||||
};
|
||||
|
||||
// Export all models
|
||||
|
||||
Reference in New Issue
Block a user