diff --git a/mvc/models.py b/mvc/models.py index fadd738..170eb52 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -94,7 +94,7 @@ class VimModel: self.currentCol = right_space_index else: self.currentCol = len(self.displayBuffer[self.currentLine]) - case "b": # Перемещает курсор в конец в начало слова слева от курсора + case "b": # Перемещает курсор в начало слова слева от курсора line = ''.join(self.displayBuffer[self.currentLine]) non_space_index = next((i for i in range(self.currentCol - 1, -1, -1) if line[i] != ' '), None) if non_space_index is not None: @@ -115,20 +115,33 @@ class VimModel: case "yy": # копирует текущую строку self.exchangeBuffer = self.displayBuffer[self.currentLine].copy() case "yw": # Копирует слово под курсором - line = ''.join(self.displayBuffer[self.currentLine]) - start_index = line.rfind(' ', 0, self.currentCol) - start_index = 0 if start_index == -1 else start_index + 1 - end_index = line.find(' ', self.currentCol) - end_index = len(line) if end_index == -1 else end_index - self.exchangeBuffer = self.displayBuffer[self.currentLine][start_index:end_index].copy() - case "dd": # вырезает текущую строку + start_index, end_index = self.WordUnderCursor() + line = self.displayBuffer[self.currentLine] + self.exchangeBuffer = line[start_index:end_index+1] + case "diw": # Удаляет слово под курсором + start_index, end_index = self.WordUnderCursor() + line = self.displayBuffer[self.currentLine] + if end_index < len(line) and line[end_index] == ' ': + end_index += 1 + self.displayBuffer[self.currentLine] = line[:start_index] + line[end_index:] + self.currentCol = start_index + case "dd": # Вырезает текущую строку self.exchangeBuffer = self.displayBuffer[self.currentLine].copy() - del self.displayBuffer[self.currentLine] - case "p": # вставить после курсора + self.displayBuffer[self.currentLine] = [] + self.currentCol = 0 + case "p": # Вставить после курсора self.displayBuffer[self.currentLine][self.currentCol+1:self.currentCol+1] = self.exchangeBuffer return ReturnCode.GOOD + def WordUnderCursor(self)-> tuple[int, int]: + line = ''.join(self.displayBuffer[self.currentLine]) + start_index = line.rfind(' ', 0, self.currentCol) + start_index = 0 if start_index == -1 else start_index + 1 + end_index = line.find(' ', self.currentCol) + end_index = len(line) if end_index == -1 else end_index + return start_index, end_index + def Enter(self) -> None: # Разделяем текущую строку на две части new_line = self.displayBuffer[self.currentLine][self.currentCol:]