Skip to content

Commit

Permalink
Inline ghost-text autocompletion
Browse files Browse the repository at this point in the history
Added optional ghost-text preview to popup-based autocompletion (disabled by default)
New external inline-autocompletion widget which supports ghost-text only autocompletion
  • Loading branch information
azmkercso committed Mar 13, 2023
1 parent 338dacf commit 3ef14dd
Show file tree
Hide file tree
Showing 15 changed files with 1,760 additions and 147 deletions.
105 changes: 105 additions & 0 deletions ace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,71 @@ export namespace Ace {
prefix: string,
callback: CompleterCallback): void;
}

export class AceInline {
show(editor: Editor, completion: Completion, prefix: string): void;
isOpen(): void;
hide(): void;
destroy(): void;
}

interface CompletionOptions {
matches?: Completion[];
}

type CompletionProviderOptions = {
exactMatch?: boolean;
ignoreCaption?: boolean;
}

type CompletionRecord = {
all: Completion[];
filtered: Completion[];
filterText: string;
} | CompletionProviderOptions

type GatherCompletionRecord = {
prefix: string;
matches: Completion[];
finished: boolean;
}

type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void;
type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void;

export class CompletionProvider {
insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean;
insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean;
completions: CompletionRecord;
gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean;
provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void;
detach(): void;
}

export class Autocomplete {
constructor();
autoInsert?: boolean;
autoSelect?: boolean;
exactMatch?: boolean;
inlineEnabled?: boolean;
getPopup(): AcePopup;
showPopup(editor: Editor, options: CompletionOptions): void;
detach(): void;
destroy(): void;
}

type AcePopupNavigation = "up" | "down" | "start" | "end";

export class AcePopup {
constructor(parentNode: HTMLElement);
setData(list: Completion[], filterText: string): void;
getData(row: number): Completion;
getRow(): number;
getRow(line: number): void;
hide(): void;
show(pos: Point, lineHeight: number, topdownOnly: boolean): void;
goTo(where: AcePopupNavigation): void;
}
}


Expand All @@ -944,3 +1009,43 @@ export const Range: {
fromPoints(start: Ace.Point, end: Ace.Point): Ace.Range;
comparePoints(p1: Ace.Point, p2: Ace.Point): number;
};


type InlineAutocompleteAction = "prev" | "next" | "first" | "last";

type TooltipCommandEnabledFunction = (editor: Ace.Editor) => boolean;

interface TooltipCommand extends Ace.Command {
enabled: TooltipCommandEnabledFunction | boolean,
position?: number;
}

export class InlineAutocomplete {
constructor();
getInlineRenderer(): Ace.AceInline;
getInlineTooltip(): InlineTooltip;
getCompletionProvider(): Ace.CompletionProvider;
show(editor: Ace.Editor): void;
isOpen(): boolean;
detach(): void;
destroy(): void;
goTo(action: InlineAutocompleteAction): void;
tooltipEnabled: boolean;
commands: Record<string, TooltipCommand>
getIndex(): number;
setIndex(value: number): void;
getLength(): number;
getData(index?: number): Ace.Completion | undefined;
updateCompletions(options: Ace.CompletionOptions): void;
}

export class InlineTooltip {
constructor(parentElement: HTMLElement);
setCommands(commands: Record<string, TooltipCommand>): void;
show(editor: Ace.Editor): void;
updatePosition(): void;
updateButtons(force?: boolean): void;
isShown(): boolean;
detach(): void;
destroy(): void;
}
48 changes: 48 additions & 0 deletions demo/inline_autocompletion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ACE Inline Autocompletion demo</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}

#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>

<pre id="editor"></pre>

<script src="kitchen-sink/require.js"></script>
<script>
// setup paths
require.config({paths: { "ace" : "../src"}});
// load ace and extensions
require(["ace/ace", "ace/mode/javascript", "ace/ext/language_tools", "ace/ext/inline_autocomplete"], function(ace, codeLens) {
var editor = ace.edit("editor");
editor.session.setMode("ace/mode/javascript");
editor.setTheme("ace/theme/tomorrow");
// enable inline autocompletion
editor.setOptions({
enableBasicAutocompletion: false,
enableInlineAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});

window.editor = editor;
});
</script>

<script src="./show_own_source.js"></script>
</body>
</html>
Loading

0 comments on commit 3ef14dd

Please sign in to comment.