Skip to content
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

Extract operations on buffer into line buffer #71

Merged
merged 10 commits into from
Jun 21, 2021

Conversation

nixypanda
Copy link
Contributor

#61 (comment)

The basic idea here is to pull out the functionality of editing into line_buffer.

- Renamed insert_char -> insert_char_at
- Renamed insert_str -> insert_str_at, Modified the interface to use
  insertion_point instead of insertion_point.offset
- Added insert_char: this also modifies the insertion_point in addition
  to chaning the buffer
- Added insert_str: this also modifies the insertion_point in addition
  to chaning the buffer

Question: Do we really need insert_char_at and insert_str_at?
- Rename backspace -> delete_grapheme_left
- Rename delete -> delete_grapheme_right
Copy link
Contributor Author

@nixypanda nixypanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only added basic tests for now as I want to know what you folks think about this. If it looks alright then I can add more tests to this.

Comment on lines 150 to 153
/// Insert a single character at the given cursor postion
pub fn insert_char(&mut self, pos: InsertionPoint, c: char) {
pub fn insert_char_at(&mut self, pos: InsertionPoint, c: char) {
self.lines[pos.line].insert(pos.offset, c)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we don't really have a use-case where the newly created insert_char is not sufficient, we can remove this method from the public interface and only use that.

Reasoning:
It leads to an inconsistent internal state and the user has to be cognizant about making sure that the insertion point is updated properly. I think we should only expose this sort of API if there is something we can't do with the high-level API that we have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can express everything pub with codepoint/grapheme safe moves and edits based on the current insertion point state, less weird unicode failure points 👍
For internal stuff we might still want to use it for performance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now there is not really any place we are making use of this internally so, I am removing this for now. If there is a use for this we can re-add this. Is that ok?

src/line_buffer.rs Show resolved Hide resolved
src/line_buffer.rs Show resolved Hide resolved
src/line_buffer.rs Show resolved Hide resolved
assert_eq!(expected_line_buffer, line_buffer);
}
}

#[test]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this now.

Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to rebase this on #62 with EditEngine or keep the other PR as a draft for a little bit longer? Would be fine to merge into main as well.

Regarding tests, in 08ff9c1 I wrote some doctests for most of the functions, but didn't end up merging that upstrream as doctests don't run on private parts and the API would change anyway. But might have some inspiration for what we might test in the future.

Comment on lines 150 to 153
/// Insert a single character at the given cursor postion
pub fn insert_char(&mut self, pos: InsertionPoint, c: char) {
pub fn insert_char_at(&mut self, pos: InsertionPoint, c: char) {
self.lines[pos.line].insert(pos.offset, c)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can express everything pub with codepoint/grapheme safe moves and edits based on the current insertion point state, less weird unicode failure points 👍
For internal stuff we might still want to use it for performance reasons.

src/line_buffer.rs Outdated Show resolved Hide resolved
src/line_buffer.rs Show resolved Hide resolved
src/line_buffer.rs Show resolved Hide resolved
src/engine.rs Outdated Show resolved Hide resolved
src/engine.rs Outdated Show resolved Hide resolved
src/line_buffer.rs Show resolved Hide resolved
@nixypanda
Copy link
Contributor Author

Do you want to rebase this on #62 with EditEngine or keep the other PR as a draft for a little bit longer? Would be fine to merge into main as well.

I was thinking that PR to just be a sort of discussion point where we can try out a few ideas and not necessarily get it merged. If we try to get that merged it might block other contributors, which is something I would like to avoid. We can extract the bits that make sense there into smaller PRs that way we make continuous progress. Moreover, the more I think about that, the less convinced I am about the inheritance hierarchy that I have created there.
So, I would prefer we get this one merged first.

@nixypanda nixypanda force-pushed the extract-stuff-into-line-buffer branch from 10b4ea0 to af487f9 Compare June 21, 2021 12:58
@nixypanda nixypanda marked this pull request as ready for review June 21, 2021 13:01
@sholderbach
Copy link
Member

@sherubthakur Ready to merge?

@nixypanda
Copy link
Contributor Author

@sherubthakur Ready to merge?

Yup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants