/text -> поиск строки text от текущей строки до конца файла, ?text -> поиск строки text от текущей строки до начала файла
parent
0dc325466e
commit
4880835bf1
|
@ -112,6 +112,7 @@ class NormalStrategy(BaseStrategy):
|
|||
case self.adapter.KEY_y:
|
||||
if self.model.CombinationCheck("yy", 3): self.model.CopyLine()
|
||||
case self.adapter.KEY_x: self.model.DeleteNext()
|
||||
case self.adapter.KEY_U: self.model.RecoverLine()
|
||||
case self.adapter.KEY_G:
|
||||
num, ind = tools.ExtracrtNumBeforeLastKey(''.join([chr(item[0]) for item in self.model.keyLog]))
|
||||
if num != None and ind != None:
|
||||
|
|
|
@ -201,6 +201,24 @@ class VimModel:
|
|||
# Переход на строку по введенному номеру
|
||||
elif cmd.isdigit():
|
||||
self.MoveToLine(int(cmd))
|
||||
# Поиск строки от курсора до конца файла
|
||||
elif len(cmd) > 1 and cmd[0] == '/':
|
||||
index = tools.findSublistIndex(self.displayBuffer,
|
||||
list(cmd[1:]),
|
||||
self.currentLine,
|
||||
direction=1)
|
||||
if index != -1:
|
||||
self.currentLine = index
|
||||
self.currentCol = 0
|
||||
# Поиск строки от курсора до начала файла
|
||||
elif len(cmd) > 1 and cmd[0] == '?':
|
||||
index = tools.findSublistIndex(self.displayBuffer,
|
||||
list(cmd[1:]),
|
||||
self.currentLine,
|
||||
direction=0)
|
||||
if index != -1:
|
||||
self.currentLine = index
|
||||
self.currentCol = 0
|
||||
|
||||
return ReturnCode.GOOD
|
||||
|
||||
|
@ -265,6 +283,10 @@ class VimModel:
|
|||
"""Обновляет дамп данных"""
|
||||
self.dump = [sublist.copy() for sublist in self.displayBuffer]
|
||||
|
||||
def RecoverLine(self) -> None:
|
||||
self.displayBuffer[self.currentLine] = self.dump[self.currentLine].copy()
|
||||
self.currentCol = 0
|
||||
|
||||
def LoadFile(self, file_path) -> None:
|
||||
"""Загрузка файла для редактирования"""
|
||||
self.Reset()
|
||||
|
|
|
@ -10,6 +10,7 @@ class CursesAdapter:
|
|||
self.KEY_NULL = 48
|
||||
self.KEY_TWO_DOTS = 59
|
||||
self.KEY_G = 71
|
||||
self.KEY_U = 85
|
||||
self.KEY_XOR = 94
|
||||
self.KEY_b = 98
|
||||
self.KEY_d = 100
|
||||
|
|
13
tools.py
13
tools.py
|
@ -1,5 +1,18 @@
|
|||
import time, re
|
||||
|
||||
def findSublistIndex(main_list, sublist, start_index=0, direction=1):
|
||||
start_index = max(0, min(start_index, len(main_list) - 1))
|
||||
|
||||
if direction == 1: # forward
|
||||
for index in range(start_index+1, len(main_list)):
|
||||
if main_list[index] == sublist:
|
||||
return index
|
||||
else: # backward
|
||||
for index in range(start_index-1, -1, -1):
|
||||
if main_list[index] == sublist:
|
||||
return index
|
||||
return -1
|
||||
|
||||
def ExtracrtNumBeforeLastKey(s):
|
||||
numbers_list = list(re.finditer(r'\d+', s))
|
||||
if numbers_list:
|
||||
|
|
Loading…
Reference in New Issue