Skip to content

Commit

Permalink
Fix replacing spaces with tabs, fix cursor after paste
Browse files Browse the repository at this point in the history
  • Loading branch information
peteraba committed Apr 16, 2020
1 parent a99feb8 commit ff6e3fa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions static/roadmap-form.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ export const roadmapForm = () => {
};

const handlePaste = (e, txtField, txtFieldValid, txtFieldInvalid) => {
const before = txtField.value.substr(0, txtField.selectionStart),
after = txtField.value.substr(txtField.selectionEnd);
const origText = txtField.value,
s0 = txtField.selectionStart,
e0 = txtField.selectionEnd,
before = origText.substr(0, s0),
after = origText.substr(e0);

let lines = (e.clipboardData || window.clipboardData).getData('text').split("\n");

// Remove empty lines from the top
while (lines.length > 0 && lines[0].trim() === "") {
lines.shift();
}
// while (lines.length > 0 && lines[0].trim() === "") {
// lines.shift();
// }

if (lines.length === 0) {
return handleInvalidTextarea(txtField, txtFieldValid, txtFieldInvalid, 'empty lines', [0]);
Expand Down Expand Up @@ -104,6 +107,9 @@ export const roadmapForm = () => {

txtField.value = before + val + after;

txtField.selectionStart = s0 + val.length;
txtField.selectionEnd = s0 + val.length;

e.preventDefault();
};

Expand Down

0 comments on commit ff6e3fa

Please sign in to comment.