From b549187381e69552fea5cf7653bc63d772625b22 Mon Sep 17 00:00:00 2001 From: anekos Date: Fri, 28 May 2010 09:32:09 +0000 Subject: 補完改良 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@37738 d0d07461-0603-4401-acd4-de1884942a52 --- gmail-commando.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'gmail-commando.js') diff --git a/gmail-commando.js b/gmail-commando.js index a431783..10d821d 100755 --- a/gmail-commando.js +++ b/gmail-commando.js @@ -127,6 +127,17 @@ let INFO = const GMailSearchKeyword = 'label subject from to cc bcc has is in'.split(/\s/); + const KeywordValueCompleter = { + __noSuchMethod__: function () void 0, + + label: function (context) { + context.completions = [ + [label.textContent.replace(/\s*\(\d+\+?\)$/, ''), label.textContent] + for ([, label] in Iterator(Elements.labels)) + ]; + } + }; + commands.addUserCommand( ['gmail'], 'GMail Commando', @@ -140,19 +151,14 @@ let INFO = let input = args.string.slice(0, context.caret); let m; - if (m = /(\s|^)(label):([^\s]*)$/(input)) { + if (m = /([\(\)\s]|^)([a-z]+):([^\s\(\)]*)$/(input)) { context.advance(input.length - m[3].length); let key = m[2]; - if (key === 'label') { - context.completions = [ - [label.textContent.replace(/\s*\(\d+\+?\)$/, ''), label.textContent] - for ([, label] in Iterator(Elements.labels)) - ]; - } + KeywordValueCompleter[key](context, args); return; } - if (m = /\s*([^\s:]*)$/(input)) { + if (m = /\s*([^\s:\(\)]*)$/(input)) { context.advance(input.length - m[1].length); context.completions = [ [v + ':', v] for ([, v] in Iterator(GMailSearchKeyword)) -- cgit v1.2.3