aboutsummaryrefslogtreecommitdiffstats
path: root/hints-yank-paste.js
diff options
context:
space:
mode:
authordrry2009-02-17 13:11:24 +0000
committerdrry2009-02-17 13:11:24 +0000
commite7cfb120270459dd885c6ed703531eb1c7f820b6 (patch)
tree21a5657c760c581f80f019511eda6bb328de5c52 /hints-yank-paste.js
parent0591adeb5a0122efb2a2f21793e2b549d33ed61a (diff)
downloadvimperator-plugins-e7cfb120270459dd885c6ed703531eb1c7f820b6.tar.bz2
* 正規表現を修正しました。
* ほか。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30195 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'hints-yank-paste.js')
-rw-r--r--hints-yank-paste.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/hints-yank-paste.js b/hints-yank-paste.js
index d682a04..db33ba9 100644
--- a/hints-yank-paste.js
+++ b/hints-yank-paste.js
@@ -1,21 +1,21 @@
var PLUGIN_INFO =
<VimperatorPlugin>
<name>{NAME}</name>
- <description>add "Yank element's text/html/attrs" or "Paste to element" hint mode</description>
+ <description>Adds "Yank element's text/html/attrs" or "Paste to element" hint mode</description>
<description lang="ja">要素の text/html/attrs をコピーするヒントモードを追加する</description>
- <minVersion>2.0</minVersion>
+ <minVersion>2.0pre</minVersion>
<maxVersion>2.0</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hints-yank-paste.js</updateURL>
<author mail="hotchpotch@gmail.com" homepage="http://d.hatena.ne.jp/secondlife/">Yuichi Tateno</author>
<license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
<version>0.1</version>
<detail><![CDATA[
-; の hint モードで、c/C で要素の text / html / attributes をクリップボードにコピー(Yank)できるようにするプラグインです。
-ソースコードや段落, 画像のURL, input/textarea の値などをさくっとコピーしたり、どこかの部分の html 自体をコピりたいなー、という時に活用できます。
+; の hint モードにおいて、c/C で要素の text / HTML / attributes をクリップボードにコピー(Yank)できるようにするプラグインです。
+ソースコードや段落, 画像のURL, input/textarea の値などをさくっとコピーしたり、どこかの部分の HTML 自体をコピりたいなー、という時に活用できます。
また p/P で、input/textarea の要素に、現在のクリップボードの値を貼り付け(pが追加、Pが置換)することができます。エディタで書いた文章をそのまんま追加したい時などに利用できます。
== SETTINGS ==
-マップするキーや hint の xpath などは変更できます。
+マップするキーや hint の XPath などは変更できます。
liberator.globalVariables.hints_copy_maps = ['c', 'C', 'p', 'P'];
@@ -29,7 +29,7 @@ set hintpastetags='//xpath|//xpath2';
;c :
Yank hint element's text or attributes.
;C :
- Yank hint element's html.
+ Yank hint element's HTML.
;p :
Paste(append) to input/textarea.
;P :
@@ -40,7 +40,7 @@ set hintpastetags='//xpath|//xpath2';
(function() {
var p = function(msg) {
- liberator.log(msg, 0);
+ liberator.log(msg, 0);
};
const DEFAULT_MAPS = ['c', 'C', 'p', 'P'];
@@ -61,19 +61,19 @@ options.add(["hintpastetags"],
let maps = liberator.globalVariables.hints_copy_maps || DEFAULT_MAPS;
var stripText = function(text) {
- text = text.replace(/(^\s+\r?\n)|(\s+$)/m, '');
- let matched = text.match(/(\r?\n)/mg);
+ text = text.replace(/^[ \t]+(?:\r\n|[\r\n])|\s+$/m, ''); //mg?
+ let matched = text.match(/\r\n|[\r\n]/g);
if (!matched || matched.length == 1)
text = text.replace(/^\s+/, '');
return text;
-}
+};
if (maps[0]) // c
hints.addMode(maps[0], 'Yank TEXT', function(elem) {
let text = elem.textContent;
if (!text)
- for (let i = 0; i < TEXT_ATTRS.length; i++)
- if (text = elem[TEXT_ATTRS[i]]) break;
+ TEXT_ATTRS.some(function(attr)
+ (text = elem[attr]) ? true : false);
util.copyToClipboard(stripText(text), true);
}, function() options['hintyanktags']);
@@ -90,8 +90,8 @@ var replaceOrAppend = function(replace) {
return function(elem) {
let clipboard = util.readFromClipboard();
if (clipboard && clipboard.length) {
- if (elem.tagName == 'INPUT')
- clipboard.replace(/\r?\n/, ' ');
+ if (elem.tagName.toUpperCase() == 'INPUT')
+ clipboard.replace(/\r\n|[\r\n]/g, ' ');
if (replace) {
elem.value = clipboard;
@@ -99,8 +99,8 @@ var replaceOrAppend = function(replace) {
elem.value += clipboard;
}
}
- }
-}
+ };
+};
if (maps[2]) // p
hints.addMode(maps[2], 'Paste text (append)', replaceOrAppend(false), function() options['hintpastetags']);