Skip to content

Commit

Permalink
Merge pull request #1578 from SergeyMosin/compact-composer-plugin-v1.0.4
Browse files Browse the repository at this point in the history
Compact composer plugin v1.0.4
  • Loading branch information
the-djmaze authored May 13, 2024
2 parents c0c0106 + c0d3c35 commit ad3313f
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 351 deletions.
2 changes: 1 addition & 1 deletion plugins/compact-composer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CompactComposerPlugin extends \RainLoop\Plugins\AbstractPlugin
NAME = 'Compact Composer',
AUTHOR = 'Sergey Mosin',
URL = 'https://github.com/the-djmaze/snappymail/pull/1466',
VERSION = '1.0.3',
VERSION = '1.0.4',
RELEASE = '2024-04-23',
REQUIRED = '2.34.0',
LICENSE = 'AGPL v3',
Expand Down
27 changes: 23 additions & 4 deletions plugins/compact-composer/js/CompactComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@
pasteImageHandler(e, squire);
});

wysiwyg.addEventListener('focus', () => {
const range = this.squire.getSelection();
if (range.collapsed && range.startContainer === wysiwyg) {
// when the caret is directly in the wysiwyg a bunch of stuff
// (like lists, blockquotes, etc...) do not work,
// so we need to place it inside the nearest element
if (wysiwyg.children[range.startOffset] !== undefined) {
const newRange = document.createRange();
newRange.setStart(wysiwyg.children[range.startOffset], 0);
this.squire.setSelection(newRange);
}
}
});

// squire.addEventListener('focus', () => shortcuts.off());
// squire.addEventListener('blur', () => shortcuts.on());

Expand Down Expand Up @@ -598,23 +612,23 @@
type: 'menu_item',
label: 'HTML Mode',
id: 'menu-item-mode-wysiwyg',
cmd: () => this.setMode('wysiwyg'),
cmd: () => this.setModeCmd('wysiwyg'),
showInPlainMode: true,
icon: '<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m2 2v3h1v-2h2v-1zm13 0v1h2v2h1v-3zm-9 3v10h2v-4h4v4h2v-10h-2v4h-4v-4zm-4 10v3h3v-1h-2v-2zm15 0v2h-2v1h3v-3z"/></svg>'
},
{
type: 'menu_item',
label: 'Edit Source',
id: 'menu-item-mode-source',
cmd: () => this.setMode('source'),
cmd: () => this.setModeCmd('source'),
showInPlainMode: true,
icon: '<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m12 2.83c-0.478-0.138-0.976 0.141-1.11 0.619l-3.6 12.6c-0.138 0.478 0.141 0.976 0.619 1.11 0.478 0.138 0.976-0.141 1.11-0.619l3.6-12.6c0.138-0.478-0.141-0.976-0.619-1.11zm2.27 4.65 2.51 2.51-2.51 2.51c-0.352 0.352-0.352 0.923 0 1.27 0.352 0.352 0.923 0.352 1.27 0l3.15-3.15c0.352-0.352 0.352-0.923 0-1.27l-3.15-3.15c-0.352-0.352-0.923-0.352-1.27-0.00141-0.35 0.35-0.35 0.921 0.00141 1.27zm-8.63-1.27c-0.352-0.352-0.923-0.352-1.27 0l-3.15 3.15c-0.352 0.352-0.352 0.923 0 1.27l3.15 3.15c0.352 0.352 0.923 0.352 1.27 0 0.352-0.352 0.352-0.923 0-1.27l-2.51-2.51 2.51-2.51c0.352-0.352 0.352-0.923 0-1.27z"/></svg>'
},
{
type: 'menu_item',
label: 'Plain Text Mode',
id: 'menu-item-mode-plain',
cmd: () => this.setMode('plain'),
cmd: () => this.setModeCmd('plain'),
showInPlainMode: true,
icon: '<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="m2 2v3h1v-2h2v-1zm13 0v1h2v2h1v-3zm-9 3v2h3v8h2v-8h3v-2zm-4 10v3h3v-1h-2v-2zm15 0v2h-2v1h3v-3z"/></svg>'
}
Expand Down Expand Up @@ -871,6 +885,12 @@
return validation.test(this.squire.getPath()) || this.squire.hasFormat(format);
}
*/

setModeCmd(mode) {
this.setMode(mode);
setTimeout(() => this.focus(), 1);
}

setMode(mode) {
if (this.mode !== mode) {
let cl = this.container.classList,
Expand All @@ -894,7 +914,6 @@
this.mode = mode;
cl.add('squire2-mode-' + mode);
this.onModeChange?.();
setTimeout(() => this.focus(), 1);
}
}

Expand Down
Loading

0 comments on commit ad3313f

Please sign in to comment.