Widget
elva.widgets.ytextarea.widget
Widget definition.
Classes:
-
YTextArea–Widget for displaying and manipulating text synchronized in realtime.
YTextArea(ytext, *args, **kwargs)
Bases: TextArea
Widget for displaying and manipulating text synchronized in realtime.
Parameters:
-
ytext(Text) –Y text data type holding the text.
-
args(tuple, default:()) –positional arguments passed to
TextArea. -
kwargs(dict, default:{}) –keyword arguments passed to
TextArea.
Methods:
-
code_editor–Construct a text area with coding specific settings.
-
get_index_from_binary_index–Convert the index in UTF-8 encoding to character index.
-
get_binary_index_from_index–Convert the character index to index in UTF-8 encoding.
-
get_location_from_binary_index–Convert binary index to document location.
-
get_binary_index_from_location–Convert location to binary index.
-
on_textevent–Hook called on changes in the Y text data type:
-
on_mount–Hook called on mounting.
-
on_unmount–Hook called on unmounting.
-
load_text–Load a text into the document.
-
replace–Replace part of the text in the Y text data type.
-
delete–Delete a range of text.
-
insert–Insert characters at a given location.
-
clear–Remove all content from the document.
-
undo–Undo an edit done by this widget.
-
redo–Redo an edit done by this widget.
-
move_cursor–Move the cursor to a given location and adapt the scroll position.
Attributes:
-
DEFAULT_CSS–Default CSS.
-
ytext(Text) –The Y Text data type holding the text.
-
origin(int) –The own origin of edits.
-
history(UndoManager) –The history manager for undo and redo operations.
Source code in src/elva/widgets/ytextarea/widget.py
DEFAULT_CSS = '\n YTextArea {\n border: none;\n padding: 0;\n background: transparent;\n\n &:focus {\n border: none;\n }\n }\n '
class-attribute
instance-attribute
Default CSS.
ytext = ytext
instance-attribute
The Y Text data type holding the text.
origin = ytext.doc.client_id
instance-attribute
The own origin of edits.
history = UndoManager(scopes=[ytext], capture_timeout_millis=300)
instance-attribute
The history manager for undo and redo operations.
code_editor(ytext, *args, **kwargs)
classmethod
Construct a text area with coding specific settings.
Parameters:
-
ytext(Text) –the Y Text data type holding the text.
-
args(tuple, default:()) –positional arguments passed to
TextArea. -
kwargs(dict, default:{}) –keyword arguments passed to
TextArea.
Returns:
Source code in src/elva/widgets/ytextarea/widget.py
get_index_from_binary_index(index)
get_binary_index_from_index(index)
get_location_from_binary_index(index)
Convert binary index to document location.
Parameters:
-
index(int) –index in the UTF-8 encoded text.
Returns:
-
tuple–a location with containing row and column coordinates.
Source code in src/elva/widgets/ytextarea/widget.py
get_binary_index_from_location(location)
Convert location to binary index.
Parameters:
-
location(tuple) –row and column coordinates.
Returns:
-
int–the index in the UTF-8 encoded text.
Source code in src/elva/widgets/ytextarea/widget.py
on_textevent(event)
Hook called on changes in the Y text data type:
It parses the event and applies the edit to the document.
Parameters:
-
event(TextEvent) –an object holding edit information.
Source code in src/elva/widgets/ytextarea/widget.py
on_mount()
Hook called on mounting.
It adds a subscription to changes in the Y text data type.
on_unmount()
Hook called on unmounting.
It cancels the subscription to changes in the Y text data type.
load_text(text, language=None)
Load a text into the document.
Parameters:
-
text(str) –the text to display.
-
language(str | None, default:None) –the tree-sitter syntax highlighting language to use.
Source code in src/elva/widgets/ytextarea/widget.py
replace(insert, start, end)
Replace part of the text in the Y text data type.
Parameters:
-
insert(str) –the characters to insert.
-
start(tuple) –the start location of the deletion range.
-
end(tuple) –the end location of the deletion range.
Source code in src/elva/widgets/ytextarea/widget.py
delete(start, end)
insert(text, location=None)
clear()
_replace_via_keyboard(insert, start, end)
Guard method respecting the read_only
attribute before calling replace
to replace a range of text.
Parameters:
-
insert(str) –the characters to insert.
-
start(tuple) –the start location of the deletion range.
-
end(tuple) –the end location of the deletion range.
Source code in src/elva/widgets/ytextarea/widget.py
_delete_via_keyboard(start, end)
Guard method respecting the read_only
attribute before calling replace
to delete a range of text.
Parameters:
-
start(tuple) –the start location of the deletion range.
-
end(tuple) –the end location of the deletion range.
Source code in src/elva/widgets/ytextarea/widget.py
_apply_update(text, start, end)
Apply a Y text data type update to the document.
Parameters:
-
text(str) –the characters to insert.
-
start(tuple) –the start location of the deletion range.
-
end(tuple) –the end location of the deletion range.
Source code in src/elva/widgets/ytextarea/widget.py
_edit(text, top, bottom)
Perform the edit operation.
Parameters:
-
text(str) –the characters to insert.
-
top(tuple) –the minimum of start and end location of the deletion range.
-
bottom(tuple) –the maximum of start and end location of the deletion range.
Returns:
-
tuple[Selection, tuple, tuple, tuple]–the updated selection, top and bottom locations as well as the end location of the insertion range.
Source code in src/elva/widgets/ytextarea/widget.py
undo()
redo()
_watch_language(new)
Hook called on change in the language attribute.
Parameters:
-
new(str | None) –the new language.
Source code in src/elva/widgets/ytextarea/widget.py
_watch_has_focus(new)
Hook called on change of the has_focus attribute.
Parameters:
-
new(bool) –the new value.
Source code in src/elva/widgets/ytextarea/widget.py
_on_mouse_down(event)
async
Hook on a pressed mouse button.
Parameters:
-
event(MouseDown) –an object containing event information.
Source code in src/elva/widgets/ytextarea/widget.py
move_cursor(location, select=False, center=False, record_width=True)
Move the cursor to a given location and adapt the scroll position.
Parameters:
-
location(tuple) –the location to move the cursor to
-
select(bool, default:False) –flag whether to expand the current selection or just move the cursor.
-
center(bool, default:False) –flag whether to scroll the view.
-
record_width(bool, default:True) –flag whether to record the cursor width.