w - смещает курсор в конец слова справа от курсора

master
serr 2025-02-04 20:50:47 +03:00
parent 8e711e95ae
commit 5cf89f71f9
2 changed files with 25 additions and 15 deletions

View File

@ -48,12 +48,11 @@ class CommandStrategy(BaseStrategy):
"""Обработка ввода пользователя""" """Обработка ввода пользователя"""
result = self.handle_common_input(symbolCode) result = self.handle_common_input(symbolCode)
if result != ReturnCode.CONTINUE: return result if result != ReturnCode.CONTINUE: return result
returnCode = ReturnCode.GOOD
match symbolCode: match symbolCode:
case self.adapter.KEY_ENTER: case self.adapter.KEY_ENTER:
code = self.model.EnterCommand() returnCode = self.model.EnterCommand()
self.model.Scroll(self.adapter.lines, self.adapter.cols)
return code
case self.adapter.KEY_BACKSPACE_1 | self.adapter.KEY_BACKSPACE_2: case self.adapter.KEY_BACKSPACE_1 | self.adapter.KEY_BACKSPACE_2:
self.model.BackspaceCommand() self.model.BackspaceCommand()
case _: case _:
@ -61,7 +60,7 @@ class CommandStrategy(BaseStrategy):
self.model.InsertCommandSymbol(symbolCode) self.model.InsertCommandSymbol(symbolCode)
self.model.Scroll(self.adapter.lines, self.adapter.cols) self.model.Scroll(self.adapter.lines, self.adapter.cols)
return ReturnCode.GOOD return returnCode
class EditStrategy(BaseStrategy): class EditStrategy(BaseStrategy):
"""Режим редактирования""" """Режим редактирования"""

View File

@ -49,39 +49,50 @@ class VimModel:
cmd = ''.join(self.commandBuffer) cmd = ''.join(self.commandBuffer)
self.commandBuffer.clear() self.commandBuffer.clear()
match cmd: match cmd:
case "$": case "$": # Перемещение в конец строки
self.currentCol = len(self.displayBuffer[self.currentLine]) # Перемещение в конец строки self.currentCol = len(self.displayBuffer[self.currentLine])
return ReturnCode.GOOD return ReturnCode.GOOD
case "^" | "0": case "^" | "0": # Перемещение в начало строки
self.currentCol = 0 # Перемещение в начало строки self.currentCol = 0
return ReturnCode.GOOD return ReturnCode.GOOD
case "q": case "q": # Выход из программы
return ReturnCode.EXIT_CODE return ReturnCode.EXIT_CODE
case "i": case "i": # Вход в режим редактирования
return ReturnCode.SET_EDIT_MODE return ReturnCode.SET_EDIT_MODE
case "S": case "S": # Удаление строки на которой курсор и вход в режим редактирования
self.currentCol = 0 self.currentCol = 0
self.displayBuffer[self.currentLine] = [] self.displayBuffer[self.currentLine] = []
return ReturnCode.SET_EDIT_MODE return ReturnCode.SET_EDIT_MODE
case "RIGHT": case "RIGHT": # Перемещение курсора на 1 позицию вправо
self.currentCol += 1 self.currentCol += 1
return ReturnCode.GOOD return ReturnCode.GOOD
case "LEFT": case "LEFT": # Перемещение курсора на 1 позицию влево
if self.currentCol > 0: if self.currentCol > 0:
self.currentCol -= 1 self.currentCol -= 1
return ReturnCode.GOOD return ReturnCode.GOOD
case "UP": case "UP": # Перемещение курсора на 1 пизицию вверх
if self.currentLine > 0: if self.currentLine > 0:
self.currentLine -= 1 self.currentLine -= 1
if self.currentCol > len(self.displayBuffer[self.currentLine]): if self.currentCol > len(self.displayBuffer[self.currentLine]):
self.currentCol = len(self.displayBuffer[self.currentLine]) self.currentCol = len(self.displayBuffer[self.currentLine])
return ReturnCode.GOOD return ReturnCode.GOOD
case "DOWN": case "DOWN": # Перемещение курсора на 1 пизицию вниз
if self.currentLine < len(self.displayBuffer) - 1: if self.currentLine < len(self.displayBuffer) - 1:
self.currentLine += 1 self.currentLine += 1
if self.currentCol > len(self.displayBuffer[self.currentLine]): if self.currentCol > len(self.displayBuffer[self.currentLine]):
self.currentCol = len(self.displayBuffer[self.currentLine]) self.currentCol = len(self.displayBuffer[self.currentLine])
return ReturnCode.GOOD 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: def Enter(self) -> None:
# Разделяем текущую строку на две части # Разделяем текущую строку на две части