polish clipboard handling, clean ups, more mark functions
This commit is contained in:
parent
41caeed747
commit
acd10812c6
@ -1,11 +1,13 @@
|
||||
#!/bin/python
|
||||
from utils import mark_utils
|
||||
|
||||
try:
|
||||
from utils import mark_utils
|
||||
except Exception as e:
|
||||
print(e)
|
||||
class command():
|
||||
def __init__(self):
|
||||
pass
|
||||
def run(self, environment):
|
||||
print('run')
|
||||
|
||||
if (environment['commandBuffer']['Marks']['1'] == None) or \
|
||||
(environment['commandBuffer']['Marks']['2'] == None):
|
||||
environment['runtime']['outputManager'].presentText(environment, "two marks needed", interrupt=True)
|
||||
@ -17,12 +19,15 @@ class command():
|
||||
if environment['commandBuffer']['Marks']['3'] != None:
|
||||
endMark = environment['commandBuffer']['Marks']['3'].copy()
|
||||
|
||||
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n'))
|
||||
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'])
|
||||
|
||||
environment['commandBuffer']['clipboard'] = [marked] + environment['commandBuffer']['clipboard'][:9]
|
||||
environment['commandBuffer']['currClipboard'] = 0
|
||||
environment['commandBuffer']['Marks']['1'] = None
|
||||
environment['commandBuffer']['Marks']['2'] = None
|
||||
environment['commandBuffer']['Marks']['3'] = None
|
||||
|
||||
if marked.strip(" \t\n") == '':
|
||||
if marked.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
|
||||
char_utils.getCurrentChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currChar.strip(" \t\n") == '':
|
||||
if currChar.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank" ,interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currChar ,interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
|
||||
line_utils.getCurrentLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currLine.strip(" \t\n") == '':
|
||||
if currLine.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||
word_utils.getCurrentWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currWord.strip(" \t\n") == '':
|
||||
if currWord.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)
|
||||
|
@ -4,9 +4,6 @@ class command():
|
||||
def __init__(self):
|
||||
pass
|
||||
def run(self, environment):
|
||||
if environment['screenData']['newDelta'].strip(" \t\n") == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True)
|
||||
return environment
|
||||
def setCallback(self, callback):
|
||||
|
@ -15,7 +15,7 @@ class command():
|
||||
with open("/dev/tty" + environment['screenData']['newTTY'], 'w') as fd:
|
||||
for c in environment['commandBuffer']['clipboard'][currClipboard]:
|
||||
fcntl.ioctl(fd, termios.TIOCSTI, c)
|
||||
time.sleep(0.01)
|
||||
time.sleep(0.02)
|
||||
return environment
|
||||
def setCallback(self, callback):
|
||||
pass
|
||||
|
@ -16,9 +16,9 @@ class command():
|
||||
if environment['commandBuffer']['Marks']['3'] != None:
|
||||
endMark = environment['commandBuffer']['Marks']['3'].copy()
|
||||
|
||||
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'].split('\n'))
|
||||
marked = mark_utils.getTextBetweenMarks(startMark, endMark, environment['screenData']['newContentText'])
|
||||
|
||||
if marked.strip(" \t\n") == '':
|
||||
if marked.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, marked, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
|
||||
char_utils.getNextChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currChar.strip(" \t\n") == '':
|
||||
if currChar.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
|
||||
line_utils.getNextLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currLine.strip(" \t\n") == '':
|
||||
if currLine.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||
word_utils.getNextWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currWord.strip(" \t\n") == '':
|
||||
if currWord.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currChar = \
|
||||
char_utils.getPrevChar(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currChar.strip(" \t\n") == '':
|
||||
if currChar.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currChar, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currLine = \
|
||||
line_utils.getPrevLine(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currLine.strip(" \t\n") == '':
|
||||
if currLine.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", soundIcon='EmptyLine', interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currLine, interrupt=True)
|
||||
|
@ -12,7 +12,7 @@ class command():
|
||||
environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], currWord = \
|
||||
word_utils.getPrevWord(environment['screenData']['newCursorReview']['x'], environment['screenData']['newCursorReview']['y'], environment['screenData']['newContentText'])
|
||||
|
||||
if currWord.strip(" \t\n") == '':
|
||||
if currWord.strip() == '':
|
||||
environment['runtime']['outputManager'].presentText(environment, "blank", interrupt=True)
|
||||
else:
|
||||
environment['runtime']['outputManager'].presentText(environment, currWord, interrupt=True)
|
||||
|
@ -3,12 +3,10 @@
|
||||
def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
if inText == None:
|
||||
return ''
|
||||
if isinstance(inText, list):
|
||||
if not isinstance(inText, list):
|
||||
inText = inText.split('\n')
|
||||
if len(inText) < 1:
|
||||
return ''
|
||||
if inText == '':
|
||||
return ''
|
||||
if firstMark == None:
|
||||
return ''
|
||||
if secondMark == None:
|
||||
@ -19,30 +17,30 @@ def getTextBetweenMarks(firstMark, secondMark, inText):
|
||||
else:
|
||||
endMark = firstMark.copy()
|
||||
startMark = secondMark.copy()
|
||||
currX = startMark['x']
|
||||
currY = startMark['y']
|
||||
textPart = ''
|
||||
while currY <= endMark['y'] and currY <= len(inText):
|
||||
if startMark['y'] == endMark['y']:
|
||||
textPart += inText[currY][currX:endMark['x'] + 1]
|
||||
textPart += inText[startMark['y']][startMark['x']:endMark['x'] + 1]
|
||||
else:
|
||||
currY = startMark['y']
|
||||
while currY <= endMark['y']:
|
||||
if currY < endMark['y']:
|
||||
textPart += inText[currY][currX:]
|
||||
if currY == startMark['y']:
|
||||
textPart += inText[currY][startMark['x']:]
|
||||
else:
|
||||
textPart += inText[currY]
|
||||
if len(inText[currY].strip()) != 0:
|
||||
if len(textPart) - len(textPart[::-1].strip()) > 0:
|
||||
textPart = textPart[:len(textPart[::-1].strip())] + "\n"
|
||||
else:
|
||||
textPart += inText[currY][:currX + 1]
|
||||
currX = 0
|
||||
textPart += '\n'
|
||||
else:
|
||||
textPart += inText[currY][:endMark['x'] + 1]
|
||||
currY += 1
|
||||
return textPart
|
||||
|
||||
def getTextBeforeMark(mark, inText):
|
||||
if inText == None:
|
||||
return ''
|
||||
if isinstance(inText, list):
|
||||
inText = inText.split('\n')
|
||||
if len(inText) < 1:
|
||||
return ''
|
||||
if mark == None:
|
||||
return ''
|
||||
return getTextBetweenMarks({'x':0,'y':0}, mark, inText)
|
||||
@ -50,10 +48,6 @@ def getTextBeforeMark(mark, inText):
|
||||
def getTextAfterMark(mark, inText):
|
||||
if inText == None:
|
||||
return ''
|
||||
if isinstance(inText, list):
|
||||
inText = inText.split('\n')
|
||||
if len(inText) < 1:
|
||||
return ''
|
||||
if mark == None:
|
||||
return ''
|
||||
return getTextBetweenMarks(mark, {'x':len(inText[0])-1,'y':len(inText)-1}, inText)
|
||||
|
Loading…
Reference in New Issue
Block a user