-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an edit_ops.rs file #1263
Add an edit_ops.rs file #1263
Conversation
sorry I didn't notice this and fixed the various lints separately, want to rebase and I'll take a look? |
in editor.rs in terms of edit_ops.rs. Moved a missed function.
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I have a few preliminary comments, let me know what you think and I'll take another look.
/// A trait from which lines and columns in a document can be calculated | ||
/// into offsets inside a rope an vice versa. | ||
pub trait LineOffset { | ||
// use own breaks if present, or text if not (no line wrapping) | ||
|
||
/// Returns the byte offset corresponding to the given visual line. | ||
/// Returns the byte offset corresponding to the given line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visual
is an important distinction, here; it indicates a distinction from 'logical' lines, which are just lines that end in a newline character. a 'visual' line may not end in a line break, and may be the result of word wrap.
I guess this whole comment is slightly out of date, having been moved from view.rs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LineOffset
deals with both visual lines and logical lines, so this comment is indeed out of date.
I don't think that one trait coming with two behaviours is ideal in the long run,
but perhaps there is a way out of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so this was an intentional choice, to the best of my recollection; the idea is that in the absence of line breaks, the hard breaks are the visual lines. This means that all edit ops can work with just a buffer, but things 'just work' when you add a view?
It may be that this isn't helpful, but that was the original thinking.
rust/rope/src/delta.rs
Outdated
@@ -16,6 +16,8 @@ | |||
//! It's useful to explicitly represent these operations so they can be | |||
//! shared across multiple subsystems. | |||
|
|||
#![allow(clippy::many_single_char_names)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this to be on a specific function of that is possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
rust/core-lib/src/backspace.rs
Outdated
if !region.is_caret() { | ||
region.min() | ||
} else { | ||
// backspace deletes max(1, tab_size) contiguous spaces | ||
let (_, c) = view.offset_to_line_col(&text, region.start); | ||
let (_, c) = DefaultLineOffset.offset_to_line_col(&text, region.start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be changing the behaviour? by not using the view we may get different results here when word wrap is enabled. I'm not sure if this is a problem in practice, but it feels fishy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
view.line_of_offset
calls lines.visual_line_of_offset
, so different behaviour on word wrap was the default and the change a bugfix (see PR summary).
I've renamed DefaultLineOffset
to LogicalLines
, which should make the change more obvious (and DefaultLineOffset
more descriptive).
rust/core-lib/src/editor.rs
Outdated
builder.replace(interval, Rope::from(capitalized_text)); | ||
Transpose => { | ||
let delta = edit_ops::transpose(&self.text, regions); | ||
if !delta.is_identity() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to set EditType::Transpose
here. It is probably worth doing another close read and make sure the edit type is correct in other places as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. There was indeed another case, but I belive that got them all.
(Are we testing undo and redo behaviour?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few tests around recording that exercise undo/redo, but overall not really. 😒
if start > 0 && self.text.byte_at(start - 1) == (b'-') { | ||
start -= 1; | ||
match cmd { | ||
Delete { movement, kill } => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reading through this patch, I think my personal inclination would be to keep using the separate do_$thing
methods, and then just in those methods call out to edit_ops
; a major advantage of this approach is that it makes this diff easier to read and verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reversed this.
I didn't want multiple related functions with the same name doing different things when I made this. For now, the functions in editor.rs
that call edit_ops.rs
functions have the do_
-prefix, while the functions in edit_ops.rs
do not have that prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great yea this was the intended pattern originally; do_
meant that "this is the entry point for some command".
Codecov Report
@@ Coverage Diff @@
## master #1263 +/- ##
==========================================
+ Coverage 71.09% 71.39% +0.29%
==========================================
Files 81 83 +2
Lines 14961 14812 -149
==========================================
- Hits 10637 10575 -62
+ Misses 4324 4237 -87
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, this looks good to me, and is a helpful bit of cleanup. I'm currently working on text stuff in druid, and may at some point soon want to figure out a way to use some core xi stuff (edit ops, selections, movement) there. I'm not sure if this will mean moving that stuff to its own crate, or adding a default feature without which we only include some minimum set of things.
I'll leave this up for a minute in case you have further tweaks to make, and you can ping me when you'd like it merged.
I don't have any further tweaks to make. Please go ahead and merge. |
Thanks! |
Summary
This PR does the following:
View
to operate, but take a&[SelRegion]
instead.longer has to construct a
View
to use them for these functions.View
not just to get selections, but also for functionslike
offset_of_line
to get the lines. In case ofView
these are visual lines, not logical ones.Activating word wrap thus changed their behaviour, with special mention to
duplicate_line
, which was extremly broken. By making them think in logical lines,many previously undiscovered bugs have been fixed.
cargo test --all
/./rust/run_all_checks
.