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