Commit 833e6272fdc03999e6a10c74b5adff86a11d8d39
compose: improve insert attachment rules
still could be better #576Matt McKegg committed on 7/1/2017, 10:41:04 AM
Parent: f815ce842a77e397cb805d2045e8e7033e54da31
Files changed
modules/message/html/compose.js | changed |
modules/message/html/compose.js | |||
---|---|---|---|
@@ -57,13 +57,17 @@ | |||
57 | 57 … | files.push(file) | |
58 | 58 … | filesById[file.link] = file | |
59 | 59 … | ||
60 | 60 … | var embed = file.type.indexOf('image/') === 0 ? '!' : '' | |
61 … | + var pos = textArea.selectionStart | ||
62 … | + var before = textArea.value.slice(0, pos) | ||
63 … | + var after = textArea.value.slice(pos) | ||
64 … | + | ||
61 | 65 … | var spacer = embed ? '\n' : ' ' | |
62 | - var insertLink = `${spacer}${embed}[${file.name}](${file.link})${spacer}` | ||
66 … | + if (before && !before.endsWith(spacer)) before += spacer | ||
67 … | + if (!after.startsWith(spacer)) after = spacer + after | ||
63 | 68 … | ||
64 | - var pos = textArea.selectionStart | ||
65 | - textArea.value = `${textArea.value.slice(0, pos)}${insertLink}${textArea.value.slice(pos)}` | ||
69 … | + textArea.value = `${before}![${file.name}](${file.link})${after}` | ||
66 | 70 … | console.log('added:', file) | |
67 | 71 … | }) | |
68 | 72 … | ||
69 | 73 … | fileInput.onclick = function () { |
Built with git-ssb-web