Skip to content

Commit

Permalink
Improve resume behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Aug 1, 2023
1 parent 65c30c7 commit f69b3e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions denops/ddu/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ export function main(denops: Denops) {
ddu = pushDdu(options.name);

// Extends previous options
const prevOptions = Object.assign(prevDdu.getOptions(), {
const prevOptions = {
...prevDdu.getOptions(),
input: "",
});
};
userOptions = foldMerge(mergeDduOptions, defaultDduOptions, [
prevOptions,
userOptions,
Expand Down
2 changes: 2 additions & 0 deletions denops/ddu/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function defaultContext(): Context {
return {
bufName: "",
bufNr: 0,
cwd: "",
done: false,
doneUi: false,
input: "",
Expand Down Expand Up @@ -339,6 +340,7 @@ export class ContextBuilder {
...defaultContext(),
bufName: await fn.bufname(denops, "%"),
bufNr: await fn.bufnr(denops, "%"),
cwd: await fn.getcwd(denops),
mode: await fn.mode(denops),
winId: await fn.win_getid(denops) as number,
},
Expand Down
13 changes: 7 additions & 6 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export class Ddu {
options: DduOptions,
userOptions: UserOptions,
): Promise<void> {
const prevInput = this.context.input;
const prevPath = this.context.path;
const prevContext = { ...this.context };

this.context = context;
this.userOptions = userOptions;
Expand All @@ -151,6 +150,7 @@ export class Ddu {

if (
this.initialized && resume && !uiChanged &&
prevContext.done && this.context.cwd === prevContext.cwd &&
(!userOptions?.sources ||
equal(userOptions.sources, this.options.sources))
) {
Expand All @@ -162,12 +162,13 @@ export class Ddu {
// Set input
if (userOptions?.input !== undefined) {
await this.setInput(denops, userOptions.input as string);
} else if (prevInput !== "") {
await this.setInput(denops, prevInput);
} else if (prevContext.input !== "") {
await this.setInput(denops, prevContext.input);
}

// Set path
this.context.path = prevPath;
// Restore
this.context.path = prevContext.path;
this.context.maxItems = prevContext.maxItems;

const [ui, uiOptions, uiParams] = await this.getUi(denops);
if (!ui) {
Expand Down
1 change: 1 addition & 0 deletions denops/ddu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type TreePath = string | string[];
export type Context = {
bufName: string;
bufNr: number;
cwd: string;
done: boolean;
doneUi: boolean;
input: string;
Expand Down

0 comments on commit f69b3e3

Please sign in to comment.