From 881c544fac3493b4d48611480c59ebd9624f114a Mon Sep 17 00:00:00 2001 From: MeexReay Date: Fri, 21 Mar 2025 23:55:26 +0300 Subject: [PATCH] using chatgpt for fix this dumb fucking shit --- sys/terminal.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/sys/terminal.js b/sys/terminal.js index ed0f08e..92feb2f 100644 --- a/sys/terminal.js +++ b/sys/terminal.js @@ -70,19 +70,43 @@ var cursor = document.getElementById("cursor") var cursor_pos = [0, 0] function getCursorIndex() { - let lines = terminal_text.split("\n") - let index = 0 + let lines = terminal_text.split("\n"); + let index = 0; + for (let y = 0; y < lines.length; y++) { - const line = lines[y]; - const length = line.length + let line = lines[y]; + let strippedLine = stripColors(line); + let length = strippedLine.length; if (y == cursor_pos[1]) { - return index + cursor_pos[0] + let visiblePos = cursor_pos[0]; + let realPos = 0; + let visibleCount = 0; + + // Синхронизируем позиции между оригинальным и очищенным текстом + for (let i = 0; i < line.length; i++) { + if (visibleCount === visiblePos) { + return index + realPos; + } + + if (line[i] === "\n") { + index++; + continue; + } + + if (!line.substring(i).match(/^\$#([0-9a-fA-F]{6})|^\$[A-Z_]+--|^\$reset/)) { + visibleCount++; + } + realPos++; + } + + return index + realPos; // На случай, если курсор в конце строки } - index += length + 1 + index += line.length + 1; // +1 за \n } - return index + + return index; } function getCursor() {