"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getCurrentSearchState = getCurrentSearchState; exports.loadPatternIntoSearch = loadPatternIntoSearch; const vscode = __importStar(require("vscode")); /** * Get the current search state from the Search panel * Returns null if unable to get the state * * NOTE: VS Code doesn't expose search panel state via API. * This function tries to use editor selection as fallback. */ async function getCurrentSearchState() { // Try to get selected text from active editor const editor = vscode.window.activeTextEditor; const selection = editor?.document.getText(editor.selection); if (selection && selection.length > 0) { // Use selection as find text return { find: selection, replace: '', flags: { isRegex: false, isCaseSensitive: false, matchWholeWord: false, isMultiline: false } }; } // No selection available - return null // User will need to enter manually return null; } /** * Resolve placeholders like ${prompt:varname} in multiple strings * Prompts once per unique placeholder name and reuses the value */ async function resolvePlaceholdersMultiple(texts) { const RE = /\$\{prompt:([^}]+)\}/g; // Collect all unique placeholder names across all texts const allNames = new Set(); for (const text of texts) { Array.from(text.matchAll(RE), m => m[1]).forEach(name => allNames.add(name)); } const vals = {}; // Prompt once for each unique placeholder for (const name of allNames) { const value = await vscode.window.showInputBox({ prompt: `Value for ${name}`, placeHolder: name }); if (value === undefined) { return undefined; // User cancelled } vals[name] = value; } // Replace placeholders in all texts using the collected values return texts.map(text => text.replace(RE, (_, name) => vals[name] ?? "")); } /** * Resolve placeholders like ${prompt:varname} in a string (single text version) */ async function resolvePlaceholders(text) { const result = await resolvePlaceholdersMultiple([text]); return result ? result[0] : undefined; } async function loadPatternIntoSearch(pattern) { try { const hasReplace = pattern.replace && pattern.replace.trim().length > 0; const textsToResolve = hasReplace ? [pattern.find, pattern.replace] : [pattern.find]; const resolved = await resolvePlaceholdersMultiple(textsToResolve); if (!resolved) { return; // User cancelled } const find = resolved[0]; const replace = hasReplace ? resolved[1] : ''; const commandArgs = { query: find, replace: replace, triggerSearch: false, // Don't auto-trigger search isRegex: pattern.flags.isRegex, isCaseSensitive: pattern.flags.isCaseSensitive, matchWholeWord: pattern.flags.matchWholeWord, preserveCase: false, filesToInclude: pattern.filesToInclude || '', filesToExclude: pattern.filesToExclude || '' }; await vscode.commands.executeCommand("workbench.action.findInFiles", commandArgs); vscode.window.showInformationMessage(`✅ Loaded pattern: "${pattern.label}"`); } catch (error) { vscode.window.showErrorMessage(`Failed to load pattern: ${error}`); throw error; } } //# sourceMappingURL=searchCtx.js.map