e! -> отменяет все изменения
parent
6f262438a9
commit
492288f3db
|
@ -15,6 +15,7 @@ class VimModel:
|
||||||
self.displayLinesCount = displayLinesCount
|
self.displayLinesCount = displayLinesCount
|
||||||
self.displayColsCount = displayColsCount
|
self.displayColsCount = displayColsCount
|
||||||
self.displayBuffer = [] # буфер для хранения всех строк
|
self.displayBuffer = [] # буфер для хранения всех строк
|
||||||
|
self.dump = []
|
||||||
self.currentLine = 0 # текущий индекс строки
|
self.currentLine = 0 # текущий индекс строки
|
||||||
self.currentCol = 0 # текущий индекс колонки
|
self.currentCol = 0 # текущий индекс колонки
|
||||||
self.scrollY = 0 # вертикальная прокрутка
|
self.scrollY = 0 # вертикальная прокрутка
|
||||||
|
@ -154,7 +155,7 @@ class VimModel:
|
||||||
case "wq!" | "x": # Записать в текущий файл + выйти
|
case "wq!" | "x": # Записать в текущий файл + выйти
|
||||||
self.SaveFile()
|
self.SaveFile()
|
||||||
return ReturnCode.EXIT_CODE
|
return ReturnCode.EXIT_CODE
|
||||||
case "w":
|
case "w": # Сохраняет файл
|
||||||
self.SaveFile()
|
self.SaveFile()
|
||||||
case "i": # Вход в режим редактирования
|
case "i": # Вход в режим редактирования
|
||||||
return ReturnCode.SET_EDIT_MODE
|
return ReturnCode.SET_EDIT_MODE
|
||||||
|
@ -171,6 +172,8 @@ class VimModel:
|
||||||
case "h":
|
case "h":
|
||||||
self.LoadFile("config/usage.txt")
|
self.LoadFile("config/usage.txt")
|
||||||
return ReturnCode.SET_BASIC_MODE
|
return ReturnCode.SET_BASIC_MODE
|
||||||
|
case "e!":
|
||||||
|
self.displayBuffer = [sublist.copy() for sublist in self.dump]
|
||||||
case _:
|
case _:
|
||||||
# Открывает файл filename
|
# Открывает файл filename
|
||||||
if len(cmd) > 2 and cmd[:2] == 'o ':
|
if len(cmd) > 2 and cmd[:2] == 'o ':
|
||||||
|
@ -247,6 +250,10 @@ class VimModel:
|
||||||
self.currentLine += 1
|
self.currentLine += 1
|
||||||
self.currentCol = min(self.currentCol, len(self.displayBuffer[self.currentLine]))
|
self.currentCol = min(self.currentCol, len(self.displayBuffer[self.currentLine]))
|
||||||
|
|
||||||
|
def Dump(self) -> None:
|
||||||
|
"""Обновляет дамп данных"""
|
||||||
|
self.dump = [sublist.copy() for sublist in self.displayBuffer]
|
||||||
|
|
||||||
def LoadFile(self, file_path) -> None:
|
def LoadFile(self, file_path) -> None:
|
||||||
"""Загрузка файла для редактирования"""
|
"""Загрузка файла для редактирования"""
|
||||||
self.Reset()
|
self.Reset()
|
||||||
|
@ -255,6 +262,7 @@ class VimModel:
|
||||||
try:
|
try:
|
||||||
with open(file_path, "r") as file:
|
with open(file_path, "r") as file:
|
||||||
self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()]
|
self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()]
|
||||||
|
self.Dump()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"File '{file_path}' not found. Starting with empty buffer.")
|
print(f"File '{file_path}' not found. Starting with empty buffer.")
|
||||||
self.displayBuffer = []
|
self.displayBuffer = []
|
||||||
|
@ -276,6 +284,7 @@ class VimModel:
|
||||||
|
|
||||||
def Reset(self) -> None:
|
def Reset(self) -> None:
|
||||||
self.displayBuffer = []
|
self.displayBuffer = []
|
||||||
|
self.dump = []
|
||||||
self.currentLine = 0
|
self.currentLine = 0
|
||||||
self.currentCol = 0
|
self.currentCol = 0
|
||||||
self.scrollY = 0
|
self.scrollY = 0
|
||||||
|
|
Loading…
Reference in New Issue