пофиксил баг с UP/DOWN с большой строки на ту которая меньше
parent
94bbccde99
commit
7326aa1834
|
@ -46,19 +46,19 @@ class VimModel:
|
|||
self.displayBuffer[self.currentLine].insert(self.currentCol, chr(symbolCode))
|
||||
self.currentCol += 1
|
||||
|
||||
def MoveToLineStart(self) -> None:
|
||||
"""Переместить курсор в начало строки и сбросить прокрутку"""
|
||||
self.currentCol = 0
|
||||
self.scrollX = 0 # Сброс горизонтальной прокрутки
|
||||
|
||||
def MoveToLineEnd(self) -> None:
|
||||
"""Переместить курсор в конец строки с учетом прокрутки"""
|
||||
def MoveToPositionWithScroll(self, position: int) -> None:
|
||||
"""
|
||||
Перемещает курсор в указанную позицию в текущей строке
|
||||
и корректирует прокрутку, если это необходимо.
|
||||
"""
|
||||
line_length = len(self.displayBuffer[self.currentLine])
|
||||
self.currentCol = line_length
|
||||
self.currentCol = max(0, min(position, line_length))
|
||||
|
||||
# Если строка длиннее экрана, корректируем прокрутку
|
||||
if line_length > self.displayCols:
|
||||
self.scrollX = max(0, line_length - self.displayCols + 1)
|
||||
# Корректируем прокрутку, если курсор выходит за пределы видимой области
|
||||
if self.currentCol < self.scrollX:
|
||||
self.scrollX = self.currentCol # Прокрутка влево
|
||||
elif self.currentCol >= self.scrollX + self.displayCols:
|
||||
self.scrollX = self.currentCol - self.displayCols + 1 # Прокрутка вправо
|
||||
|
||||
def EnterCommand(self):
|
||||
"""Обработка введенной команды"""
|
||||
|
@ -66,38 +66,36 @@ class VimModel:
|
|||
self.commandBuffer.clear()
|
||||
match cmd:
|
||||
case "$":
|
||||
self.MoveToLineEnd() # Перемещение в конец строки
|
||||
self.MoveToPositionWithScroll(len(self.displayBuffer[self.currentLine])) # Перемещение в конец строки
|
||||
return ReturnCode.GOOD
|
||||
case "^" | "0":
|
||||
self.MoveToLineStart() # Перемещение в начало строки
|
||||
self.MoveToPositionWithScroll(0) # Перемещение в начало строки
|
||||
return ReturnCode.GOOD
|
||||
case "q":
|
||||
return ReturnCode.EXIT_CODE
|
||||
case "i":
|
||||
return ReturnCode.SET_EDIT_MODE
|
||||
case "S":
|
||||
self.MoveToLineStart()
|
||||
self.MoveToPositionWithScroll(0)
|
||||
self.displayBuffer[self.currentLine] = []
|
||||
return ReturnCode.SET_EDIT_MODE
|
||||
case "RIGHT":
|
||||
if self.currentCol < len(self.displayBuffer[self.currentLine]):
|
||||
self.currentCol += 1
|
||||
self.MoveToPositionWithScroll(self.currentCol + 1)
|
||||
return ReturnCode.GOOD
|
||||
case "LEFT":
|
||||
if self.currentCol > 0:
|
||||
self.currentCol -= 1
|
||||
self.MoveToPositionWithScroll(self.currentCol - 1)
|
||||
return ReturnCode.GOOD
|
||||
case "UP":
|
||||
if self.currentLine > 0:
|
||||
self.currentLine -= 1
|
||||
if self.currentCol > len(self.displayBuffer[self.currentLine]):
|
||||
self.currentCol = len(self.displayBuffer[self.currentLine])
|
||||
self.MoveToPositionWithScroll(len(self.displayBuffer[self.currentLine]))
|
||||
return ReturnCode.GOOD
|
||||
case "DOWN":
|
||||
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])
|
||||
self.MoveToPositionWithScroll(len(self.displayBuffer[self.currentLine]))
|
||||
return ReturnCode.GOOD
|
||||
|
||||
def Enter(self) -> None:
|
||||
|
|
Loading…
Reference in New Issue