From 8feb7df5e4185e2f28262a3524f7fb3d9b1e470d Mon Sep 17 00:00:00 2001 From: Alex Kovar Date: Wed, 20 Oct 2010 18:03:23 -0500 Subject: initial code for bookmark mode completion dialog --- lib/keyboardUtils.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib') diff --git a/lib/keyboardUtils.js b/lib/keyboardUtils.js index 98725d95..60eb487f 100644 --- a/lib/keyboardUtils.js +++ b/lib/keyboardUtils.js @@ -61,3 +61,25 @@ function isEscape(event) { return event.keyCode == keyCodes.ESC || (event.ctrlKey && getKeyChar(event) == '['); // c-[ is mapped to ESC in Vim by default. } + +var KeyPressListener = function(handlers) { + this.handlers = handlers; +} + +KeyPressListener.prototype = { + enable: function() { + var handlers = this.handlers; + var wrapper = function(callback){ + return function(event) { + callback(event) + } + } + (handlers.keyDown && document.addEventListener("keydown", handlers.keyDown, true)); + (handlers.keyUp && document.addEventListener("keyup", handlers.keyUp, true)); + }, + disable: function() { + var handlers = this.handlers; + (handlers.keyDown && document.removeEventListener("keydown", handlers.keyDown, true)); + (handlers.keyUp && document.removeEventListener("keyup", handlers.keyUp, true)); + } +} -- cgit v1.2.3 From baf3dd02d5891df9a35af7d2f8f2eaa42ac6bb03 Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 3 Jan 2011 04:29:12 +0800 Subject: Revise how the linkHints object is generated. Add lib/utils.js. Extend a template object rather than using prototype inheritance. The previous method created confusion about whether a given property resided in the base or in the specialization. --- lib/utils.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/utils.js (limited to 'lib') diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000..86c868b8 --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,32 @@ +var utils = { + deepcopy: function(original) { + var result; + if (typeof original == 'object') { + if (original === null) { + result = null; + } else { + result = original.constructor === Array ? [] : {}; + for (var i in original) + if (original.hasOwnProperty(i)) + result[i] = this.deepcopy(original[i]); + } + } else { + result = original; + } + + return result; + }, + extendWithSuper: function(original, ext) { + var result = this.deepcopy(original); + var tmpSuper = result._super; + result._superFunctions = {}; + result._super = function(fname) { return this._superFunctions[fname].bind(this); } + for (var i in ext) + if (ext.hasOwnProperty(i)) { + if (typeof ext[i] == 'function' && typeof original[i] == 'function') + result._superFunctions[i] = this.deepcopy(original[i]); + result[i] = this.deepcopy(ext[i]); + } + return result; + }, +}; -- cgit v1.2.3 From bbf078cf0a3bff06a9fc2172b3b63e1198a42c4e Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 4 Jan 2011 16:51:58 +0800 Subject: Comments and renaming. --- lib/utils.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/utils.js b/lib/utils.js index 86c868b8..4c05610c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,5 +1,7 @@ var utils = { - deepcopy: function(original) { + // probably doesn't handle some cases correctly, but it works fine for what + // we have now + deepCopy: function(original) { var result; if (typeof original == 'object') { if (original === null) { @@ -8,7 +10,7 @@ var utils = { result = original.constructor === Array ? [] : {}; for (var i in original) if (original.hasOwnProperty(i)) - result[i] = this.deepcopy(original[i]); + result[i] = this.deepCopy(original[i]); } } else { result = original; @@ -16,16 +18,23 @@ var utils = { return result; }, + + /* + * Extends 'original' with 'ext'. If a function in 'ext' also exists in + * 'original', let the 'original' function be accessible in the new object + * via a ._super(functionName as String) method. _Cannot_ be used on its + * result to achieve 'two-level' inheritance. + */ extendWithSuper: function(original, ext) { - var result = this.deepcopy(original); + var result = this.deepCopy(original); var tmpSuper = result._super; result._superFunctions = {}; result._super = function(fname) { return this._superFunctions[fname].bind(this); } for (var i in ext) if (ext.hasOwnProperty(i)) { if (typeof ext[i] == 'function' && typeof original[i] == 'function') - result._superFunctions[i] = this.deepcopy(original[i]); - result[i] = this.deepcopy(ext[i]); + result._superFunctions[i] = this.deepCopy(original[i]); + result[i] = this.deepCopy(ext[i]); } return result; }, -- cgit v1.2.3 From 92a0c80a4820689b14aaf1b7f0dda59de9417ac7 Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 4 Jan 2011 16:59:50 +0800 Subject: Factor out invokeCommandString. Had to make 'this' point explicitly to 'window'. --- lib/utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/utils.js b/lib/utils.js index 4c05610c..7fc2a6b9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -38,4 +38,17 @@ var utils = { } return result; }, + + /* + * Takes a dot-notation object string and call the function + * that it points to with the correct value for 'this'. + */ + invokeCommandString: function(str, argArray) { + var components = str.split('.'); + var obj = window; + for (var i = 0; i < components.length - 1; i++) + obj = obj[components[i]]; + var func = obj[components.pop()]; + return func.apply(obj, argArray); + }, }; -- cgit v1.2.3 From f33844c7895c8cf72a020171ccc1b6de1c6c08fc Mon Sep 17 00:00:00 2001 From: jez Date: Mon, 31 Jan 2011 14:47:18 +0800 Subject: Remove util functions that the refactor has rendered unnecessary --- lib/utils.js | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'lib') diff --git a/lib/utils.js b/lib/utils.js index 7fc2a6b9..0c992ad4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,44 +1,4 @@ var utils = { - // probably doesn't handle some cases correctly, but it works fine for what - // we have now - deepCopy: function(original) { - var result; - if (typeof original == 'object') { - if (original === null) { - result = null; - } else { - result = original.constructor === Array ? [] : {}; - for (var i in original) - if (original.hasOwnProperty(i)) - result[i] = this.deepCopy(original[i]); - } - } else { - result = original; - } - - return result; - }, - - /* - * Extends 'original' with 'ext'. If a function in 'ext' also exists in - * 'original', let the 'original' function be accessible in the new object - * via a ._super(functionName as String) method. _Cannot_ be used on its - * result to achieve 'two-level' inheritance. - */ - extendWithSuper: function(original, ext) { - var result = this.deepCopy(original); - var tmpSuper = result._super; - result._superFunctions = {}; - result._super = function(fname) { return this._superFunctions[fname].bind(this); } - for (var i in ext) - if (ext.hasOwnProperty(i)) { - if (typeof ext[i] == 'function' && typeof original[i] == 'function') - result._superFunctions[i] = this.deepCopy(original[i]); - result[i] = this.deepCopy(ext[i]); - } - return result; - }, - /* * Takes a dot-notation object string and call the function * that it points to with the correct value for 'this'. -- cgit v1.2.3 From 1133f348558e8e70aa5e76ca67a739a5303467bd Mon Sep 17 00:00:00 2001 From: jez Date: Tue, 1 Feb 2011 05:01:39 +0800 Subject: Use only one key[event] handler for all modes. --- lib/keyboardUtils.js | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'lib') diff --git a/lib/keyboardUtils.js b/lib/keyboardUtils.js index 5b8b4c84..fe3dcd59 100644 --- a/lib/keyboardUtils.js +++ b/lib/keyboardUtils.js @@ -61,25 +61,3 @@ function isEscape(event) { return event.keyCode == keyCodes.ESC || (event.ctrlKey && getKeyChar(event) == '['); // c-[ is mapped to ESC in Vim by default. } - -var KeyPressListener = function(handlers) { - this.handlers = handlers; -} - -KeyPressListener.prototype = { - enable: function() { - var handlers = this.handlers; - var wrapper = function(callback){ - return function(event) { - callback(event) - } - } - (handlers.keyDown && document.addEventListener("keydown", handlers.keyDown, true)); - (handlers.keyUp && document.addEventListener("keyup", handlers.keyUp, true)); - }, - disable: function() { - var handlers = this.handlers; - (handlers.keyDown && document.removeEventListener("keydown", handlers.keyDown, true)); - (handlers.keyUp && document.removeEventListener("keyup", handlers.keyUp, true)); - } -} -- cgit v1.2.3