[Console] Restore completer behaviour (#49422)

* Restore completer behaviour

* Move ace logic into shim and update getCursor -> getCursorPosition
This commit is contained in:
Jean-Louis Leysens 2019-10-28 13:54:47 +01:00 committed by GitHub
parent fb903f4f9f
commit 49804a2645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View file

@ -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(

View file

@ -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),
};