Skip to content

Commit

Permalink
fix: overflow text and wrong event target in viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
js87zz committed Dec 21, 2021
1 parent c63fe9a commit 96b7016
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion apps/editor/src/markdown/mdPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ class MarkdownPreview {

this.initEvent(highlight);
this.initContentSection();

// To prevent overflowing contents in the viewer
if (this.isViewer) {
this.previewContent.style.overflowWrap = 'break-word';
}
}

private initContentSection() {
this.previewContent = createElementWith(
`<div class="${cls('contents')}"></div>`
) as HTMLElement;
this.el!.appendChild(this.previewContent);

if (!this.isViewer) {
this.el!.appendChild(this.previewContent);
}
}

private toggleActive(active: boolean) {
Expand All @@ -103,6 +111,10 @@ class MarkdownPreview {
private initEvent(highlight: boolean) {
this.eventEmitter.listen('updatePreview', this.update.bind(this));

if (this.isViewer) {
return;
}

if (highlight) {
this.eventEmitter.listen('changeToolbarState', ({ mdNode, cursorPos }) => {
this.updateCursorNode(mdNode, cursorPos);
Expand Down
2 changes: 1 addition & 1 deletion apps/editor/src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ToastUIEditorViewer {
isViewer: true,
});

on(this.preview.el!, 'mousedown', this.toggleTask.bind(this));
on(this.preview.previewContent!, 'mousedown', this.toggleTask.bind(this));

if (initialValue) {
this.setMarkdown(initialValue);
Expand Down

0 comments on commit 96b7016

Please sign in to comment.