Skip to content

Commit

Permalink
Automatically focus output edit field
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Jul 22, 2020
1 parent c92a3b4 commit b5798c8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Nodexr/wwwroot/js/ContentEditable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ window.contentEditable = {
initContentEditable: function (div, instance, textToDisplay) {
div.innerText = textToDisplay;
div.addEventListener("input", function () {
let text = div.innerText;//contentEditable.strip(div.innerText);
instance.invokeMethodAsync("GetUpdatedTextFromJavascript", text);
instance.invokeMethodAsync("GetUpdatedTextFromJavascript", div.innerText);
});

try {
Expand All @@ -17,6 +16,16 @@ window.contentEditable = {
catch (e) {
contentEditable.setupFallbackPlaintextOnly(div);
}
contentEditable.moveCursorToEnd(div);
},

moveCursorToEnd: function (elem) {
let s = window.getSelection();
let r = document.createRange();
r.setStart(elem, 1);
r.setEnd(elem, 1);
s.removeAllRanges();
s.addRange(r);
},

setupFallbackPlaintextOnly: function (elem) {
Expand Down Expand Up @@ -55,12 +64,4 @@ window.contentEditable = {
document.selection.createRange().text = text;
}
},

strip: function(html) {
let tempDiv = document.createElement("div");
tempDiv.innerText = html;
let text = tempDiv.innerText;
tempDiv.remove();
return text;
}
}

0 comments on commit b5798c8

Please sign in to comment.