Skip to content

Commit

Permalink
Enhancement: Add write, save, ... actions to the create new step …
Browse files Browse the repository at this point in the history
…command #18
  • Loading branch information
estruyf committed Dec 27, 2024
1 parent 430e999 commit 591db4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.0.47] - 2025-12-27

- [#18](https://github.com/estruyf/vscode-demo-time/issues/18): Added the `save` and `write` actions to the `Demo Time: Add as demo step` command.

## [0.0.46] - 2025-12-20

- Improved the `position` setting so that you can define `<start line>,<start character>` a specific position or `<start line>,<start character>:<end line>,<end character>` to select a range of code
Expand Down
4 changes: 2 additions & 2 deletions src/models/Demos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export interface Icons {

export interface Step {
action: Action;
path: string;


path?: string;
content?: string;
contentPath?: string;
position?: string | number;
Expand Down
27 changes: 20 additions & 7 deletions src/services/DemoCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DemoCreator {

subscriptions.push(commands.registerCommand(COMMAND.initialize, DemoCreator.initialize));
subscriptions.push(commands.registerCommand(COMMAND.openDemoFile, DemoCreator.openFile));
subscriptions.push(commands.registerCommand(COMMAND.addToStep, DemoCreator.copy));
subscriptions.push(commands.registerCommand(COMMAND.addToStep, DemoCreator.addToStep));
subscriptions.push(
commands.registerCommand(COMMAND.stepMoveUp, (item: ActionTreeItem) => DemoCreator.move(item, "up"))
);
Expand Down Expand Up @@ -92,7 +92,7 @@ export class DemoCreator {
* If the user chooses to insert a step into an existing demo, they are prompted to select the demo.
* The modified demo file is saved after the step is added.
*/
private static async copy() {
private static async addToStep() {
let demoFiles = await FileProvider.getFiles();
if (!demoFiles) {
await FileProvider.createFile();
Expand All @@ -118,10 +118,17 @@ export class DemoCreator {
}
const { filePath, demo } = demoFile;

const action = await window.showQuickPick(["Insert", "Highlight", "Unselect", "Delete"], {
const actions: Action[] = ["insert", "highlight", "unselect", "delete", "save"];

// If selection is a single line, add the "write" action
if (selection.start.line === selection.end.line) {
actions.push("write");
}

const action = await window.showQuickPick(actions, {
title: "Demo time!",
placeHolder: "What kind of action step do you want to perform?",
});
}) as unknown as Action;

if (!action) {
return;
Expand All @@ -140,7 +147,7 @@ export class DemoCreator {
const end = selection.end.line;

let position: string | number = selection.start.line + 1;
if (action !== "Insert" && action !== "Unselect") {
if (action !== "insert" && action !== "unselect") {
position = start === end ? start + 1 : `${start + 1}:${end + 1}`;
}

Expand All @@ -151,11 +158,17 @@ export class DemoCreator {
};

// Unselect doesn't need the position
if (action === "Unselect") {
if (action === "unselect") {
delete step.position;
}

// The save action doesn't need the position and path
if (action === "save") {
delete step.position;
delete step.path;
}

if (action === "Insert") {
if (action === "insert" || action === "write") {
step.content = modifiedText;
}

Expand Down

0 comments on commit 591db4b

Please sign in to comment.