aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStephen Blott2015-01-08 11:09:06 +0000
committerStephen Blott2015-01-08 11:30:55 +0000
commit637d90be6847051d20a4cf3b704d599c877a97d3 (patch)
tree15af5d34cc20915579b4e0a19c0680bfe76fd4a0 /lib
parent5d199e6c786bb2874f7ecb700d505e7b2d70d982 (diff)
downloadvimium-637d90be6847051d20a4cf3b704d599c877a97d3.tar.bz2
Modes; more changes...
- Simplify InsertMode Trigger/Blocker (yet again). - Reduce badge flicker for singletons.
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.coffee18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 661f7e84..a7bfc440 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -152,6 +152,24 @@ Utils =
# locale-sensitive uppercase detection
hasUpperCase: (s) -> s.toLowerCase() != s
+ # Utility class. This can help different software components to interact without having to share much logic
+ # and/or state. See InsertModeTrigger for an example.
+ # suppressedResult is the value to be returned when a function call is suppressed.
+ Suppressor: class Suppressor
+ constructor: (@suppressedResult = null)->
+ @count = 0
+
+ suppress: -> @count += 1
+ unsuppress: -> @count -= 1
+
+ runSuppresed: (func) ->
+ @suppress()
+ func()
+ @unsuppress()
+
+ unlessSuppressed: (func) ->
+ if 0 < @count then @suppressedResult else func()
+
# This creates a new function out of an existing function, where the new function takes fewer arguments. This
# allows us to pass around functions instead of functions + a partial list of arguments.
Function::curry = ->