initial "new" wordWrap
This commit is contained in:
parent
4623c47137
commit
a78cb62620
@ -5,18 +5,35 @@
|
|||||||
# By Chrys, Storm Dragon, and contributers.
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
from core import debug
|
from core import debug
|
||||||
# X Y Word END BREAK
|
import string
|
||||||
# -1, -1, '', True False
|
|
||||||
def getPrevWord(currX,currY, currText):
|
def getPrevWord(currX,currY, currText):
|
||||||
lineBreak = False
|
lineBreak = False
|
||||||
endOfScreen = False
|
endOfScreen = False
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, '', endOfScreen, lineBreak
|
return -1, -1, '', endOfScreen, lineBreak
|
||||||
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(currX,currY,currText)
|
if currText.strip(string.punctuation +"§ " + string.whitespace) == '':
|
||||||
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
|
x, y, currWord, endOfScreen, lineBreakCurrWord = getCurrentWord(currX,currY,currText)
|
||||||
if endOfScreen:
|
if endOfScreen:
|
||||||
return x, y, currWord, endOfScreen, lineBreak
|
return x, y, currWord, endOfScreen, lineBreak
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
currLine = wrappedLines[y].replace("\t"," ")
|
currLine = wrappedLines[y]
|
||||||
|
if x - 1 < 0:
|
||||||
|
if y - 1 < 0:
|
||||||
|
lineBreak = False
|
||||||
|
endOfScreen = True
|
||||||
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
|
else:
|
||||||
|
y -= 1
|
||||||
|
currLine = wrappedLines[y]
|
||||||
|
x = len( wrappedLines[y]) - 1
|
||||||
|
lineBreak = True
|
||||||
|
else:
|
||||||
|
x -= 1
|
||||||
|
lineBreakCurrWord = lineBreak or lineBreakCurrWord
|
||||||
|
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(x,y,currText)
|
||||||
|
lineBreak = lineBreak or lineBreakCurrWord
|
||||||
return x, y, currWord, endOfScreen, lineBreak
|
return x, y, currWord, endOfScreen, lineBreak
|
||||||
|
|
||||||
def getCurrentWord(currX,currY, currText):
|
def getCurrentWord(currX,currY, currText):
|
||||||
@ -24,21 +41,83 @@ def getCurrentWord(currX,currY, currText):
|
|||||||
endOfScreen = False
|
endOfScreen = False
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, '', endOfScreen, lineBreak
|
return -1, -1, '', endOfScreen, lineBreak
|
||||||
|
if currText.strip(string.punctuation +"§ " + string.whitespace) == '':
|
||||||
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
x = currX
|
x = currX
|
||||||
y = currY
|
y = currY
|
||||||
currWord = ''
|
currWord = ''
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
currLine = wrappedLines[y].replace("\t"," ")
|
currLine = wrappedLines[y]
|
||||||
return x, y, currWord, endOfScreen, lineBreak
|
Found = False
|
||||||
|
while(not Found):
|
||||||
|
if not currLine[x] in string.whitespace:
|
||||||
|
if x == 0:
|
||||||
|
Found = True
|
||||||
|
else:
|
||||||
|
if currLine[x - 1] in string.whitespace:
|
||||||
|
Found = True
|
||||||
|
if not Found:
|
||||||
|
if x - 1 < 0:
|
||||||
|
if y - 1 < 0:
|
||||||
|
lineBreak = False
|
||||||
|
endOfScreen = True
|
||||||
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
|
else:
|
||||||
|
y -= 1
|
||||||
|
currLine = wrappedLines[y]
|
||||||
|
x = len( wrappedLines[y]) - 1
|
||||||
|
lineBreak = True
|
||||||
|
else:
|
||||||
|
x -= 1
|
||||||
|
if Found:
|
||||||
|
currWord = currLine[x:]
|
||||||
|
for d in string.whitespace:
|
||||||
|
delimiterPos = currWord.find(d)
|
||||||
|
if delimiterPos != -1:
|
||||||
|
currWord = currWord[:delimiterPos]
|
||||||
|
|
||||||
|
return x, y, currWord, endOfScreen, lineBreak
|
||||||
|
return currX, currY, '', False, False
|
||||||
|
|
||||||
def getNextWord(currX,currY, currText):
|
def getNextWord(currX,currY, currText):
|
||||||
lineBreak = False
|
lineBreak = False
|
||||||
endOfScreen = False
|
endOfScreen = False
|
||||||
if currText == '':
|
if currText == '':
|
||||||
return -1, -1, '', endOfScreen, lineBreak
|
return -1, -1, '', endOfScreen, lineBreak
|
||||||
x, y, currWord, endOfScreen, lineBreak = getCurrentWord(currX,currY,currText)
|
if currText.strip(string.punctuation +"§ " + string.whitespace) == '':
|
||||||
if endOfScreen:
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
return x, y, currWord, endOfScreen, lineBreak
|
x = currX
|
||||||
|
y = currY
|
||||||
|
currWord = ''
|
||||||
wrappedLines = currText.split('\n')
|
wrappedLines = currText.split('\n')
|
||||||
currLine = wrappedLines[y].replace("\t"," ")
|
currLine = wrappedLines[y]
|
||||||
return x, y, currWord, endOfScreen, lineBreak
|
Found = False
|
||||||
|
while(not Found):
|
||||||
|
if not Found:
|
||||||
|
if x + 1 > len( currLine ) - 1:
|
||||||
|
if y + 1 > len( wrappedLines ) - 1:
|
||||||
|
lineBreak = False
|
||||||
|
endOfScreen = True
|
||||||
|
return currX, currY, '', endOfScreen, lineBreak
|
||||||
|
else:
|
||||||
|
y += 1
|
||||||
|
currLine = wrappedLines[y]
|
||||||
|
x = 0
|
||||||
|
lineBreak = True
|
||||||
|
else:
|
||||||
|
x += 1
|
||||||
|
if not currLine[x] in string.whitespace:
|
||||||
|
if x == 0:
|
||||||
|
Found = True
|
||||||
|
else:
|
||||||
|
if currLine[x - 1] in string.whitespace:
|
||||||
|
Found = True
|
||||||
|
if Found:
|
||||||
|
currWord = currLine[x:]
|
||||||
|
for d in string.whitespace:
|
||||||
|
delimiterPos = currWord.find(d)
|
||||||
|
if delimiterPos != -1:
|
||||||
|
currWord = currWord[:delimiterPos]
|
||||||
|
return x, y, currWord, endOfScreen, lineBreak
|
||||||
|
return currX, currY, '', False, False
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user