From a394c043a5a3bd4853aa2bc309963f98330da28f Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Mon, 23 Nov 2020 06:49:06 +0100 Subject: [PATCH] work on webbox --- .../Controls/WebBrowser/WebBrowserEditBox.html | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ui/Controls/WebBrowser/WebBrowserEditBox.html b/src/ui/Controls/WebBrowser/WebBrowserEditBox.html index 24e8e4ac7..140fd5678 100644 --- a/src/ui/Controls/WebBrowser/WebBrowserEditBox.html +++ b/src/ui/Controls/WebBrowser/WebBrowserEditBox.html @@ -215,18 +215,18 @@ } function getNextNode(node) { - if (node.firstChild) { return node.firstChild; } - if (node.nextSibling) { return node.nextSibling; } if (node.parentNode && node.parentNode.id !== "myContent" && node.parentNode.nextSibling) { if (node.parentNode.nextSibling.firstChild) { + if (node.parentNode.nodeName === "P") { + } return node.parentNode.nextSibling; } @@ -241,16 +241,22 @@ return; } + var extra = 0; var node = document.getElementById("myContent").firstChild; + var firstNode = true; var i = 0; var idx = 0; while (node && i < 100) { i++; - if (node.nodeType === Node.TEXT_NODE && node.nodeValue) { - if (node.nodeValue && idx + node.nodeValue.length > pos) { + if (node.nodeName === "BR") { + extra++; + } if (!firstNode && node.nodeName === "P") { + extra++; + } else if (node.nodeType === Node.TEXT_NODE && node.nodeValue) { + if (node.nodeValue && idx + extra + node.nodeValue.length >= pos) { var range = document.createRange(); var sel = window.getSelection(); - var newIdx = pos - idx; + var newIdx = pos - idx - extra; range.setStart(node, newIdx); range.collapse(true); sel.removeAllRanges(); @@ -261,10 +267,10 @@ idx += node.nodeValue.length; } node = getNextNode(node); + firstNode = false; } } - // Call with: center / rtl function setTextDirection(align, dir) { var element = document.getElementById("myContent"); element.setAttribute("style", align);