w - смещает курсор в конец слова справа от курсора
parent
8e711e95ae
commit
5cf89f71f9
|
@ -48,12 +48,11 @@ class CommandStrategy(BaseStrategy):
|
|||
"""Обработка ввода пользователя"""
|
||||
result = self.handle_common_input(symbolCode)
|
||||
if result != ReturnCode.CONTINUE: return result
|
||||
returnCode = ReturnCode.GOOD
|
||||
|
||||
match symbolCode:
|
||||
case self.adapter.KEY_ENTER:
|
||||
code = self.model.EnterCommand()
|
||||
self.model.Scroll(self.adapter.lines, self.adapter.cols)
|
||||
return code
|
||||
returnCode = self.model.EnterCommand()
|
||||
case self.adapter.KEY_BACKSPACE_1 | self.adapter.KEY_BACKSPACE_2:
|
||||
self.model.BackspaceCommand()
|
||||
case _:
|
||||
|
@ -61,7 +60,7 @@ class CommandStrategy(BaseStrategy):
|
|||
self.model.InsertCommandSymbol(symbolCode)
|
||||
|
||||
self.model.Scroll(self.adapter.lines, self.adapter.cols)
|
||||
return ReturnCode.GOOD
|
||||
return returnCode
|
||||
|
||||
class EditStrategy(BaseStrategy):
|
||||
"""Режим редактирования"""
|
||||
|
|
|
@ -49,39 +49,50 @@ class VimModel:
|
|||
cmd = ''.join(self.commandBuffer)
|
||||
self.commandBuffer.clear()
|
||||
match cmd:
|
||||
case "$":
|
||||
self.currentCol = len(self.displayBuffer[self.currentLine]) # Перемещение в конец строки
|
||||
case "$": # Перемещение в конец строки
|
||||
self.currentCol = len(self.displayBuffer[self.currentLine])
|
||||
return ReturnCode.GOOD
|
||||
case "^" | "0":
|
||||
self.currentCol = 0 # Перемещение в начало строки
|
||||
case "^" | "0": # Перемещение в начало строки
|
||||
self.currentCol = 0
|
||||
return ReturnCode.GOOD
|
||||
case "q":
|
||||
case "q": # Выход из программы
|
||||
return ReturnCode.EXIT_CODE
|
||||
case "i":
|
||||
case "i": # Вход в режим редактирования
|
||||
return ReturnCode.SET_EDIT_MODE
|
||||
case "S":
|
||||
case "S": # Удаление строки на которой курсор и вход в режим редактирования
|
||||
self.currentCol = 0
|
||||
self.displayBuffer[self.currentLine] = []
|
||||
return ReturnCode.SET_EDIT_MODE
|
||||
case "RIGHT":
|
||||
case "RIGHT": # Перемещение курсора на 1 позицию вправо
|
||||
self.currentCol += 1
|
||||
return ReturnCode.GOOD
|
||||
case "LEFT":
|
||||
case "LEFT": # Перемещение курсора на 1 позицию влево
|
||||
if self.currentCol > 0:
|
||||
self.currentCol -= 1
|
||||
return ReturnCode.GOOD
|
||||
case "UP":
|
||||
case "UP": # Перемещение курсора на 1 пизицию вверх
|
||||
if self.currentLine > 0:
|
||||
self.currentLine -= 1
|
||||
if self.currentCol > len(self.displayBuffer[self.currentLine]):
|
||||
self.currentCol = len(self.displayBuffer[self.currentLine])
|
||||
return ReturnCode.GOOD
|
||||
case "DOWN":
|
||||
case "DOWN": # Перемещение курсора на 1 пизицию вниз
|
||||
if self.currentLine < len(self.displayBuffer) - 1:
|
||||
self.currentLine += 1
|
||||
if self.currentCol > len(self.displayBuffer[self.currentLine]):
|
||||
self.currentCol = len(self.displayBuffer[self.currentLine])
|
||||
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:
|
||||
# Разделяем текущую строку на две части
|
||||
|
|
Loading…
Reference in New Issue