Changeset 36928

Show
Ignore:
Timestamp:
03/04/10 20:26:43 (3 years ago)
Author:
anekos
Message:

オプション等の扱いを一般化

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/feedSomeKeys_3.js

    r36927 r36928  
    4040  <description>feed some defined key events into the Web content</description> 
    4141  <description lang="ja">キーイベントをWebコンテンツ側に送る</description> 
    42   <version>1.5.2</version> 
     42  <version>1.6.0</version> 
    4343  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> 
    4444  <license>new BSD License (Please read the source code comments of this plugin)</license> 
     
    172172  const EVENTS = 'keypress keydown keyup'.split(/\s+/); 
    173173  const EVENTS_WITH_V = EVENTS.concat(['v' + n for each (n in EVENTS)]); 
     174  const IGNORE_URLS = /<ALL>/; 
    174175 
    175176  const VKeys = { 
     
    306307      (values && !values.some(function (value) !list.some(function (event) event === value))); 
    307308 
    308   function unmap (filter, patternOrUrl, ignoreUrls) { 
    309     let result = 0; 
    310  
     309  function findMappings ({all, filter, urls, ignoreUrls, not, result}) { 
    311310    function match (map) { 
    312311      let r = ( 
    313312        map.feedSomeKeys && 
    314         (!filter || filter === map.names[0]) && 
    315         (ignoreUrls || mappings._matchingUrlsTest(map, patternOrUrl)) 
     313        (all || 
     314         (!filter || filter === map.names[0]) && 
     315         (ignoreUrls || urls === IGNORE_URLS || mappings._matchingUrlsTest(map, urls))) 
    316316      ); 
    317       result++; 
    318       return r; 
     317      if (result && r) { 
     318        if (typeof result.matched === 'number') 
     319          result.matched++; 
     320        else 
     321          result.matched = 1; 
     322      } 
     323      return !!r ^ !!not; 
    319324    } 
    320325 
    321     let mode = modes.NORMAL; 
    322     mappings._user[mode] = [ 
    323       map 
    324       for each (map in mappings._user[mode]) 
    325       if (!match(map)) 
    326     ]; 
    327     return result; 
    328   } 
    329  
    330   function gets (filter) { 
    331326    if (filter) 
    332327      filter = mappings._expandLeader(filter); 
    333     return [ 
    334       map 
    335       for (map in mappings._mappingsIterator([modes.NORMAL], mappings._user)) 
    336         if (map.feedSomeKeys && (!filter || map.names[0] == filter)) 
    337     ]; 
    338   } 
    339  
    340   function list (filter) { 
    341     let maps = gets(filter); 
     328    if (urls) 
     329      urls = RegExp(urls); 
     330 
     331    return mappings._user[modes.NORMAL].filter(match); 
     332  } 
     333 
     334  function unmap (condition) { 
     335    condition.not = true; 
     336    mappings._user[modes.NORMAL] = findMappings(condition); 
     337  } 
     338 
     339  function list (condition) { 
     340    let maps = findMappings(condition); 
    342341    let template = modules.template; 
    343342    let list = 
     
    347346            template.map(map.names, function (name) 
    348347            <tr> 
    349               <td>{name}</td> 
    350               <td>{map.feedSomeKeys.rhs}</td> 
     348              <td style="font-weight: bold">{name}</td> 
     349              <td style="font-weight: bold">{map.feedSomeKeys.rhs}</td> 
    351350              <td>{map.matchingUrls ? map.matchingUrls : '[Global]'}</td> 
    352351            </tr>)) 
     
    368367        map.feedSomeKeys.rhs + ' for ' + (map.matchingUrls ? map.matchingUrls : 'Global') 
    369368      ] 
    370       for each (map in gets()) 
     369      for each (map in findMappings({urls: args['-urls'], ignoreUrls: args['-ignoreurls']})) 
    371370    ]; 
    372371  } 
    373372 
    374373  function urlCompleter (context, args) { 
    375     let maps = gets(); 
     374    let maps = findMappings({all: true}); 
    376375    let uniq = {}; 
    377376    return [ 
     
    419418              matchingUrls: args['-urls'], 
    420419              feedSomeKeys: { 
    421                 rhs: rhs 
     420                rhs: rhs, 
    422421              } 
    423422            }, 
     
    432431          let [, lhs, rhs] = args.literalArg.match(/^(\S+)\s+(.*)$/) || args.literalArg; 
    433432          if (!rhs) { 
    434             list(args.literalArg.trim()); 
     433            list({ 
     434              filter: args.literalArg.trim(), 
     435              urls: args['-urls'], 
     436              ignoreUrls: !args['-urls'] 
     437            }); 
    435438          } else { 
    436439            add([lhs, rhs]); 
     
    471474    function (args) { 
    472475      if (args.bang) { 
    473         unmap(null, null, true); 
    474         liberator.log('All fmappings were removed'); 
     476        unmap({ignoreUrls: true}); 
     477        liberator.log('All fmappings were removed.'); 
    475478      } else { 
    476         let urls = args.literalArg; 
    477         liberator.echo( 
    478           unmap(null, urls && RegExp(urls), false) ? 
    479             'Some fmappings were removed' : 
    480             'Not found specifed fmappings' 
    481         ); 
     479        let result = {}; 
     480        unmap({urls: args.literalArg, result: result}); 
     481        liberator.echo(result.matched ? 'Some fmappings were removed.' : 'Not found specifed fmappings.'); 
    482482      } 
    483483    }, 
     
    502502        return liberator.echoerr('E471: Argument required'); 
    503503 
    504       liberator.echo( 
    505         unmap(name, urls && RegExp(urls), args['-ignoreurls']) ? 
    506           'Some fmappings were removed' : 
    507           'Not found specifed fmappings' 
    508       ); 
     504      let result = {}; 
     505      unmap({filter: name, urls: urls, ignoreUrls: args['-ignoreurls'], result: result}); 
     506      liberator.echo(result.matched ?  'Some fmappings were removed.' : 'Not found specifed fmappings.'); 
    509507    }, 
    510508    { 
     
    531529 
    532530  __context__.API = 
    533     'VKeys feed getFrames fromXPath virtualize unmap gets list'.split(/\s+/).reduce( 
     531    'VKeys feed getFrames fromXPath virtualize unmap findMappings list'.split(/\s+/).reduce( 
    534532      function (result, name) 
    535533        (result[name] = eval(name), result),