Skip to content
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

Disable Insert Adjustment Setting and Limit Insert to once #197

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"default": true,
"description": "Specifies whether or not to show tour markers in the editor gutter."
},
"codetour.adjustOnInsertCodeSnippet": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to adjust tour step line numbers when a snippet is inserted."
},
"codetour.customTourDirectory": {
"type": "string",
"default": null,
Expand Down
22 changes: 17 additions & 5 deletions src/player/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { progress } from "../store/storage";
import { readUriContents } from "../utils";
import { CodeTourNode } from "./tree/nodes";

const adjustOnInsertCodeSnippet = vscode.workspace
.getConfiguration("codetour")
.get("adjustOnInsertCodeSnippet", true);

let terminal: vscode.Terminal | null;
export function registerPlayerCommands() {
// This is a "private" command that's used exclusively
Expand Down Expand Up @@ -112,6 +116,12 @@ export function registerPlayerCommands() {
const codeSnippet = decodeURIComponent(codeBlock);

const step = store.activeTour!.tour.steps[store.activeTour!.step];
const docText = vscode.window.activeTextEditor?.document.getText();

if (docText?.includes(codeSnippet)) {
return; // early out snippet has already been inserted
}

if (step.selection) {
await vscode.window.activeTextEditor?.edit(e => {
const selection = new vscode.Selection(
Expand All @@ -130,11 +140,13 @@ export function registerPlayerCommands() {
}

const lineAdjustment = codeSnippet.split("\n").length - 1;
if (lineAdjustment > 0) {
store.activeTour!.tour.steps[
store.activeTour!.step
].line! += lineAdjustment;

if (adjustOnInsertCodeSnippet && lineAdjustment > 0) {
const step = store.activeTour!.tour.steps[store.activeTour!.step];
step.line! += lineAdjustment;
if (step.selection) {
step.selection.start.line += lineAdjustment;
step.selection.end.line += lineAdjustment;
}
saveTour(store.activeTour!.tour);
}

Expand Down