| 1 | import bpy, re |
| 2 | |
| 3 | class TextBlock: |
| 4 | def __init__(self, text_block): |
| 5 | if text_block is None: raise AttributeError() |
| 6 | self.text_block = text_block |
| 7 | |
| 8 | @property |
| 9 | def current_line(self): |
| 10 | return self.text_block.current_line.body |
| 11 | @current_line.setter |
| 12 | def current_line(self, text): |
| 13 | self.text_block.current_line.body = text |
| 14 | |
| 15 | @property |
| 16 | def cursor_position(self): |
| 17 | return self.current_line_index, self.current_character_index |
| 18 | @cursor_position.setter |
| 19 | def cursor_position(self, position): |
| 20 | self.current_line_index = position[0] |
| 21 | self.current_character_index = position[1] |
| 22 | |
| 23 | @property |
| 24 | def current_character_index(self): |
| 25 | return self.get_character_index() |
| 26 | @current_character_index.setter |
| 27 | def current_character_index(self, index): |
| 28 | self.set_cursor_position_horizontal(index) |
| 29 | |
| 30 | @property |
| 31 | def current_line_index(self): |
| 32 | return self.get_line_index() |
| 33 | @current_line_index.setter |
| 34 | def current_line_index(self, index): |
| 35 | self.set_cursor_position_vertical(index) |
| 36 | |
| 37 | @property |
| 38 | def line_amount(self): |
| 39 | return len(self.text_block.lines) |
| 40 | |
| 41 | @property |
| 42 | def text_before_cursor(self): |
| 43 | return self.current_line[:self.current_character_index] |
| 44 | |
| 45 | @property |
| 46 | def current_word(self): |
| 47 | return self.get_last_word(self.text_before_cursor) |
| 48 | |
| 49 | @property |
| 50 | def lines(self): |
| 51 | return self.get_all_lines() |
| 52 | @lines.setter |
| 53 | def lines(self, lines): |
| 54 | cursor_position = self.cursor_position |
| 55 | text = "\n".join(lines) |
| 56 | self.text_block.from_string(text) |
| 57 | self.cursor_position = cursor_position |
| 58 | |
| 59 | def get_all_lines(self): |
| 60 | lines = [] |
no outgoing calls
no test coverage detected