Remove maintain_selection_offset Flag
#5857
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please review the following checklist.
Hey 👋
I am combining realtime syncing provided by
pycrdtwith theTextAreawidget and I am pretty impressed by how little code it takes to adapt the widget to my needs, given the complexity ofsrc/textual/document/*.pyandsrc/textual/widgets/_text_area.py.Good job, @darrenburns!
Background Story
The edit flow in the released
TextAreawidget is:with
maintain_selection_offsetdeciding inEdit.dowhether the current selection gets shifted/moved (True) or set as cursor to the end of the edit (False).However, this edit flow is not compatible to CRDTs in
pycrdt.Changes to those CRDTs are announced via callbacks with event objects passed holding the information about a particular change.
For the
Text-CRDT, there is theTextEventevent object holding info about which text range has been deleted and where a particular piece of text has been inserted.This mechanism requires text manipulation on the
TextAreawidget - from the user via keyboard, the API or as update message from remote - to be done with the information given in the callback.It does not provide a way of transporting arbitrary/app-specific metadata, especially not allowing to pass
maintain_selection_offsetflag:I thereby started experimenting whether I could get decent functionality without
maintain_selection_offset.What I Changed
I removed
maintain_selection_offsetfrom the API.Edits via the API (
insert,delete) do not automatically set theTextAreaselection as a cursor to the end of the edit anymore (maintain_selection_offset = Falsebefore), but keep the current selection.See also tests for
ctrl + u(delete to line start)comparison
ctrl + ubefore:


now:
and
ctrl + k(delete to line end).comparison
ctrl + kbefore:


now:
On
clear,maintain_selection_offsethad no effect.Edits deleting a range covering the current
TextAreaselection place the selection as a cursor at the end of the edit.comparison
before:

now:

Selectionnow supports the operatorsin,<,<=,>and>=forLocations (tuples).I updated the tests.
What are your thoughts, especially about the new API behavior?