feat: 添加上下文按钮和自定义下拉框,优化输入区域样式
This commit is contained in:
@ -58,7 +58,9 @@ export async function showICHelperPanel(
|
|||||||
const historyManager = ChatHistoryManager.getInstance();
|
const historyManager = ChatHistoryManager.getInstance();
|
||||||
const panelId = (panel as any).__uniqueId;
|
const panelId = (panel as any).__uniqueId;
|
||||||
|
|
||||||
// 在处理消息前,确保面板有任务上下文
|
switch (message.command) {
|
||||||
|
case "sendMessage":
|
||||||
|
// 仅在用户发送消息时,确保面板有任务上下文
|
||||||
// 如果没有,则创建新任务(仅在首次发送消息时)
|
// 如果没有,则创建新任务(仅在首次发送消息时)
|
||||||
if (!historyManager.getPanelTask(panelId)) {
|
if (!historyManager.getPanelTask(panelId)) {
|
||||||
const workspacePath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
const workspacePath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
||||||
@ -75,8 +77,6 @@ export async function showICHelperPanel(
|
|||||||
// 切换到当前面板的任务上下文
|
// 切换到当前面板的任务上下文
|
||||||
historyManager.switchToPanelTask(panelId);
|
historyManager.switchToPanelTask(panelId);
|
||||||
|
|
||||||
switch (message.command) {
|
|
||||||
case "sendMessage":
|
|
||||||
handleUserMessage(panel, message.text, context.extensionPath);
|
handleUserMessage(panel, message.text, context.extensionPath);
|
||||||
break;
|
break;
|
||||||
case "readFile":
|
case "readFile":
|
||||||
|
|||||||
@ -8,8 +8,18 @@ export function getInputAreaContent(): string {
|
|||||||
<div class="input-area">
|
<div class="input-area">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-wrapper">
|
<div class="input-wrapper">
|
||||||
|
<!-- 顶部工具栏 -->
|
||||||
|
<div class="input-top-toolbar">
|
||||||
|
<!-- 添加上下文按钮 -->
|
||||||
|
<div class="tooltip">
|
||||||
|
<button class="add-context-button" onclick="handleAddContext()">
|
||||||
|
<svg t="1766915545722" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4994" width="200" height="200"><path d="M469.333333 469.333333V170.666667h85.333334v298.666666h298.666666v85.333334h-298.666666v298.666666h-85.333334v-298.666666H170.666667v-85.333334h298.666666z" fill="#8a8a8a" p-id="4995"></path></svg>
|
||||||
|
<span class="add-context-label">添加上下文</span>
|
||||||
|
</button>
|
||||||
|
<span class="tooltiptext">添加文件或代码片段作为上下文</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Plan 开关 -->
|
<!-- Plan 开关 -->
|
||||||
<div class="plan-toggle-container">
|
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<label class="plan-toggle">
|
<label class="plan-toggle">
|
||||||
<input type="checkbox" id="planToggle" onchange="handlePlanToggle()">
|
<input type="checkbox" id="planToggle" onchange="handlePlanToggle()">
|
||||||
@ -26,13 +36,41 @@ export function getInputAreaContent(): string {
|
|||||||
></textarea>
|
></textarea>
|
||||||
<div class="input-bottom-row">
|
<div class="input-bottom-row">
|
||||||
<div class="mode-selector">
|
<div class="mode-selector">
|
||||||
|
<!-- 模式选择 -->
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<select id="modeSelect">
|
<div class="custom-select" id="customSelect">
|
||||||
<option value="agent" selected>Agent</option>
|
<div class="select-trigger" onclick="toggleModeDropdown()">
|
||||||
<option value="ask">Ask</option>
|
<span class="select-value" id="selectValue">Agent</span>
|
||||||
<option value="auto">Auto</option>
|
<svg class="select-arrow" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||||
</select>
|
<path d="M507.8 727.728a30.016 30.016 0 0 1-21.288-8.824L231.104 463.496a30.088 30.088 0 0 1 0-42.568 30.088 30.088 0 0 1 42.568 0l234.128 234.128 234.16-234.128a30.088 30.088 0 0 1 42.568 0 30.088 30.088 0 0 1 0 42.568L529.08 718.904a30 30 0 0 1-21.28 8.824z" fill="#8a8a8a"/>
|
||||||
<span class="tooltiptext">切换模型</span>
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="select-dropdown" id="selectDropdown">
|
||||||
|
<div class="select-option" data-value="agent" onclick="selectMode('agent', 'Agent')">Agent</div>
|
||||||
|
<div class="select-option" data-value="ask" onclick="selectMode('ask', 'Ask')">Ask</div>
|
||||||
|
<div class="select-option" data-value="auto" onclick="selectMode('auto', 'Auto')">Auto</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="tooltiptext">切换模式</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 模型选择 -->
|
||||||
|
<div class="tooltip">
|
||||||
|
<div class="custom-select" id="modelSelect">
|
||||||
|
<div class="select-trigger" onclick="toggleModelDropdown()">
|
||||||
|
<span class="select-value" id="modelValue">Auto</span>
|
||||||
|
<svg class="select-arrow" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M507.8 727.728a30.016 30.016 0 0 1-21.288-8.824L231.104 463.496a30.088 30.088 0 0 1 0-42.568 30.088 30.088 0 0 1 42.568 0l234.128 234.128 234.16-234.128a30.088 30.088 0 0 1 42.568 0 30.088 30.088 0 0 1 0 42.568L529.08 718.904a30 30 0 0 1-21.28 8.824z" fill="#8a8a8a"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="select-dropdown" id="modelDropdown">
|
||||||
|
<div class="select-option" data-value="lite" onclick="selectModel('lite', 'Lite')">Lite</div>
|
||||||
|
<div class="select-option selected" data-value="auto" onclick="selectModel('auto', 'Auto')">Auto</div>
|
||||||
|
<div class="select-option" data-value="syntaxic" onclick="selectModel('syntaxic', 'Syntaxic')">Syntaxic</div>
|
||||||
|
<div class="select-option" data-value="max" onclick="selectModel('max', 'Max')">Max</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<span class="tooltiptext">选择模型</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-actions">
|
<div class="input-actions">
|
||||||
@ -123,11 +161,44 @@ export function getInputAreaStyles(): string {
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
/* Plan 开关样式 */
|
/* 顶部工具栏样式 */
|
||||||
.plan-toggle-container {
|
.input-top-toolbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: space-between;
|
||||||
margin-bottom: -4px;
|
align-items: center;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加上下文按钮样式 */
|
||||||
|
.add-context-button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
background: rgba(128, 128, 128, 0.2);
|
||||||
|
border: 1px solid var(--vscode-input-border);
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-context-button:hover {
|
||||||
|
background: rgba(128, 128, 128, 0.3);
|
||||||
|
border-color: var(--vscode-focusBorder);
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-context-button svg {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-context-label {
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.plan-toggle {
|
.plan-toggle {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -182,26 +253,77 @@ export function getInputAreaStyles(): string {
|
|||||||
.mode-selector {
|
.mode-selector {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
/* 自定义下拉框样式 */
|
||||||
|
.custom-select {
|
||||||
|
position: relative;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
.select-trigger {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
background: var(--vscode-input-background);
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
}
|
||||||
|
.select-trigger:hover {
|
||||||
|
background: var(--vscode-list-hoverBackground);
|
||||||
|
}
|
||||||
|
.select-value {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.select-arrow {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
.custom-select.active .select-arrow {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
.select-dropdown {
|
||||||
|
position: absolute;
|
||||||
|
bottom: calc(100% + 2px);
|
||||||
|
left: 0;
|
||||||
|
min-width: 100%;
|
||||||
|
background: var(--vscode-dropdown-background);
|
||||||
|
border: 1px solid var(--vscode-dropdown-border);
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
z-index: 1100;
|
||||||
|
display: none;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.custom-select.active .select-dropdown {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.select-option {
|
||||||
|
padding: 6px 12px;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.select-option:hover {
|
||||||
|
background: rgba(128, 128, 128, 0.3);
|
||||||
|
}
|
||||||
|
.select-option.selected {
|
||||||
|
background: rgba(128, 128, 128, 0.5);
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
}
|
||||||
.input-actions {
|
.input-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
.mode-selector select {
|
|
||||||
padding: 2px 4px;
|
|
||||||
background: var(--vscode-input-background);
|
|
||||||
color: var(--vscode-foreground);
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 12px;
|
|
||||||
outline: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
.mode-selector select:hover {
|
|
||||||
background: var(--vscode-list-hoverBackground);
|
|
||||||
}
|
|
||||||
/* Tooltip 样式 */
|
/* Tooltip 样式 */
|
||||||
.tooltip {
|
.tooltip {
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -468,15 +590,109 @@ export function getInputAreaScript(): string {
|
|||||||
messageInput.focus();
|
messageInput.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 自定义下拉框相关变量
|
||||||
|
let currentMode = 'agent';
|
||||||
|
let currentModel = 'auto';
|
||||||
|
|
||||||
|
// 切换模式下拉框显示/隐藏
|
||||||
|
function toggleModeDropdown() {
|
||||||
|
const customSelect = document.getElementById('customSelect');
|
||||||
|
const modelSelect = document.getElementById('modelSelect');
|
||||||
|
if (customSelect) {
|
||||||
|
customSelect.classList.toggle('active');
|
||||||
|
// 关闭模型下拉框
|
||||||
|
if (modelSelect) {
|
||||||
|
modelSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换模型下拉框显示/隐藏
|
||||||
|
function toggleModelDropdown() {
|
||||||
|
const modelSelect = document.getElementById('modelSelect');
|
||||||
|
const customSelect = document.getElementById('customSelect');
|
||||||
|
if (modelSelect) {
|
||||||
|
modelSelect.classList.toggle('active');
|
||||||
|
// 关闭模式下拉框
|
||||||
|
if (customSelect) {
|
||||||
|
customSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择模式
|
||||||
|
function selectMode(value, label) {
|
||||||
|
currentMode = value;
|
||||||
|
const selectValue = document.getElementById('selectValue');
|
||||||
|
if (selectValue) {
|
||||||
|
selectValue.textContent = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新选中状态
|
||||||
|
const options = document.querySelectorAll('#selectDropdown .select-option');
|
||||||
|
options.forEach(option => {
|
||||||
|
if (option.getAttribute('data-value') === value) {
|
||||||
|
option.classList.add('selected');
|
||||||
|
} else {
|
||||||
|
option.classList.remove('selected');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 关闭下拉框
|
||||||
|
const customSelect = document.getElementById('customSelect');
|
||||||
|
if (customSelect) {
|
||||||
|
customSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择模型
|
||||||
|
function selectModel(value, label) {
|
||||||
|
currentModel = value;
|
||||||
|
const modelValue = document.getElementById('modelValue');
|
||||||
|
if (modelValue) {
|
||||||
|
modelValue.textContent = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新选中状态
|
||||||
|
const options = document.querySelectorAll('#modelDropdown .select-option');
|
||||||
|
options.forEach(option => {
|
||||||
|
if (option.getAttribute('data-value') === value) {
|
||||||
|
option.classList.add('selected');
|
||||||
|
} else {
|
||||||
|
option.classList.remove('selected');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 关闭下拉框
|
||||||
|
const modelSelect = document.getElementById('modelSelect');
|
||||||
|
if (modelSelect) {
|
||||||
|
modelSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击外部关闭下拉框
|
||||||
|
document.addEventListener('click', (event) => {
|
||||||
|
const customSelect = document.getElementById('customSelect');
|
||||||
|
const modelSelect = document.getElementById('modelSelect');
|
||||||
|
|
||||||
|
if (customSelect && !customSelect.contains(event.target)) {
|
||||||
|
customSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modelSelect && !modelSelect.contains(event.target)) {
|
||||||
|
modelSelect.classList.remove('active');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
const text = messageInput.value.trim();
|
const text = messageInput.value.trim();
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
const modeSelect = document.getElementById('modeSelect');
|
const mode = currentMode;
|
||||||
const mode = modeSelect ? modeSelect.value : 'agent';
|
const model = currentModel;
|
||||||
|
|
||||||
addMessage(text, 'user');
|
addMessage(text, 'user');
|
||||||
vscode.postMessage({ command: 'sendMessage', text: text, mode: mode });
|
vscode.postMessage({ command: 'sendMessage', text: text, mode: mode, model: model });
|
||||||
messageInput.value = '';
|
messageInput.value = '';
|
||||||
autoResizeTextarea(); // 重置输入框高度
|
autoResizeTextarea(); // 重置输入框高度
|
||||||
messageInput.focus();
|
messageInput.focus();
|
||||||
@ -485,6 +701,12 @@ export function getInputAreaScript(): string {
|
|||||||
resetOptimizeButton();
|
resetOptimizeButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加上下文处理函数
|
||||||
|
function handleAddContext() {
|
||||||
|
// 发送添加上下文请求到扩展
|
||||||
|
vscode.postMessage({ command: 'addContext' });
|
||||||
|
}
|
||||||
|
|
||||||
// Plan 开关处理函数
|
// Plan 开关处理函数
|
||||||
function handlePlanToggle() {
|
function handlePlanToggle() {
|
||||||
const planToggle = document.getElementById('planToggle');
|
const planToggle = document.getElementById('planToggle');
|
||||||
|
|||||||
Reference in New Issue
Block a user