add getPrevWord and fix some bugs
This commit is contained in:
parent
51ac131043
commit
9a004f27ca
@ -1,5 +1,13 @@
|
||||
#!/bin/python
|
||||
|
||||
def getPrevWord(currX,currY, currText):
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
x, y, word = getCurrentWord(currX,currY,currText)
|
||||
if (x == currX) or (y == currY) and (word == ''):
|
||||
return currX, currY, ''
|
||||
return getCurrentWord(x - 2, y, currText)
|
||||
|
||||
def getCurrentWord(currX,currY, currText):
|
||||
if currText == '':
|
||||
return -1, -1, ''
|
||||
@ -8,7 +16,15 @@ def getCurrentWord(currX,currY, currText):
|
||||
wrappedLines = currText.split('\n')
|
||||
wordFound = False
|
||||
currWord = ''
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
if x <= 0:
|
||||
if y != 0:
|
||||
y -= 1
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
else:
|
||||
return currX, currY, ''
|
||||
x = len(currLine) - 1
|
||||
else:
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
while not wordFound:
|
||||
x = currLine[:x].rfind(" ")
|
||||
if x == -1:
|
||||
@ -30,7 +46,7 @@ def getCurrentWord(currX,currY, currText):
|
||||
currLine = wrappedLines[y].replace("\t"," ")
|
||||
else:
|
||||
return currX, currY, ''
|
||||
x = len(wrappedLines[y]) - 1
|
||||
x = len(currLine) - 1
|
||||
else:
|
||||
x -= 1
|
||||
return x, y, currWord
|
||||
|
Loading…
Reference in New Issue
Block a user