[Console] Restore completer behaviour (#49422)
* Restore completer behaviour * Move ace logic into shim and update getCursor -> getCursorPosition
This commit is contained in:
parent
fb903f4f9f
commit
49804a2645
|
@ -317,16 +317,16 @@ export default function({
|
|||
coreEditor: editor,
|
||||
parser,
|
||||
execCommand,
|
||||
getCursor,
|
||||
isCompleteActive,
|
||||
getCursorPosition,
|
||||
isCompleterActive,
|
||||
addChangeListener,
|
||||
removeChangeListener,
|
||||
}: {
|
||||
coreEditor: LegacyEditor;
|
||||
parser: any;
|
||||
execCommand: (cmd: string) => void;
|
||||
getCursor: () => any;
|
||||
isCompleteActive: () => boolean;
|
||||
getCursorPosition: () => Position | null;
|
||||
isCompleterActive: () => boolean;
|
||||
addChangeListener: (fn: any) => void;
|
||||
removeChangeListener: (fn: any) => void;
|
||||
}) {
|
||||
|
@ -969,11 +969,10 @@ export default function({
|
|||
100);
|
||||
|
||||
function editorChangeListener() {
|
||||
const cursor = getCursor();
|
||||
if (isCompleteActive()) {
|
||||
return;
|
||||
const position = getCursorPosition();
|
||||
if (position && !isCompleterActive()) {
|
||||
evaluateCurrentTokenAfterAChange(position);
|
||||
}
|
||||
evaluateCurrentTokenAfterAChange(cursor);
|
||||
}
|
||||
|
||||
function getCompletions(
|
||||
|
|
|
@ -24,6 +24,7 @@ import { LegacyEditor } from '../../../np_ready/public/application/models';
|
|||
|
||||
// @ts-ignore
|
||||
import SenseEditor from './sense_editor/editor';
|
||||
import { Position } from '../../../np_ready/public/types';
|
||||
|
||||
let input: any;
|
||||
export function initializeEditor($el: JQuery<HTMLElement>, $actionsEl: JQuery<HTMLElement>) {
|
||||
|
@ -35,8 +36,18 @@ export function initializeEditor($el: JQuery<HTMLElement>, $actionsEl: JQuery<HT
|
|||
coreEditor: new LegacyEditor(input),
|
||||
parser: input.parser,
|
||||
execCommand: (cmd: string) => input.execCommand(cmd),
|
||||
getCursor: () => input.selection.lead,
|
||||
isCompleteActive: () => input.__ace.completer && input.__ace.completer.activated,
|
||||
getCursorPosition: (): Position | null => {
|
||||
if (input.selection && input.selection.lead) {
|
||||
return {
|
||||
lineNumber: input.selection.lead.row + 1,
|
||||
column: input.selection.lead.column + 1,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
},
|
||||
isCompleterActive: () => {
|
||||
return Boolean(input.__ace.completer && input.__ace.completer.activated);
|
||||
},
|
||||
addChangeListener: (fn: any) => input.on('changeSelection', fn),
|
||||
removeChangeListener: (fn: any) => input.off('changeSelection', fn),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue