Skip to content

Commit

Permalink
Hide air popover in code view (summernote#3609)
Browse files Browse the repository at this point in the history
* feature: hide popover when codeview activated
* feature: add codeView escape
  • Loading branch information
roseline124 authored Feb 22, 2020
1 parent f5113a5 commit 4be52ec
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/js/base/core/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const KEY_MAP = {
'BACKSPACE': 8,
'TAB': 9,
'ENTER': 13,
'ESCAPE': 27,
'SPACE': 32,
'DELETE': 46,

Expand Down
7 changes: 7 additions & 0 deletions src/js/base/module/AirPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export default class AirPopover {
}
}

updateCodeview(isCodeview) {
this.ui.toggleBtnActive(this.$popover.find('.btn-codeview'), isCodeview);
if (isCodeview) {
this.hide();
}
}

hide() {
if (this.hidable) {
this.$popover.hide();
Expand Down
14 changes: 13 additions & 1 deletion src/js/base/module/Codeview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import env from '../core/env';
import dom from '../core/dom';
import env from '../core/env';
import key from '../core/key';

let CodeMirror;
if (env.hasCodeMirror) {
Expand All @@ -25,6 +26,14 @@ export default class CodeView {
}
}

initialize() {
this.$codable.on('keyup', (event) => {
if (event.keyCode === key.code.ESCAPE) {
this.deactivate();
}
});
}

/**
* @return {Boolean}
*/
Expand Down Expand Up @@ -82,6 +91,8 @@ export default class CodeView {
this.$codable.height(this.$editable.height());

this.context.invoke('toolbar.updateCodeview', true);
this.context.invoke('airPopover.updateCodeview', true);

this.$editor.addClass('codeview');
this.$codable.focus();

Expand Down Expand Up @@ -143,6 +154,7 @@ export default class CodeView {
this.$editable.focus();

this.context.invoke('toolbar.updateCodeview', false);
this.context.invoke('airPopover.updateCodeview', false);
}

destroy() {
Expand Down
1 change: 1 addition & 0 deletions src/js/base/module/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Editor {
this.bullet = new Bullet();
this.history = new History(context);

this.context.memo('help.escape', this.lang.help.escape);
this.context.memo('help.undo', this.lang.help.undo);
this.context.memo('help.redo', this.lang.help.redo);
this.context.memo('help.tab', this.lang.help.tab);
Expand Down
2 changes: 2 additions & 0 deletions src/js/base/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ $.summernote = $.extend($.summernote, {

keyMap: {
pc: {
'ESC': 'escape',
'ENTER': 'insertParagraph',
'CTRL+Z': 'undo',
'CTRL+Y': 'redo',
Expand Down Expand Up @@ -276,6 +277,7 @@ $.summernote = $.extend($.summernote, {
},

mac: {
'ESC': 'escape',
'ENTER': 'insertParagraph',
'CMD+Z': 'undo',
'CMD+SHIFT+Z': 'redo',
Expand Down
1 change: 1 addition & 0 deletions src/js/base/summernote-en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ $.extend($.summernote.lang, {
extraKeys: 'Extra keys',
},
help: {
'escape': 'Escape',
'insertParagraph': 'Insert Paragraph',
'undo': 'Undoes the last command',
'redo': 'Redoes the last command',
Expand Down

0 comments on commit 4be52ec

Please sign in to comment.