diff --git a/js/term.js b/js/term.js index c7289d9..c6bb03a 100644 --- a/js/term.js +++ b/js/term.js @@ -5,6 +5,7 @@ window.termInit = function ({ labels, theme, allFn }) { const input = Input(conn, screen) const termUpload = TermUpl(conn, input, screen) screen.input = input + input.termUpload = termUpload // we delay the display of "connecting" to avoid flash when changing tabs with the terminal open let showConnectingTimeout = -1 diff --git a/js/term_input.js b/js/term_input.js index 71bf711..eef3fcd 100644 --- a/js/term_input.js +++ b/js/term_input.js @@ -15,6 +15,9 @@ * m - mouse move */ window.Input = function (conn, screen) { + // handle for input object + let input + const KEY_NAMES = { 0x03: 'Cancel', 0x06: 'Help', @@ -299,10 +302,16 @@ window.Input = function (conn, screen) { }) window.addEventListener('paste', e => { e.preventDefault() - console.log('User pasted:\n' + e.clipboardData.getData('text/plain')) - - // just write it for now - sendString(e.clipboardData.getData('text/plain')) + let string = e.clipboardData.getData('text/plain') + if (string.includes('\n') || string.length > 90) { + if (!input.termUpload) console.error('input.termUpload is undefined') + input.termUpload.setContent(string) + input.termUpload.open() + } else { + // simple string, just paste it + if (screen.bracketedPaste) string = `\x1b[200~${string}\x1b[201~` + sendString(string) + } }) cfg.all_fn = allFn @@ -361,7 +370,7 @@ window.Input = function (conn, screen) { return modifiers } - return { + input = { /** Init the Input module */ init, @@ -428,4 +437,5 @@ window.Input = function (conn, screen) { cfg.no_keys = yes } } + return input } diff --git a/js/term_upload.js b/js/term_upload.js index 938b420..1ff6752 100644 --- a/js/term_upload.js +++ b/js/term_upload.js @@ -164,6 +164,10 @@ window.TermUpl = function (conn, input, screen) { fuClose() return false }) + }, + open: openUploadDialog, + setContent (content) { + qs('#fu_text').value = content } } }