remove sledi prestuplenya

This commit is contained in:
MeexReay 2025-03-22 00:03:43 +03:00
parent 9e1a1adcc8
commit b4bb5b6dff

View File

@ -79,34 +79,32 @@ function getCursorIndex() {
let length = strippedLine.length; let length = strippedLine.length;
if (y === cursor_pos[1]) { if (y === cursor_pos[1]) {
let visiblePos = cursor_pos[0]; // Где курсор в ОЧИЩЕННОМ тексте let visiblePos = cursor_pos[0];
let realPos = 0; // Где он должен быть в ИСХОДНОМ тексте let realPos = 0;
let visibleCount = 0; // Сколько обычных символов прошло let visibleCount = 0;
for (let i = 0; i < line.length; i++) { for (let i = 0; i < line.length; i++) {
if (line[i] === "$") { if (line[i] === "$") {
// Проверяем, начинается ли тут цветовой код
let match = line.substring(i).match(/^(\$#([0-9a-fA-F]{6})|\$[A-Z_]+--|\$reset)/); let match = line.substring(i).match(/^(\$#([0-9a-fA-F]{6})|\$[A-Z_]+--|\$reset)/);
if (match) { if (match) {
i += match[0].length - 1; // Перепрыгиваем цветовой код i += match[0].length - 1;
realPos += match[0].length; realPos += match[0].length;
continue; continue;
} }
} }
// Если мы дошли до позиции курсора в очищенном тексте
if (visibleCount === visiblePos) { if (visibleCount === visiblePos) {
return index + realPos; return index + realPos;
} }
visibleCount++; // Считаем обычные символы visibleCount++;
realPos++; // Считаем индекс в исходном тексте realPos++;
} }
return index + realPos; // Если курсор стоит в конце строки return index + realPos;
} }
index += line.length + 1; // +1 за \n index += line.length + 1;
} }
return index; return index;