<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> from kivy . event import EventDispatcher <EOL> import string <EOL> class CodeNavigationBehavior ( EventDispatcher ) : <EOL> '''<STR_LIT>''' <EOL> def _move_cursor_word_left ( self , index = None ) : <EOL> pos = index or self . cursor_index ( ) <EOL> pos -= <NUM_LIT:1> <EOL> if pos == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> , <NUM_LIT:0> <EOL> col , row = self . get_cursor_from_index ( pos ) <EOL> lines = self . _lines <EOL> ucase = string . ascii_uppercase <EOL> lcase = string . ascii_lowercase <EOL> ws = string . whitespace <EOL> punct = string . punctuation <EOL> mode = '<STR_LIT>' <EOL> rline = lines [ row ] <EOL> c = rline [ col ] if len ( rline ) > col else '<STR_LIT:\n>' <EOL> if c in ws : <EOL> mode = '<STR_LIT>' <EOL> elif c == '<STR_LIT:_>' : <EOL> mode = '<STR_LIT>' <EOL> elif c in punct : <EOL> mode = '<STR_LIT>' <EOL> elif c not in ucase : <EOL> mode = '<STR_LIT>' <EOL> while True : <EOL> if col == - <NUM_LIT:1> : <EOL> if row == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> , <NUM_LIT:0> <EOL> row -= <NUM_LIT:1> <EOL> rline = lines [ row ] <EOL> col = len ( rline ) <EOL> lc = c <EOL> c = rline [ col ] if len ( rline ) > col else '<STR_LIT:\n>' <EOL> if c == '<STR_LIT:\n>' : <EOL> if lc not in ws : <EOL> col += <NUM_LIT:1> <EOL> break <EOL> if mode in ( '<STR_LIT>' , '<STR_LIT>' ) and c in ws : <EOL> col += <NUM_LIT:1> <EOL> break <EOL> if mode in ( '<STR_LIT>' , '<STR_LIT>' ) and c in punct : <EOL> col += <NUM_LIT:1> <EOL> break <EOL> if mode == '<STR_LIT>' and c in ucase : <EOL> break <EOL> if mode == '<STR_LIT>' and ( c == '<STR_LIT:_>' or c not in punct ) : <EOL> col += <NUM_LIT:1> <EOL> break <EOL> if mode == '<STR_LIT>' and c != '<STR_LIT:_>' and ( c in punct or c in ws ) : <EOL> col += <NUM_LIT:1> <EOL> break <EOL> if mode == '<STR_LIT>' and c != '<STR_LIT:_>' : <EOL> mode = ( '<STR_LIT>' if c in ucase <EOL> else '<STR_LIT>' if c in ws <EOL> else '<STR_LIT>' ) <EOL> elif mode == '<STR_LIT>' and c not in ws : <EOL> mode = ( '<STR_LIT>' if c in ucase <EOL> else '<STR_LIT>' if c == '<STR_LIT:_>' <EOL> else '<STR_LIT>' if c in punct <EOL> else '<STR_LIT>' ) <EOL> col -= <NUM_LIT:1> <EOL> if col > len ( rline ) : <EOL> if row == len ( lines ) - <NUM_LIT:1> : <EOL> return row , len ( lines [ row ] ) <EOL> row += <NUM_LIT:1> <EOL> col = <NUM_LIT:0> <EOL> return col , row <EOL> def _move_cursor_word_right ( self , index = None ) : <EOL> pos = index or self . cursor_index ( ) <EOL> col , row = self . get_cursor_from_index ( pos ) <EOL> lines = self . _lines <EOL> mrow = len ( lines ) - <NUM_LIT:1> <EOL> if row == mrow and col == len ( lines [ row ] ) : <EOL> return col , row <EOL> ucase = string . ascii_uppercase <EOL> lcase = string . ascii_lowercase <EOL> ws = string . whitespace <EOL> punct = string . punctuation <EOL> mode = '<STR_LIT>' <EOL> rline = lines [ row ] <EOL> c = rline [ col ] if len ( rline ) > col else '<STR_LIT:\n>' <EOL> if c in ws : <EOL> mode = '<STR_LIT>' <EOL> elif c == '<STR_LIT:_>' : <EOL> mode = '<STR_LIT>' <EOL> elif c in punct : <EOL> mode = '<STR_LIT>' <EOL> elif c in lcase : <EOL> mode = '<STR_LIT>' <EOL> while True : <EOL> if mode in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) and c in ws : <EOL> mode = '<STR_LIT>' <EOL> elif mode in ( '<STR_LIT>' , '<STR_LIT>' ) and c == '<STR_LIT:_>' : <EOL> mode = '<STR_LIT>' <EOL> elif mode == '<STR_LIT>' and c not in ucase : <EOL> mode = '<STR_LIT>' <EOL> if mode == '<STR_LIT>' : <EOL> if c in ws : <EOL> mode = '<STR_LIT>' <EOL> elif c != '<STR_LIT:_>' : <EOL> break <EOL> if mode == '<STR_LIT>' and c not in ws : <EOL> break <EOL> if mode == '<STR_LIT>' and c in ucase : <EOL> break <EOL> if mode == '<STR_LIT>' and ( c == '<STR_LIT:_>' or c not in punct ) : <EOL> break <EOL> if mode != '<STR_LIT>' and c != '<STR_LIT:_>' and c in punct : <EOL> break <EOL> col += <NUM_LIT:1> <EOL> if col > len ( rline ) : <EOL> if row == mrow : <EOL> return len ( rline ) , mrow <EOL> row += <NUM_LIT:1> <EOL> rline = lines [ row ] <EOL> col = <NUM_LIT:0> <EOL> c = rline [ col ] if len ( rline ) > col else '<STR_LIT:\n>' <EOL> if c == '<STR_LIT:\n>' : <EOL> break <EOL> return col , row </s>
