n -> повторить поиск, N -> повторить поиск в обратном направлении

master
serr 2025-02-05 23:18:49 +03:00
parent 4880835bf1
commit c405e36dcf
1 changed files with 24 additions and 0 deletions

View File

@ -15,6 +15,7 @@ class VimModel:
self.displayLinesCount = displayLinesCount self.displayLinesCount = displayLinesCount
self.displayColsCount = displayColsCount self.displayColsCount = displayColsCount
self.showLineNumbers = True self.showLineNumbers = True
self.lastSearch = ()
self.displayBuffer = [] # буфер для хранения всех строк self.displayBuffer = [] # буфер для хранения всех строк
self.dump = [] self.dump = []
self.currentLine = 0 # текущий индекс строки self.currentLine = 0 # текущий индекс строки
@ -181,6 +182,26 @@ 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 "n":
if self.lastSearch != ():
index = tools.findSublistIndex(self.displayBuffer,
list(self.lastSearch[0]),
self.currentLine,
direction=self.lastSearch[1])
if index != -1:
self.currentLine = index
self.currentCol = 0
self.lastSearch = (self.lastSearch[0], self.lastSearch[1])
case "N":
if self.lastSearch != ():
index = tools.findSublistIndex(self.displayBuffer,
list(self.lastSearch[0]),
self.currentLine,
direction=(self.lastSearch[1]+1)%2)
if index != -1:
self.currentLine = index
self.currentCol = 0
self.lastSearch = (self.lastSearch[0], (self.lastSearch[1]+1)%2)
case "e!": case "e!":
self.displayBuffer = [sublist.copy() for sublist in self.dump] self.displayBuffer = [sublist.copy() for sublist in self.dump]
case "set num": case "set num":
@ -210,6 +231,7 @@ class VimModel:
if index != -1: if index != -1:
self.currentLine = index self.currentLine = index
self.currentCol = 0 self.currentCol = 0
self.lastSearch = (cmd[1:], 1)
# Поиск строки от курсора до начала файла # Поиск строки от курсора до начала файла
elif len(cmd) > 1 and cmd[0] == '?': elif len(cmd) > 1 and cmd[0] == '?':
index = tools.findSublistIndex(self.displayBuffer, index = tools.findSublistIndex(self.displayBuffer,
@ -219,6 +241,7 @@ class VimModel:
if index != -1: if index != -1:
self.currentLine = index self.currentLine = index
self.currentCol = 0 self.currentCol = 0
self.lastSearch = (cmd[1:], 0)
return ReturnCode.GOOD return ReturnCode.GOOD
@ -325,5 +348,6 @@ class VimModel:
self.scrollX = 0 self.scrollX = 0
self.file_path = "" self.file_path = ""
self.mode = "" self.mode = ""
self.lastSearch = ()
self.commandBuffer = [] self.commandBuffer = []
self.exchangeBuffer = [] self.exchangeBuffer = []