Skip to content

TagSpaces is an offline, open source, document manager with tagging support

adding mousetrap global bind library

uggrock06149d38332e
diff --git a/data/js/fileopener.js b/data/js/fileopener.js
index ca6f8cda1..52931e9cd 100644
--- a/data/js/fileopener.js
+++ b/data/js/fileopener.js
@@ -331,19 +331,19 @@
// Handling the keybindings
Mousetrap.unbind(TSCORE.Config.getSaveDocumentKeyBinding());
- Mousetrap.bind(TSCORE.Config.getSaveDocumentKeyBinding(), function() {
+ Mousetrap.bindGlobal(TSCORE.Config.getSaveDocumentKeyBinding(), function() {
saveFile();
return false;
});
Mousetrap.unbind(TSCORE.Config.getCloseViewerKeyBinding());
- Mousetrap.bind(TSCORE.Config.getCloseViewerKeyBinding(), function() {
+ Mousetrap.bindGlobal(TSCORE.Config.getCloseViewerKeyBinding(), function() {
closeFile();
return false;
});
Mousetrap.unbind(TSCORE.Config.getReloadDocumentKeyBinding());
- Mousetrap.bind(TSCORE.Config.getReloadDocumentKeyBinding(), function() {
+ Mousetrap.bindGlobal(TSCORE.Config.getReloadDocumentKeyBinding(), function() {
reloadFile();
return false;
});
@@ -355,7 +355,7 @@
});*/
Mousetrap.unbind(TSCORE.Config.getPropertiesDocumentKeyBinding());
- Mousetrap.bind(TSCORE.Config.getPropertiesDocumentKeyBinding(), function() {
+ Mousetrap.bindGlobal(TSCORE.Config.getPropertiesDocumentKeyBinding(), function() {
showFilePropertiesDialog();
return false;
});
@@ -373,7 +373,7 @@
});
Mousetrap.unbind(TSCORE.Config.getEditDocumentKeyBinding());
- Mousetrap.bind(TSCORE.Config.getEditDocumentKeyBinding(), function() {
+ Mousetrap.bindGlobal(TSCORE.Config.getEditDocumentKeyBinding(), function() {
editFile(_openedFilePath);
return false;
});
diff --git a/data/libs/mousetrap/mousetrap-global-bind.js b/data/libs/mousetrap/mousetrap-global-bind.js
new file mode 100644
index 000000000..022ceb71d
--- /dev/null
+++ b/data/libs/mousetrap/mousetrap-global-bind.js
@@ -0,0 +1,36 @@
+/**
+ * adds a bindGlobal method to Mousetrap that allows you to
+ * bind specific keyboard shortcuts that will still work
+ * inside a text input field
+ *
+ * usage:
+ * Mousetrap.bindGlobal('ctrl+s', _saveChanges);
+ */
+/* global Mousetrap:true */
+Mousetrap = (function(Mousetrap) {
+ var _globalCallbacks = {},
+ _originalStopCallback = Mousetrap.stopCallback;
+
+ Mousetrap.stopCallback = function(e, element, combo, sequence) {
+ if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
+ return false;
+ }
+
+ return _originalStopCallback(e, element, combo);
+ };
+
+ Mousetrap.bindGlobal = function(keys, callback, action) {
+ Mousetrap.bind(keys, callback, action);
+
+ if (keys instanceof Array) {
+ for (var i = 0; i < keys.length; i++) {
+ _globalCallbacks[keys[i]] = true;
+ }
+ return;
+ }
+
+ _globalCallbacks[keys] = true;
+ };
+
+ return Mousetrap;
+}) (Mousetrap);
diff --git a/data/loader.js b/data/loader.js
index 110d1cd48..eefad6ef7 100644
--- a/data/loader.js
+++ b/data/loader.js
@@ -83,6 +83,7 @@ requirejs.config({
d3: 'libs/d3/d3.v3',
i18next: 'libs/i18next/i18next.amd.withJQuery-1.7.2.min',
mousetrap: 'libs/mousetrap/mousetrap.min',
+ mousetrapgb: 'libs/mousetrap/mousetrap-global-bind',
select2: 'libs/select2/select2.min',
hammerjs: 'libs/hammerjs/jquery.hammer.min',
handlebarsjs: 'libs/handlebars.js/handlebars-v1.1.2',
@@ -122,6 +123,7 @@ requirejs.config({
'i18next': { deps: ['jquery'] },
'select2': { deps: ['jquery'] },
'hammerjs': { deps: ['jquery'] },
+ 'mousetrapgb': { deps: ['mousetrap'] },
'tscore': { deps: [
'jquery',
'jqueryui',
@@ -140,6 +142,7 @@ requirejs.config({
'jquerysimplecolorpicker',
'i18next',
'mousetrap',
+ 'mousetrapgb',
'select2',
'handlebarsjs',
'tssettingsdefault'