Skip to content

Commit

Permalink
Add limitPath option
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Dec 25, 2024
1 parent 980acc5 commit d198836
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions denops/ddu/base/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function defaultSourceOptions(): SourceOptions {
converters: [],
defaultAction: "",
ignoreCase: false,
limitPath: "",
matcherKey: "word",
matchers: [],
maxItems: 10000,
Expand Down
17 changes: 14 additions & 3 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,21 +1010,32 @@ export class Ddu {
}

// Check path is changed by action
if (itemAction.sourceOptions.path !== prevPath) {
const limitPath = itemAction.sourceOptions.limitPath;
const newPath = itemAction.sourceOptions.path;
if (
newPath !== prevPath && (
limitPath.length === 0 ||
treePath2Filename(newPath) === treePath2Filename(limitPath) ||
isParentPath(
convertTreePath(limitPath),
convertTreePath(newPath),
)
)
) {
itemAction.userSource = convertUserString(itemAction.userSource);
// Overwrite current path
if (!itemAction.userSource.options) {
itemAction.userSource.options = {};
}
itemAction.userSource.options.path = itemAction.sourceOptions.path;
itemAction.userSource.options.path = newPath;
if (this.#context.path.length > 0) {
this.#context.pathHistories.push(this.#context.path);
}

// Overwrite userSource
this.#options.sources[itemAction.sourceIndex] = itemAction.userSource;

this.#context.path = itemAction.sourceOptions.path;
this.#context.path = newPath;

// Clear input when path is changed
await this.setInput(denops, "");
Expand Down
1 change: 1 addition & 0 deletions denops/ddu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type SourceOptions = {
converters: UserFilter[];
defaultAction: string;
ignoreCase: boolean;
limitPath: TreePath;
matcherKey: string;
matchers: UserFilter[];
maxItems: number;
Expand Down
9 changes: 9 additions & 0 deletions doc/ddu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ ignoreCase (boolean)

Default: v:false

*ddu-source-option-limitPath*
limitPath (string | string[])
Specify limit path when current path is changed by actions.
The path must be under the limit path.
NOTE: You can represents a path by two way like below.
"/aa/bb/cc" (string)
["/", "aa", "bb", "cc"] (string[])
NOTE: It must be full path.

*ddu-source-option-matcherKey*
matcherKey (string)
Matcher compare key for items.
Expand Down

0 comments on commit d198836

Please sign in to comment.