Skip to content

Commit d198836

Browse files
committed
Add limitPath option
1 parent 980acc5 commit d198836

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

denops/ddu/base/source.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export function defaultSourceOptions(): SourceOptions {
8080
converters: [],
8181
defaultAction: "",
8282
ignoreCase: false,
83+
limitPath: "",
8384
matcherKey: "word",
8485
matchers: [],
8586
maxItems: 10000,

denops/ddu/ddu.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,21 +1010,32 @@ export class Ddu {
10101010
}
10111011

10121012
// Check path is changed by action
1013-
if (itemAction.sourceOptions.path !== prevPath) {
1013+
const limitPath = itemAction.sourceOptions.limitPath;
1014+
const newPath = itemAction.sourceOptions.path;
1015+
if (
1016+
newPath !== prevPath && (
1017+
limitPath.length === 0 ||
1018+
treePath2Filename(newPath) === treePath2Filename(limitPath) ||
1019+
isParentPath(
1020+
convertTreePath(limitPath),
1021+
convertTreePath(newPath),
1022+
)
1023+
)
1024+
) {
10141025
itemAction.userSource = convertUserString(itemAction.userSource);
10151026
// Overwrite current path
10161027
if (!itemAction.userSource.options) {
10171028
itemAction.userSource.options = {};
10181029
}
1019-
itemAction.userSource.options.path = itemAction.sourceOptions.path;
1030+
itemAction.userSource.options.path = newPath;
10201031
if (this.#context.path.length > 0) {
10211032
this.#context.pathHistories.push(this.#context.path);
10221033
}
10231034

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

1027-
this.#context.path = itemAction.sourceOptions.path;
1038+
this.#context.path = newPath;
10281039

10291040
// Clear input when path is changed
10301041
await this.setInput(denops, "");

denops/ddu/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export type SourceOptions = {
122122
converters: UserFilter[];
123123
defaultAction: string;
124124
ignoreCase: boolean;
125+
limitPath: TreePath;
125126
matcherKey: string;
126127
matchers: UserFilter[];
127128
maxItems: number;

doc/ddu.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,15 @@ ignoreCase (boolean)
861861

862862
Default: v:false
863863

864+
*ddu-source-option-limitPath*
865+
limitPath (string | string[])
866+
Specify limit path when current path is changed by actions.
867+
The path must be under the limit path.
868+
NOTE: You can represents a path by two way like below.
869+
"/aa/bb/cc" (string)
870+
["/", "aa", "bb", "cc"] (string[])
871+
NOTE: It must be full path.
872+
864873
*ddu-source-option-matcherKey*
865874
matcherKey (string)
866875
Matcher compare key for items.

0 commit comments

Comments
 (0)