From d5f70ecba1cdcfbd5e686cbdf1c67185285b88c3 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Tue, 20 Dec 2016 17:34:30 +0100 Subject: [PATCH] Update word_utils.py --- src/fenrir/utils/word_utils.py | 61 +++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/fenrir/utils/word_utils.py b/src/fenrir/utils/word_utils.py index 8a5e5632..4b2d10c0 100644 --- a/src/fenrir/utils/word_utils.py +++ b/src/fenrir/utils/word_utils.py @@ -7,35 +7,6 @@ from core import debug import string -def getPrevWord(currX,currY, currText): - lineBreak = False - endOfScreen = False - if currText == '': - return -1, -1, '', endOfScreen, lineBreak - if currText.strip( string.whitespace) == '': - return currX, currY, '', endOfScreen, lineBreak - x, y, currWord, endOfScreen, lineBreakCurrWord = getCurrentWord(currX,currY,currText) - if endOfScreen: - return x, y, currWord, endOfScreen, lineBreak - wrappedLines = currText.split('\n') - 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 - def getCurrentWord(currX,currY, currText): lineBreak = False endOfScreen = False @@ -74,11 +45,39 @@ def getCurrentWord(currX,currY, currText): for d in string.whitespace: delimiterPos = currWord.find(d) if delimiterPos != -1: - currWord = currWord[:delimiterPos] - + currWord = currWord[:delimiterPos] return x, y, currWord, endOfScreen, lineBreak return currX, currY, '', False, False +def getPrevWord(currX,currY, currText): + lineBreak = False + endOfScreen = False + if currText == '': + return -1, -1, '', endOfScreen, lineBreak + if currText.strip( string.whitespace) == '': + return currX, currY, '', endOfScreen, lineBreak + x, y, currWord, endOfScreen, lineBreakCurrWord = getCurrentWord(currX,currY,currText) + if endOfScreen: + return x, y, currWord, endOfScreen, lineBreak + wrappedLines = currText.split('\n') + 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 + def getNextWord(currX,currY, currText): lineBreak = False endOfScreen = False