Skip to content

Commit

Permalink
Merge pull request #1990 from citizenos/#1984
Browse files Browse the repository at this point in the history
FIX #1984
  • Loading branch information
ilmartyrk authored Feb 27, 2025
2 parents 4fa986e + d300fee commit 92aca62
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions src/app/directives/markdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class MarkdownDirective {
action: (editor: any) => {
if (!editor.isPreviewActive()) {
EasyMDE.togglePreview(editor);
console.log('PREVIEW');
editor.toolbarElements.write.classList.remove('tab-active');
}
},
Expand Down Expand Up @@ -77,19 +76,19 @@ export class MarkdownDirective {
'|',
{
name: 'strikethrough',
action: EasyMDE.toggleStrikethrough,
action: this.toggleStrikethrough(),
className: 'fa md-right fa-strikethrough',
title: this.Translate.instant('MDEDITOR_TOOLTIP_STRIKETHROUGH'),
},
{
name: 'italic',
action: EasyMDE.toggleItalic,
action: this.toggleItalic(),
className: 'md-right fa fa-italic',
title: this.Translate.instant('MDEDITOR_TOOLTIP_ITALIC'),
},
{
name: 'bold',
action: EasyMDE.toggleBold,
action: this.toggleBold(),
className: 'md-right fa fa-bold',
title: this.Translate.instant('MDEDITOR_TOOLTIP_BOLD'),
},
Expand Down Expand Up @@ -153,6 +152,51 @@ export class MarkdownDirective {
});
}

trimSelection() {
const editor = this.easymde;
if (!editor.codemirror || editor.isPreviewActive()) {
return;
}
const cm = editor.codemirror;
if (!cm || editor.isPreviewActive()) {
return;
}

const startPoint = cm.getCursor('start');
const endPoint = cm.getCursor('end');
const text = cm.getSelection().trim();
cm.replaceSelection(text);

endPoint.ch = startPoint.ch + text.length + 1;
cm.setSelection(startPoint, endPoint);
cm.focus();
}

toggleStrikethrough() {
return () => {
const editor = this.easymde;
this.trimSelection();
EasyMDE.toggleStrikethrough(editor);
}
}

toggleItalic() {
return () => {
const editor = this.easymde;
this.trimSelection();
EasyMDE.toggleItalic(editor);
}
}

toggleBold() {
return () => {
const editor = this.easymde;
this.trimSelection();
EasyMDE.toggleBold(editor);
}
}


toggleLink() {
return () => {
const selected = this.easymde.codemirror.getSelection();
Expand All @@ -164,7 +208,6 @@ export class MarkdownDirective {

linkDialog.afterClosed().subscribe({
next: (data) => {
console.log(data);
if (data) {
if (!data.link) {
return;
Expand Down

0 comments on commit 92aca62

Please sign in to comment.