From 996dedeaa1cd67a4611cc641b0ceabf70101ed6c Mon Sep 17 00:00:00 2001 From: teramako Date: Fri, 28 Nov 2008 14:29:27 +0000 Subject: change algorithm(replaceVariable) and fix bug git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@25278 d0d07461-0603-4401-acd4-de1884942a52 --- copy.js | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'copy.js') diff --git a/copy.js b/copy.js index e8b642e..6b0906d 100644 --- a/copy.js +++ b/copy.js @@ -117,17 +117,38 @@ function replaceVariable(str){ if (!str) return ''; var win = new XPCNativeWrapper(window.content.window); var sel = '',htmlsel = ''; - if (str.indexOf('%SEL%') >= 0 || str.indexOf('%HTMLSEL%') >= 0){ - sel = win.getSelection().rangeCount()>0? win.getSelection().getRangeAt(0): ''; - } - if (str.indexOf('%HTMLSEL%') >= 0){ - var serializer = new XMLSerializer(); - htmlsel = serializer.serializeToString(sel.cloneContents()); - } - return str.replace(/%TITLE%/g,buffer.title) - .replace(/%URL%/g,buffer.URL) - .replace(/%SEL%/g,sel.toString()) - .replace(/%HTMLSEL%/g,htmlsel); + var selection = win.getSelection(); + function replacer(value){ //{{{ + switch(value){ + case '%TITLE%': + return buffer.title; + case '%URL%': + return buffer.URL; + case '%SEL%': + if (sel) + return sel; + else if (selection.rangeCount < 1) + return ''; + + for (var i=0, c=selection.rangeCount; i