o filename -> открывает файл filename, не сохраняя изменения в текущем файле
parent
7e5c5d3723
commit
cffa12f07e
|
@ -139,6 +139,13 @@ class VimModel:
|
|||
self.currentLine += self.displayLinesCount
|
||||
else:
|
||||
self.currentLine = len(self.displayBuffer) - 1
|
||||
case _:
|
||||
# Открывает файл
|
||||
if len(cmd) > 2 and cmd[:2] == 'o ':
|
||||
filename = cmd[2:]
|
||||
self.LoadFile(filename)
|
||||
return ReturnCode.SET_BASIC_MODE
|
||||
|
||||
|
||||
return ReturnCode.GOOD
|
||||
|
||||
|
@ -201,10 +208,13 @@ class VimModel:
|
|||
|
||||
def LoadFile(self, file_path) -> None:
|
||||
"""Загрузка файла для редактирования"""
|
||||
self.Reset()
|
||||
self.file_path = file_path
|
||||
self.mode = "NORMAL"
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()]
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"File {file_path} not found. Starting with empty buffer.")
|
||||
self.displayBuffer = []
|
||||
|
@ -218,3 +228,14 @@ class VimModel:
|
|||
print(f"File {self.file_path} saved successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error saving file: {str(e)}")
|
||||
|
||||
def Reset(self) -> None:
|
||||
self.displayBuffer = []
|
||||
self.currentLine = 0
|
||||
self.currentCol = 0
|
||||
self.scrollY = 0
|
||||
self.scrollX = 0
|
||||
self.file_path = ""
|
||||
self.mode = ""
|
||||
self.commandBuffer = []
|
||||
self.exchangeBuffer = []
|
Loading…
Reference in New Issue