From 492288f3db2682d51d130de3b985b4697fc43ca9 Mon Sep 17 00:00:00 2001 From: serr Date: Wed, 5 Feb 2025 21:42:04 +0300 Subject: [PATCH] =?UTF-8?q?e!=20->=20=D0=BE=D1=82=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B2=D1=81=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mvc/models.py b/mvc/models.py index ec6a5fa..8039b5f 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -15,6 +15,7 @@ class VimModel: self.displayLinesCount = displayLinesCount self.displayColsCount = displayColsCount self.displayBuffer = [] # буфер для хранения всех строк + self.dump = [] self.currentLine = 0 # текущий индекс строки self.currentCol = 0 # текущий индекс колонки self.scrollY = 0 # вертикальная прокрутка @@ -154,7 +155,7 @@ class VimModel: case "wq!" | "x": # Записать в текущий файл + выйти self.SaveFile() return ReturnCode.EXIT_CODE - case "w": + case "w": # Сохраняет файл self.SaveFile() case "i": # Вход в режим редактирования return ReturnCode.SET_EDIT_MODE @@ -171,6 +172,8 @@ class VimModel: case "h": self.LoadFile("config/usage.txt") return ReturnCode.SET_BASIC_MODE + case "e!": + self.displayBuffer = [sublist.copy() for sublist in self.dump] case _: # Открывает файл filename if len(cmd) > 2 and cmd[:2] == 'o ': @@ -247,6 +250,10 @@ class VimModel: self.currentLine += 1 self.currentCol = min(self.currentCol, len(self.displayBuffer[self.currentLine])) + def Dump(self) -> None: + """Обновляет дамп данных""" + self.dump = [sublist.copy() for sublist in self.displayBuffer] + def LoadFile(self, file_path) -> None: """Загрузка файла для редактирования""" self.Reset() @@ -255,6 +262,7 @@ class VimModel: try: with open(file_path, "r") as file: self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()] + self.Dump() except FileNotFoundError: print(f"File '{file_path}' not found. Starting with empty buffer.") self.displayBuffer = [] @@ -276,6 +284,7 @@ class VimModel: def Reset(self) -> None: self.displayBuffer = [] + self.dump = [] self.currentLine = 0 self.currentCol = 0 self.scrollY = 0