Skip to content

Commit

Permalink
Feat: Restored Home and End functionality when in autocomplete results
Browse files Browse the repository at this point in the history
  • Loading branch information
GerwinBosch committed Feb 7, 2020
1 parent 9c95c05 commit cdf574a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
10 changes: 10 additions & 0 deletions packages/yasqe/src/autocompleters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ export class Completer extends EventEmitter {
completeSingle: false,
hint: getHints,
container: this.yasqe.rootEl,
// Override these actions back to use their default function
// Otherwise these would navigate to the start/end of the suggestion list, while this can also be accomplished with PgUp and PgDn
extraKeys: {
Home: (yasqe, event) => {
yasqe.getDoc().setCursor({ ch: 0, line: event.data.from.line });
},
End: (yasqe, event) => {
yasqe.getDoc().setCursor({ ch: yasqe.getLine(event.data.to.line).length, line: event.data.to.line });
}
},
...this.yasqe.config.hintConfig
};
this.yasqe.showHint(hintConfig);
Expand Down
47 changes: 40 additions & 7 deletions packages/yasqe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,22 @@ export interface Hint {
from?: Position;
to?: Position;
}
// type AutocompleteEventHandler = (
// yasqe: Yasqe,
// event: {
// close: () => void;
// data: {
// from: Position;
// to: Position;
// list: Hint[];
// };
// length: number;
// menuSize: () => void;
// moveFocus: () => void;
// pick: () => void;
// setFocus: () => void;
// }
// ) => {};

export type HintFn = { async?: boolean } & (() => Promise<HintList> | HintList);
export interface HintConfig {
Expand All @@ -919,25 +935,42 @@ export interface HintConfig {
customKeys?: any;

// Like customKeys above, but the bindings will be added to the set of default bindings, instead of replacing them.
extraKeys?: any;
extraKeys?: {
[key: string]: (
yasqe: Yasqe,
event: {
close: () => void;
data: {
from: Position;
to: Position;
list: Hint[];
};
length: number;
menuSize: () => void;
moveFocus: (movement: number) => void;
pick: () => void;
setFocus: (index: number) => void;
}
) => void;
};
}
export interface RequestConfig<Y> {
queryArgument: string | ((yasqe: Y) => string);
endpoint: string | ((yasqe: Y) => string);
method: "POST" | "GET" | ((yasqe:Y) => "POST" | "GET");
method: "POST" | "GET" | ((yasqe: Y) => "POST" | "GET");
acceptHeaderGraph: string | ((yasqe: Y) => string);
acceptHeaderSelect: string | ((yasqe: Y) => string);
acceptHeaderUpdate: string | ((yasqe: Y) => string);
namedGraphs: string[] | ((yasqe:Y) => string[]);
defaultGraphs: string[] | ((yasqe:Y) => []);
namedGraphs: string[] | ((yasqe: Y) => string[]);
defaultGraphs: string[] | ((yasqe: Y) => []);
args: Array<{ name: string; value: string }> | ((yasqe: Y) => Array<{ name: string; value: string }>);
headers: { [key: string]: string } | ((yasqe: Y) => { [key: string]: string });
withCredentials: boolean | ((yasqe:Y) => boolean);
withCredentials: boolean | ((yasqe: Y) => boolean);
adjustQueryBeforeRequest: ((yasqe: Y) => string) | false;
}
export type PlainRequestConfig = {[K in keyof RequestConfig<any> ]: Exclude<RequestConfig<any>[K], Function>};
export type PlainRequestConfig = { [K in keyof RequestConfig<any>]: Exclude<RequestConfig<any>[K], Function> };
export type PartialConfig = {
[P in keyof Config]?: Config[P] extends object? Partial<Config[P]>:Config[P]
[P in keyof Config]?: Config[P] extends object ? Partial<Config[P]> : Config[P];
};
export interface Config extends Partial<CodeMirror.EditorConfiguration> {
mode: string;
Expand Down

0 comments on commit cdf574a

Please sign in to comment.