From edc2ab0ead2742492521d29ddfe3dce44f785c41 Mon Sep 17 00:00:00 2001 From: tophf Date: Wed, 30 Aug 2017 02:26:47 +0300 Subject: [PATCH] auto-open import dialog when pasted text has @-moz-document --- edit/edit.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/edit/edit.js b/edit/edit.js index e9d5fba3..1690b93f 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -396,7 +396,18 @@ function setupCodeMirror(textarea, index) { hotkeyRerouter.setState(false); wrapper.classList.add('CodeMirror-active'); }); - cm.on('paste', () => { + cm.on('paste', (cm, event) => { + const text = event.clipboardData.getData('text') || ''; + if ( + text.includes('@-moz-document') && + text.replace(/\/\*[\s\S]*?\*\//g, '') + .match(/@-moz-document[\s\r\n]+(url|url-prefix|domain|regexp)\(/) + ) { + event.preventDefault(); + fromMozillaFormat(); + $('#help-popup').codebox.setValue(text); + $('#help-popup').codebox.markClean(); + } if (editors.length === 1) { setTimeout(() => { if (cm.display.sizer.clientHeight > cm.display.wrapper.clientHeight) {