Skip to content

Build your personal knowledge base with Trilium Notes

ctrl+enter should work only on tab detail

zadamddb99a0917ad
diff --git a/src/public/javascripts/services/note_detail_code.js b/src/public/javascripts/services/note_detail_code.js
index 34bddd3322..1403d07115 100644
--- a/src/public/javascripts/services/note_detail_code.js
+++ b/src/public/javascripts/services/note_detail_code.js
@@ -16,7 +16,7 @@ class NoteDetailCode {
this.$component = ctx.$tabContent.find('.note-detail-code');
this.$executeScriptButton = ctx.$tabContent.find(".execute-script-button");
- utils.bindShortcut("ctrl+return", () => this.executeCurrentNote());
+ utils.bindElShortcut(ctx.$tabContent, "ctrl+return", () => this.executeCurrentNote());
this.$executeScriptButton.click(() => this.executeCurrentNote());
}
diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.js
index 8c4fb474ee..1a96dd393a 100644
--- a/src/public/javascripts/services/note_type.js
+++ b/src/public/javascripts/services/note_type.js
@@ -51,7 +51,6 @@ function NoteTypeContext(ctx) {
const self = this;
this.$executeScriptButton = ctx.$tabContent.find(".execute-script-button");
- this.$toggleEditButton = ctx.$tabContent.find('.toggle-edit-button');
this.$renderButton = ctx.$tabContent.find('.render-button');
this.ctx = ctx;
@@ -178,10 +177,8 @@ function NoteTypeContext(ctx) {
};
this.updateExecuteScriptButtonVisibility = function() {
- self.$executeScriptButton.toggle(self.mime().startsWith('application/javascript'));
-
- self.$toggleEditButton.toggle(self.type() === 'render');
- self.$renderButton.toggle(self.type() === 'render');
+ self.$executeScriptButton.toggle(ctx.note.mime.startsWith('application/javascript'));
+ self.$renderButton.toggle(ctx.note.type === 'render');
};
ko.applyBindings(this, ctx.$tabContent.find('.note-type-wrapper')[0])
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 7088a2c6d0..e2636bdfc7 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -106,6 +106,10 @@ class TabContext {
}
}, 5000);
+ if (utils.isDesktop()) {
+ this.noteType.updateExecuteScriptButtonVisibility();
+ }
+
console.log(`Switched tab ${this.tabId} to ${this.noteId}`);
}
diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js
index 0bb0a8ec5d..65ef0295f4 100644
--- a/src/public/javascripts/services/utils.js
+++ b/src/public/javascripts/services/utils.js
@@ -130,13 +130,17 @@ function randomString(len) {
}
function bindShortcut(keyboardShortcut, handler) {
+ bindElShortcut($(document), keyboardShortcut, handler);
+}
+
+function bindElShortcut($el, keyboardShortcut, handler) {
if (isDesktop()) {
if (isMac()) {
// use CMD (meta) instead of CTRL for all shortcuts
keyboardShortcut = keyboardShortcut.replace("ctrl", "meta");
}
- $(document).bind('keydown', keyboardShortcut, e => {
+ $el.bind('keydown', keyboardShortcut, e => {
handler();
e.preventDefault();
@@ -212,6 +216,7 @@ export default {
toObject,
randomString,
bindShortcut,
+ bindElShortcut,
isMobile,
isDesktop,
setCookie,