-
Notifications
You must be signed in to change notification settings - Fork 236
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
Custom EditableStyledDocument #277
Changes from 1 commit
1eb8e5a
a8f0f44
f4e111f
5583d52
bbf8efc
277b548
fc48bae
4ec6411
2f55e40
9aa1a8b
fb39977
89af8ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,13 @@ public interface EditableStyledDocument<PS, S> extends StyledDocument<PS, S> { | |
|
||
ReadOnlyStyledDocument<PS, S> snapshot(); | ||
|
||
EventStream<PlainTextChange> plainChanges(); | ||
default EventStream<PlainTextChange> plainChanges() { | ||
return richChanges() | ||
// map is used to prevent code repetition: StyledDocument#getText() | ||
.map(c -> new PlainTextChange(c.position, c.removed.getText(), c.inserted.getText())) | ||
// filter out rich changes where the style was changed but text wasn't added/removed | ||
.filter(pc -> !pc.removed.equals(pc.inserted)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is a rich-text change, then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be more efficient to filter it first? Otherwise, we're creating unneeded default EventStream<PlainTextChange> plainChanges() {
return richChanges()
// exclude style changes
.filter(c -> !c.inserted.getText().equals(c.removed.getText()))
.map(c -> new PlainTextChange(c.position, c.removed.getText(), c.inserted.getText()));
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, slightly. On the other hand there is a slight repetition of code in calling And if you want to avoid an intermediate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah... I noticed that, too. One way to get around it 😜 default EventStream<PlainTextChange> plainChanges() {
return richChanges()
// exclude style changes
.map(c -> {
String inserted = c.inserted.getText();
String removed = c.removed.getText();
if (!inserted.equals(removed)) {
return new PlainTextChange(c.position, removed, inserted);
} else {
return null;
}
})
.filter(c -> c != null);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't care so much, do what you think is right ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't care too much about optimizing one object allocation, since there are already other much higher costs paid anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the most recent approach used, does that lead to higher costs due to the EventStreams? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you do care 😉 Ok. I didn't factor that into consideration. Code clarity it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I do care, when I see how much noise 4e6ce6b adds in the name of saving one object allocation per change. Also, code comments can go out of sync with code very easily, so self-documenting code is better :) |
||
|
||
EventStream<RichTextChange<PS, S>> richChanges(); | ||
|
||
|
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.
Out of context of our previous discussion, this comment does not make much sense, does it? ;)
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 suppose not... should it be removed entirely?