-
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
Improvement: Make insertion style a convenience generic method #209
Comments
Correct me if I'm wrong @melkhaldi, but I think this can already be done. If one wanted to do what you suggest, wouldn't they just do the following? StyledTextArea<?, ?> area = // creation code...
int start = // somewhere in the area
int end = // somewhere else in the area
S desiredStyleInsertion = //
PS desiredParagraphStyleInsertion = //
ReadOnlyStyledDocument doc = ReadOnlyStyledDocument.fromString(
"some text insertion",
desiredStyleInsertion,
desiredParagraphStyleInsertion
);
area.replace(start, end, doc); |
Hi Jordan, I believe the code example suggested above will work for replacing text. but would it work when the area receives text input (user typing)? |
Ok, that makes sense. Let me see if I understand you correctly. When you modify the text and style within the
Yes! All you'd need to do is override the EventHandler. Here's an example class RichTextArea extends StyledTextArea {
private static final EventHandlerTemplate<RichTextArea, ? super KeyEvent> KEY_TYPED_TEMPLATE;
static {
KEY_TYPED_TEMPLATE = EventHandlerTemplate
.on(KeyEvent.KEY_TYPED)
.act(RichTextArea::inserUserText)
.create();
}
RichTextArea(/* constructor params */) {
// constructor code
EventHandler<? super KeyEvent> keyTypedHandler = KEY_TYPED_TEMPLATE.bind(this);
// Note: use `install()`, not `installAfter()` here. The former applies before
// implementations of the latter, which in your case prevents it from occurring.
EventHandlerHelper.install(onKeyTypedProperty(), keyTypedHandler);
}
public void insertUserText(String text) {
IndexRange sel = getSelection();
S currentUserStyle = // get the current style used for user input
PS curretParagraphStyle = // get current style used for user input
replace(sel.getStart(), sel.getEnd(), ReadOnlyStyledDocument.fromString(
text,
currentUserStyle,
currentParagraphStyle
));
}
} If you look at
|
Yes that is correct. In my mind, if an insertion style is set as a public
|
Ok. I see what you mean. Yeah, that would just need to be implemented on top of Tomas' work. MVC vs MVVM vs MVP seem to be defined differently by different people. I can't remember which link I specifically read that explain them in detail, but this link seems helpful. I won't say whether it is or not because the differences between them are otherwise unimportant to me because they all adhere to the Separation of Concerns (the most important point), just in their own way. Also, do you know how to style your comments using GitHub-flavored Markdown? I've noticed that you tend not to style them. |
I hope you have a good time traveling 😄 |
Yes, i didn't really know about markdown in got until you mentioned it..
|
Hey @melkhaldi, did the above solution work for you? I was wondering if this issue could be closed or not. |
I guess yes! Although the implementation I am suggesting can be tagged as a
|
So, you're suggesting something like... // Properties
private PS insertionParagraphStyle;
public final void setInsertionParagraphStyle(PS style) { insertionParagraphStyle = style; }
public final PS getInsertionParagraphStyle() {
return insertionParagraphStyle == null
? initialParagraphStyle
: insertionParagraphStyle;
}
private S insertionTextStyle;
public final void setInsertionTextStyle(S style) { insertionTextStyle = style; }
public final S getInsertionTextStyle() {
return insertionTextStyle == null
? initialStyle
: insertionTextStyle;
}
public final void replaceTextWithInsertionStyle(int from, int to, String text) {
ReadOnlyStyledDocument<PS, S> doc = ReadOnlyStyledDocument.fromString(
text,
getInsertionParagraphStyle(),
getInsertionTextStyle()
);
replace(from, to, doc); |
Yes :)
|
I think this issue should be closed as the proposed method could be implemented on top of RTFX. If that's not possible due to casting issues (like if one wanted to use |
Hi Tomas, following on earlier communication. I am logging this request so that it is trackable.
Would be great if there was a way to define insertion style of new text, without having to have it be applied first to caret location.
Best,
maher
The text was updated successfully, but these errors were encountered: