-
-
Notifications
You must be signed in to change notification settings - Fork 175
feat: improve macro open file command #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+363
−56
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f07db89
feat: improve macro open file command
chhoumann 0fd618b
fix: preserve legacy open file mapping
chhoumann 36d6c14
chore: improve open file modal ux
chhoumann e06f5cb
test: align open file tab expectation
chhoumann 0a8cf2a
fix: align open file modal legacy mapping
chhoumann 6c473fa
test: cover open file defaults and tidy modal
chhoumann 6dc8415
fix: keep legacy split default and add coverage
chhoumann 74de619
chore: sync legacy flags with location selections
chhoumann a3d33f9
fix: use enum value for split default
chhoumann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { buildOpenFileOptions } from "./helpers/openFileOptions"; | ||
| import { NewTabDirection } from "../types/newTabDirection"; | ||
| import type { IOpenFileCommand } from "../types/macros/QuickCommands/IOpenFileCommand"; | ||
| import { CommandType } from "../types/macros/CommandType"; | ||
|
|
||
| function createCommand( | ||
| overrides: Partial<IOpenFileCommand> = {} | ||
| ): IOpenFileCommand { | ||
| return { | ||
| id: "test-id", | ||
| name: "Open file: test.md", | ||
| type: overrides.type ?? CommandType.OpenFile, | ||
| filePath: "test.md", | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("buildOpenFileOptions", () => { | ||
| it("respects explicit location when provided", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ location: "right-sidebar" }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("right-sidebar"); | ||
| }); | ||
|
|
||
| it("keeps legacy default behavior: new tab when openInNewTab is false", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ openInNewTab: false, location: undefined }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("tab"); | ||
| expect(options.direction).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("keeps legacy default behavior: split when openInNewTab is true and no direction", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ openInNewTab: true, direction: undefined, location: undefined }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("split"); | ||
| expect(options.direction).toBe("vertical"); | ||
| }); | ||
|
|
||
| it("reuses the current tab when openInNewTab is false and location set to reuse", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ openInNewTab: false, location: "reuse" }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("reuse"); | ||
| expect(options.direction).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("opens a new tab without splitting when location is explicitly tab", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ openInNewTab: true, direction: undefined, location: "tab" }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("tab"); | ||
| expect(options.direction).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("splits vertically when direction is vertical", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ | ||
| openInNewTab: true, | ||
| direction: NewTabDirection.vertical, | ||
| location: "split", | ||
| }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("split"); | ||
| expect(options.direction).toBe("vertical"); | ||
| }); | ||
|
|
||
| it("splits horizontally when direction is horizontal", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ | ||
| openInNewTab: true, | ||
| direction: NewTabDirection.horizontal, | ||
| location: "split", | ||
| }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("split"); | ||
| expect(options.direction).toBe("horizontal"); | ||
| }); | ||
|
|
||
| it("opens in a new window", () => { | ||
| const options = buildOpenFileOptions( | ||
| createCommand({ location: "window", focus: false }) | ||
| ); | ||
|
|
||
| expect(options.location).toBe("window"); | ||
| expect(options.focus).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import type { OpenFileOptions } from "../../types/fileOpening"; | ||
| import type { IOpenFileCommand } from "../../types/macros/QuickCommands/IOpenFileCommand"; | ||
|
|
||
| export function buildOpenFileOptions( | ||
| command: IOpenFileCommand | ||
| ): OpenFileOptions { | ||
| const focus = command.focus ?? true; | ||
|
|
||
| if (command.location) { | ||
| switch (command.location) { | ||
| case "reuse": | ||
| return { location: "reuse", focus, mode: "default" }; | ||
| case "tab": | ||
| return { location: "tab", focus, mode: "default" }; | ||
| case "split": { | ||
| const direction = | ||
| command.direction === "horizontal" || command.direction === "vertical" | ||
| ? command.direction | ||
| : "vertical"; | ||
| return { | ||
| location: "split", | ||
| direction, | ||
| focus, | ||
| mode: "default", | ||
| }; | ||
| } | ||
| case "window": | ||
| return { location: "window", focus, mode: "default" }; | ||
| case "left-sidebar": | ||
| return { location: "left-sidebar", focus, mode: "default" }; | ||
| case "right-sidebar": | ||
| return { location: "right-sidebar", focus, mode: "default" }; | ||
| default: | ||
| break; // fall back to legacy fields | ||
| } | ||
| } | ||
|
|
||
| const openInNewTab = command.openInNewTab ?? false; | ||
| const legacyDirection = | ||
| command.direction === "horizontal" || command.direction === "vertical" | ||
| ? command.direction | ||
| : undefined; | ||
|
|
||
| // Legacy mapping (pre-location field): | ||
| // openInNewTab === false -> open in a new tab (not reuse) | ||
| // openInNewTab === true without direction -> split (default vertical) | ||
| if (!openInNewTab) { | ||
| return { location: "tab", focus, mode: "default" }; | ||
| } | ||
|
|
||
| return { | ||
| location: "split", | ||
| direction: legacyDirection ?? "vertical", | ||
| focus, | ||
| mode: "default", | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.