修改优化

This commit is contained in:
JenniferW 2025-08-15 17:36:33 +08:00
parent be2c60ead0
commit f6f2db9fe7
1 changed files with 33 additions and 30 deletions

View File

@ -410,19 +410,26 @@ const findCursorConditionIndex = () => {
const cursorPos = inputEl.selectionStart;
const inputValue = currentInput.value;
const parts = inputValue.split(/[;]/);
let currentLength = 0;
for (let i = 0; i < parts.length; i++) {
//
const partLength = parts[i].length + 1;
if (cursorPos <= currentLength + partLength) {
return i;
}
currentLength += partLength;
//
const semicolons = [];
const semicolonRegex = /[;]/g;
let match;
//
while ((match = semicolonRegex.exec(inputValue)) !== null) {
semicolons.push(match.index);
}
return parts.length - 1;
//
for (let i = 0; i < semicolons.length; i++) {
if (cursorPos <= semicolons[i]) {
return i;
}
}
//
return semicolons.length;
};
//
@ -765,24 +772,21 @@ const getOperator = (conditionValue) => {
return operators.find((op) => conditionValue.startsWith(op));
};
// - 13
//
// selectSuggestion
const selectSuggestion = (item) => {
// 使
const targetIndex = findCursorConditionIndex();
if (targetIndex === -1) return;
const parts = currentInput.value.split(/[;]/);
//
let targetIndex = parts.length - 1;
// 使
if (parts.length > 0 && parts[targetIndex].trim() === "") {
targetIndex = Math.max(0, parts.length - 2);
}
let targetPart = parts[targetIndex] || "";
if (item.type === "field") {
// :
// :
parts[targetIndex] = `${item.label}:`;
} else {
//
//
const colonIndex = targetPart.indexOf(":");
const operator = getOperator(targetPart.split(":").pop() || "");
@ -799,15 +803,15 @@ const selectSuggestion = (item) => {
//
parts[targetIndex] = `${fieldPart}${item.label}`;
}
// 1
parts[targetIndex] += ";";
} else {
//
parts[targetIndex] = item.label;
}
// 1
parts[targetIndex] += ";";
//
const lastChar = parts[targetIndex].slice(-1);
if (![",", ";", ""].includes(lastChar)) {
parts[targetIndex] += ";"; // 使
}
}
@ -819,21 +823,20 @@ const selectSuggestion = (item) => {
handleInput(currentInput.value);
}, 0);
//
//
searchInput.value.focus();
const inputEl = searchInput.value.$el.querySelector("input");
if (inputEl) {
//
//
let cursorPos = 0;
for (let i = 0; i < targetIndex; i++) {
cursorPos += parts[i].length + 1; // +1
}
cursorPos += parts[targetIndex].length;
cursorPos += parts[targetIndex].length; //
inputEl.setSelectionRange(cursorPos, cursorPos);
}
};
//
const navigateSuggestions = (direction) => {
if (!showSuggestions.value || suggestions.value.length === 0) return;