Skip to content

Commit

Permalink
feat(TextEditSelecter): add __getitem__
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Jun 6, 2023
1 parent 3a810d9 commit b5cacb6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion prettyqt/utils/texteditselecter.py
Expand Up @@ -29,6 +29,18 @@ def __init__(self, widget):
self.search_buffer: str | None = None
self.search_flags = None

def __getitem__(self, index: int | slice):
doc = self._widget.document()
if isinstance(index, int):
return doc.findBlockByNumber(index)
start = doc.findBlockByNumber(index.start)
end = doc.findBlockByNumber(index.stop)
blocks = [start]
while start != end:
start = start.next()
blocks.append(start)
return blocks

def goto_line(self, line_no: int, end_pos: Literal["top", "bottom"] | None = None):
doc = self._widget.document()
match end_pos:
Expand Down Expand Up @@ -251,5 +263,5 @@ def replace_block_at_cursor(self, new_text: str):
test.show()
with app.debug_mode():
app.sleep(2)
test.selecter.goto_line(50, end_pos="top")
print(test.selecter[20:50])
app.main_loop()

0 comments on commit b5cacb6

Please sign in to comment.