From 3dc39393599777bda264bf2d63068d36a5cbbf2d Mon Sep 17 00:00:00 2001 From: anekos Date: Thu, 24 Nov 2011 18:14:19 +0900 Subject: Fix user tags completer --- direct_bookmark.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'direct_bookmark.js') diff --git a/direct_bookmark.js b/direct_bookmark.js index 62353c9..90cf3bf 100644 --- a/direct_bookmark.js +++ b/direct_bookmark.js @@ -3,7 +3,7 @@ var PLUGIN_INFO = {NAME} Direct Post to Social Bookmarks Trapezoid - 0.16.0 + 0.16.1 GPL 2.0pre https://github.com/vimpr/vimperator-plugins/raw/master/direct_bookmark.js @@ -492,6 +492,8 @@ for Migemo search: require XUL/Migemo Extension var mypage_html = parseHTML(xhr.responseText); var tags = getElementsByXPath("id(\"tag_list\")/div/span",mypage_html); + if (!tags) + return []; tags.forEach(function(tag){ ldc_tags.push(tag.textContent); @@ -732,6 +734,19 @@ for Migemo search: require XUL/Migemo Extension },{ literal: 0, completer: let (lastURL, lastUserTags, onComplete, done = true) function(context, arg){ + function set (context, tags) { + let filter = context.filter; + var match_result = filter.match(/((?:\[[^\]]*\])*)\[?(.*)/); //[all, commited, now inputting] + var m = new RegExp(XMigemoCore && isUseMigemo ? "^(" + XMigemoCore.getRegExp(match_result[2]) + ")" : "^" + match_result[2],'i'); + + context.advance( match_result[1].length ); + + context.incomplete = false; + context.completions = + [ ["[" + tag + "]","Tag"] + for each (tag in tags) + if (m.test(tag) && match_result[1].indexOf('[' + tag + ']') < 0) ]; + } context.fork('UserTags', 0, context, function(context){ context.title = ['User Tags', 'User Tags']; @@ -740,7 +755,7 @@ for Migemo search: require XUL/Migemo Extension done = true; lastUserTags = tags; context.incomplete = false; - context.completions = [['[' + t + ']', t] for ([, t] in Iterator(tags))]; + set(context, tags); }; if (buffer.URL == lastURL){ @@ -758,27 +773,13 @@ for Migemo search: require XUL/Migemo Extension }); context.fork('MyTags', 0, context, function(context, arg){ - function set (){ - var completionList = []; - context.incomplete = false; - context.completions = - [ ["[" + tag + "]","Tag"] - for each (tag in __context__.tags) - if (m.test(tag) && match_result[1].indexOf('[' + tag + ']') < 0) ]; - } - - let filter = context.filter; - var match_result = filter.match(/((?:\[[^\]]*\])*)\[?(.*)/); //[all, commited, now inputting] - var m = new RegExp(XMigemoCore && isUseMigemo ? "^(" + XMigemoCore.getRegExp(match_result[2]) + ")" : "^" + match_result[2],'i'); - context.title = ['My Tag','Description']; - context.advance( match_result[1].length ); if(__context__.tags.length == 0){ context.incomplete = true; - getTagsAsync(set).call([]); + getTagsAsync(set.bind(null, context)).call([]); } else { - set(); + set(context, __context__.tags); } }); }, -- cgit v1.2.3