From 4880835bf1fe84dd6fe99ae990514ca78e785509 Mon Sep 17 00:00:00 2001 From: serr Date: Wed, 5 Feb 2025 23:08:48 +0300 Subject: [PATCH] =?UTF-8?q?/text=20->=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20text=20=D0=BE=D1=82=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B9=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D0=B8=20=D0=B4=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=86?= =?UTF-8?q?=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0,=20=3Ftext=20->=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B8=20text=20=D0=BE=D1=82=20=D1=82=D0=B5=D0=BA=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B0=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mvc/controllers.py | 1 + mvc/models.py | 22 ++++++++++++++++++++++ mvc/views.py | 1 + tools.py | 13 +++++++++++++ 4 files changed, 37 insertions(+) diff --git a/mvc/controllers.py b/mvc/controllers.py index 8ec8405..83b161c 100644 --- a/mvc/controllers.py +++ b/mvc/controllers.py @@ -112,6 +112,7 @@ class NormalStrategy(BaseStrategy): case self.adapter.KEY_y: if self.model.CombinationCheck("yy", 3): self.model.CopyLine() case self.adapter.KEY_x: self.model.DeleteNext() + case self.adapter.KEY_U: self.model.RecoverLine() case self.adapter.KEY_G: num, ind = tools.ExtracrtNumBeforeLastKey(''.join([chr(item[0]) for item in self.model.keyLog])) if num != None and ind != None: diff --git a/mvc/models.py b/mvc/models.py index 233e020..c28127e 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -201,6 +201,24 @@ class VimModel: # Переход на строку по введенному номеру elif cmd.isdigit(): self.MoveToLine(int(cmd)) + # Поиск строки от курсора до конца файла + elif len(cmd) > 1 and cmd[0] == '/': + index = tools.findSublistIndex(self.displayBuffer, + list(cmd[1:]), + self.currentLine, + direction=1) + if index != -1: + self.currentLine = index + self.currentCol = 0 + # Поиск строки от курсора до начала файла + elif len(cmd) > 1 and cmd[0] == '?': + index = tools.findSublistIndex(self.displayBuffer, + list(cmd[1:]), + self.currentLine, + direction=0) + if index != -1: + self.currentLine = index + self.currentCol = 0 return ReturnCode.GOOD @@ -265,6 +283,10 @@ class VimModel: """Обновляет дамп данных""" self.dump = [sublist.copy() for sublist in self.displayBuffer] + def RecoverLine(self) -> None: + self.displayBuffer[self.currentLine] = self.dump[self.currentLine].copy() + self.currentCol = 0 + def LoadFile(self, file_path) -> None: """Загрузка файла для редактирования""" self.Reset() diff --git a/mvc/views.py b/mvc/views.py index 7ea4fd3..4851ed2 100644 --- a/mvc/views.py +++ b/mvc/views.py @@ -10,6 +10,7 @@ class CursesAdapter: self.KEY_NULL = 48 self.KEY_TWO_DOTS = 59 self.KEY_G = 71 + self.KEY_U = 85 self.KEY_XOR = 94 self.KEY_b = 98 self.KEY_d = 100 diff --git a/tools.py b/tools.py index e19ba24..a724ff6 100644 --- a/tools.py +++ b/tools.py @@ -1,5 +1,18 @@ import time, re +def findSublistIndex(main_list, sublist, start_index=0, direction=1): + start_index = max(0, min(start_index, len(main_list) - 1)) + + if direction == 1: # forward + for index in range(start_index+1, len(main_list)): + if main_list[index] == sublist: + return index + else: # backward + for index in range(start_index-1, -1, -1): + if main_list[index] == sublist: + return index + return -1 + def ExtracrtNumBeforeLastKey(s): numbers_list = list(re.finditer(r'\d+', s)) if numbers_list: