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: