From 5cf89f71f98b4c93b44b16fd7972cca5cc740c19 Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 4 Feb 2025 20:50:47 +0300 Subject: [PATCH] =?UTF-8?q?w=20-=20=D1=81=D0=BC=D0=B5=D1=89=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D1=80=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D0=B5=D1=86=20=D1=81=D0=BB=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B0=20=D0=BE=D1=82=20=D0=BA?= =?UTF-8?q?=D1=83=D1=80=D1=81=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/controllers.py | 7 +++---- mvc/models.py | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/mvc/controllers.py b/mvc/controllers.py index 87a594e..c44c56f 100644 --- a/mvc/controllers.py +++ b/mvc/controllers.py @@ -48,12 +48,11 @@ class CommandStrategy(BaseStrategy): """Обработка ввода пользователя""" result = self.handle_common_input(symbolCode) if result != ReturnCode.CONTINUE: return result + returnCode = ReturnCode.GOOD match symbolCode: case self.adapter.KEY_ENTER: - code = self.model.EnterCommand() - self.model.Scroll(self.adapter.lines, self.adapter.cols) - return code + returnCode = self.model.EnterCommand() case self.adapter.KEY_BACKSPACE_1 | self.adapter.KEY_BACKSPACE_2: self.model.BackspaceCommand() case _: @@ -61,7 +60,7 @@ class CommandStrategy(BaseStrategy): self.model.InsertCommandSymbol(symbolCode) self.model.Scroll(self.adapter.lines, self.adapter.cols) - return ReturnCode.GOOD + return returnCode class EditStrategy(BaseStrategy): """Режим редактирования""" diff --git a/mvc/models.py b/mvc/models.py index 03c9dc0..4d18887 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -49,39 +49,50 @@ class VimModel: cmd = ''.join(self.commandBuffer) self.commandBuffer.clear() match cmd: - case "$": - self.currentCol = len(self.displayBuffer[self.currentLine]) # Перемещение в конец строки + case "$": # Перемещение в конец строки + self.currentCol = len(self.displayBuffer[self.currentLine]) return ReturnCode.GOOD - case "^" | "0": - self.currentCol = 0 # Перемещение в начало строки + case "^" | "0": # Перемещение в начало строки + self.currentCol = 0 return ReturnCode.GOOD - case "q": + case "q": # Выход из программы return ReturnCode.EXIT_CODE - case "i": + case "i": # Вход в режим редактирования return ReturnCode.SET_EDIT_MODE - case "S": + case "S": # Удаление строки на которой курсор и вход в режим редактирования self.currentCol = 0 self.displayBuffer[self.currentLine] = [] return ReturnCode.SET_EDIT_MODE - case "RIGHT": + case "RIGHT": # Перемещение курсора на 1 позицию вправо self.currentCol += 1 return ReturnCode.GOOD - case "LEFT": + case "LEFT": # Перемещение курсора на 1 позицию влево if self.currentCol > 0: self.currentCol -= 1 return ReturnCode.GOOD - case "UP": + case "UP": # Перемещение курсора на 1 пизицию вверх if self.currentLine > 0: self.currentLine -= 1 if self.currentCol > len(self.displayBuffer[self.currentLine]): self.currentCol = len(self.displayBuffer[self.currentLine]) return ReturnCode.GOOD - case "DOWN": + case "DOWN": # Перемещение курсора на 1 пизицию вниз if self.currentLine < len(self.displayBuffer) - 1: self.currentLine += 1 if self.currentCol > len(self.displayBuffer[self.currentLine]): self.currentCol = len(self.displayBuffer[self.currentLine]) return ReturnCode.GOOD + case "w": # Перемещение курсора в конец слова справа от курсора + line = ''.join(self.displayBuffer[self.currentLine]) + # Находим ближайший непробельный символ + non_space_index = next((i for i, char in enumerate(line[self.currentCol:]) if char != ' '), None) + if non_space_index is not None: + non_space_index += self.currentCol + right_space_index = line.find(' ', non_space_index) + if right_space_index != -1: + self.currentCol = right_space_index + else: + self.currentCol = len(self.displayBuffer[self.currentLine]) def Enter(self) -> None: # Разделяем текущую строку на две части