From cffa12f07e087e092394014b0a58adb9575859b8 Mon Sep 17 00:00:00 2001 From: serr Date: Wed, 5 Feb 2025 01:02:33 +0300 Subject: [PATCH] =?UTF-8?q?o=20filename=20->=20=D0=BE=D1=82=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D1=84=D0=B0=D0=B9=D0=BB=20fil?= =?UTF-8?q?ename,=20=D0=BD=D0=B5=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D1=8F=D1=8F=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B2=20=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mvc/models.py b/mvc/models.py index 79424df..ada82c5 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -139,6 +139,13 @@ class VimModel: self.currentLine += self.displayLinesCount else: self.currentLine = len(self.displayBuffer) - 1 + case _: + # Открывает файл + if len(cmd) > 2 and cmd[:2] == 'o ': + filename = cmd[2:] + self.LoadFile(filename) + return ReturnCode.SET_BASIC_MODE + return ReturnCode.GOOD @@ -201,10 +208,13 @@ class VimModel: def LoadFile(self, file_path) -> None: """Загрузка файла для редактирования""" + self.Reset() self.file_path = file_path + self.mode = "NORMAL" try: with open(file_path, "r") as file: self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()] + except FileNotFoundError: print(f"File {file_path} not found. Starting with empty buffer.") self.displayBuffer = [] @@ -218,3 +228,14 @@ class VimModel: print(f"File {self.file_path} saved successfully.") except Exception as e: print(f"Error saving file: {str(e)}") + + def Reset(self) -> None: + self.displayBuffer = [] + self.currentLine = 0 + self.currentCol = 0 + self.scrollY = 0 + self.scrollX = 0 + self.file_path = "" + self.mode = "" + self.commandBuffer = [] + self.exchangeBuffer = [] \ No newline at end of file