Skip to content

Commit

Permalink
[Console] Restore completer behaviour (#49422) (#49481)
Browse files Browse the repository at this point in the history
* Restore completer behaviour

* Move ace logic into shim and update getCursor -> getCursorPosition
  • Loading branch information
jloleysens authored Oct 28, 2019
1 parent 0cff839 commit 3919073
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}) {
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 13 additions & 2 deletions src/legacy/core_plugins/console/public/quarantined/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand All @@ -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),
};
Expand Down

0 comments on commit 3919073

Please sign in to comment.