diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 40cb149..054d7c1 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -116,6 +116,11 @@ "config_modeForNoSelection_treeDescendants_label": { "message": "Copy Tree Descendants" }, "config_modeForNoSelectionModified_label": { "message": "Middle Click" }, + "config_delimiter_caption": { "message": "Separator of copied items" }, + "config_delimiter_lineBreak_label": { "message": "Line Break" }, + "config_delimiter_space_label": { "message": "Space" }, + "config_delimiter_tab_label": { "message": "Tab" }, + "config_debug_caption": { "message": "Development" }, "config_debug_label": { "message": "Debug mode" }, "config_all_caption": { "message": "All Configs" } diff --git a/_locales/ja/messages.json b/_locales/ja/messages.json index 71b89f2..24ba1b6 100644 --- a/_locales/ja/messages.json +++ b/_locales/ja/messages.json @@ -116,6 +116,11 @@ "config_modeForNoSelection_treeDescendants_label": { "message": "配下のタブのみをコピー" }, "config_modeForNoSelectionModified_label": { "message": "中ボタンクリック" }, + "config_delimiter_caption": { "message": "コピーした項目の区切り文字" }, + "config_delimiter_lineBreak_label": { "message": "改行" }, + "config_delimiter_space_label": { "message": "スペース" }, + "config_delimiter_tab_label": { "message": "タブ" }, + "config_debug_caption": { "message": "開発用" }, "config_debug_label": { "message": "デバッグモード" }, "config_all_caption": { "message": "すべての設定" } diff --git a/common/commands.js b/common/commands.js index 6c6fa91..86bdd08 100644 --- a/common/commands.js +++ b/common/commands.js @@ -14,11 +14,29 @@ import { notify, collectAncestors, } from './common.js'; +import * as Constants from './constants.js'; import * as Permissions from './permissions.js'; const kFORMAT_PARAMETER_MATCHER = /\([^\)]+\)|\[[^\]]+\]|\{[^\}]+\}|<[^>]+>/g; const kFORMAT_MATCHER_TREE_INDENT = new RegExp(`%(TST|TREE)_INDENT(?:${kFORMAT_PARAMETER_MATCHER.source})*%`, 'gi'); +function getDelimiter() { + switch (configs.delimiter) { + case Constants.kDELIMITER_SPACE: + return ' '; + + case Constants.kDELIMITER_TAB: + return '\t'; + + default: + return getLineFeed(); + } +} + +function getLineFeed() { + return configs.useCRLF ? '\r\n' : '\n'; +} + export async function copyToClipboard(tabs, format) { let indentLevels = []; if (kFORMAT_MATCHER_TREE_INDENT.test(format)) { @@ -34,13 +52,14 @@ export async function copyToClipboard(tabs, format) { } } - const lineFeed = configs.useCRLF ? '\r\n' : '\n' ; + const delimiter = getDelimiter(); const itemsToCopy = await Promise.all(tabs.map((tab, index) => fillPlaceHolders(format, tab, indentLevels[index]))); const richText = /%RT%/i.test(format) ? itemsToCopy.map(item => item.richText).join('
') : null ; - let plainText = itemsToCopy.map(item => item.plainText).join(lineFeed); - if (tabs.length > 1) - plainText += lineFeed; + let plainText = itemsToCopy.map(item => item.plainText).join(delimiter); + if (configs.delimiter == Constants.kDELIMITER_LINE_BREAK && + tabs.length > 1) + plainText += delimiter; log('richText: ', richText); log('plainText: ', plainText); @@ -201,7 +220,7 @@ export async function fillPlaceHolders(format, tab, indentLevel) { let params = { tab, indentLevel, - lineFeed: configs.useCRLF ? '\r\n' : '\n', + delimiter: getDelimiter(), timeUTC: now.toUTCString(), timeLocal: now.toLocaleString() }; @@ -274,14 +293,14 @@ export async function fillPlaceHolders(format, tab, indentLevel) { function fillPlaceHoldersInternal( format, - { tab, author, description, keywords, timeUTC, timeLocal, lineFeed, indentLevel } = {} + { tab, author, description, keywords, timeUTC, timeLocal, delimiter, indentLevel } = {} ) { return PlaceHolderParser.process(format, (name, rawArgs, ...args) => { return processPlaceHolder( name, rawArgs, args, - { tab, author, description, keywords, timeUTC, timeLocal, lineFeed, indentLevel } + { tab, author, description, keywords, timeUTC, timeLocal, delimiter, indentLevel } ); }, '', log); } @@ -292,7 +311,7 @@ function processPlaceHolder( name, rawArgs, args, - { tab, author, description, keywords, timeUTC, timeLocal, lineFeed, indentLevel } = {} + { tab, author, description, keywords, timeUTC, timeLocal, delimiter, indentLevel } = {} ) { log('processPlaceHolder ', name, rawArgs, args); switch (name.trim().toLowerCase()) { @@ -361,7 +380,7 @@ function processPlaceHolder( return '\t'; case 'eol': - return lineFeed; + return getLineFeed(); case 'tst_indent': { const indenters = args.length == 0 ? @@ -384,7 +403,7 @@ function processPlaceHolder( matchedToHTMLSafe[1], rawArgs, args, - { tab, author, description, keywords, timeUTC, timeLocal, lineFeed, indentLevel } + { tab, author, description, keywords, timeUTC, timeLocal, delimiter, indentLevel } )); return rawArgs ? `%${name}(${rawArgs})%` : `%${name}%`; diff --git a/common/common.js b/common/common.js index 34bdf46..f77ee8b 100644 --- a/common/common.js +++ b/common/common.js @@ -47,6 +47,7 @@ export const configs = new Configs({ shouldNotifyResult: true, copyToClipboardFormats: defaultClipboardFormats, reportErrors: false, + delimiter: Constants.kDELIMITER_LINE_BREAK, useCRLF: false, notificationTimeout: 10 * 1000, debug: false, diff --git a/common/constants.js b/common/constants.js index 11399d3..bfe6d29 100644 --- a/common/constants.js +++ b/common/constants.js @@ -12,6 +12,10 @@ export const kCOPY_TREE_DESCENDANTS = 3; export const kCOPY_ALL = 4; export const kCOPY_CHOOSE_FROM_MENU = 5; +export const kDELIMITER_LINE_BREAK = 0; +export const kDELIMITER_SPACE = 1; +export const kDELIMITER_TAB = 2; + export const WITH_CONTAINER_MATCHER = /%(?:CONTAINER_URL(?:_HTML(?:IFIED)?)?|CONTAINER_(?:TITLE|NAME)(?:_HTML(?:IFIED)?)?(?:\(.*?\))?)%/i; diff --git a/options/options.html b/options/options.html index aea6344..b991d1c 100644 --- a/options/options.html +++ b/options/options.html @@ -156,6 +156,24 @@ +
+ __MSG_config_delimiter_caption__ + +
+