diw -> удаляет слово под курсором

master
serr 2025-02-04 23:12:19 +03:00
parent b17ecd7fce
commit e22f700468
1 changed files with 23 additions and 10 deletions

View File

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