-
Notifications
You must be signed in to change notification settings - Fork 0
Delete 'content' variable from MarkdownEditor Class for synchronization
Related with #9.
In order for the WYSIWYG MarkdownEditor to be seen as a UI, the getComponent() function must be called.
/**
* Returns a component which represents the editor in UI.
*/
@Override
public @NotNull JComponent getComponent() {
//jTextPane.setText(makeHtmlWithCss("<center><u>Text</u></center>" + content));
jTextPane.setText(Utils.stringToHtml(content));
return jTextPane;
}
The getComponent() function sets the content variable with the most up-to-date text value to the text of the jTextPane and returns the jTextPane.
//Markdown to Editor
private void setContentFromFile()
{
try {
content = VfsUtil.loadText(file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
The problem is that the time when the content is updated is when the tab is changed.This means that if you modify the editor's text (modify the text value of jTextPane) while the Editor tab is open and you do not select another tab, the content is no longer up-to-date.

If the editor tries to end the project without moving the tab after modifying the text, the getComponent() function is called and the content is set to the editor's text rather than the latest value, causing the correction to be rolled back.
//Markdown to Editor
private void updateEditor()
{
try {
EditorText.setText(VfsUtil.loadText(file));//Change jTextPane variable name to 'EditorText'
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Returns a component which represents the editor in UI.
*/
@Override
public @NotNull JComponent getComponent() {
return EditorText;
}
As above, the problem was solved by deleting the content variable and implementing the editor's corrections so that they could be applied immediately.