diff options
author | Maxim Devaev <[email protected]> | 2022-02-24 12:33:41 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-02-24 12:33:41 +0300 |
commit | a8af9b62909747bedbeb900c45da8c2fdc8767c3 (patch) | |
tree | ef126e475f10fe41ac0ea5c88ddb8f3c2f2e64df /web | |
parent | 13afa9f4d34fbdb961b64e307c951b3e2868edc3 (diff) |
fixed ocr selection in firefox
Diffstat (limited to 'web')
-rw-r--r-- | web/share/js/kvm/ocr.js | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/web/share/js/kvm/ocr.js b/web/share/js/kvm/ocr.js index c7fcf643..7bf2ad5a 100644 --- a/web/share/js/kvm/ocr.js +++ b/web/share/js/kvm/ocr.js @@ -54,8 +54,10 @@ export function Ocr(__getGeometry) { $("stream-ocr-window").onkeyup = function(event) { event.preventDefault(); if (event.code === "Enter") { - __recognizeSelection(); - wm.closeWindow($("stream-ocr-window")); + if (__selection) { + __recognizeSelection(); + wm.closeWindow($("stream-ocr-window")); + } } else if (event.code === "Escape") { wm.closeWindow($("stream-ocr-window")); } @@ -116,8 +118,9 @@ export function Ocr(__getGeometry) { let rect = $("stream-box").getBoundingClientRect(); let rel_left = Math.min(__start_pos.x, __end_pos.x) - rect.left; let rel_right = Math.max(__start_pos.x, __end_pos.x) - rect.left; - let rel_top = Math.min(__start_pos.y, __end_pos.y) - rect.top; - let rel_bottom = Math.max(__start_pos.y, __end_pos.y) - rect.top; + let offset = __getNavbarOffset(); + let rel_top = Math.min(__start_pos.y, __end_pos.y) - rect.top + offset; + let rel_bottom = Math.max(__start_pos.y, __end_pos.y) - rect.top + offset; let geo = __getGeometry(); __selection = { left: tools.remap(rel_left, geo.x, geo.width, 0, geo.real_width), @@ -135,12 +138,21 @@ export function Ocr(__getGeometry) { var __getGlobalPosition = function(event) { let rect = $("stream-box").getBoundingClientRect(); let geo = __getGeometry(); + let offset = __getNavbarOffset(); return { x: Math.min(Math.max(event.clientX, rect.left + geo.x), rect.right - geo.x), - y: Math.min(Math.max(event.clientY, rect.top + geo.y), rect.bottom - geo.y), + y: Math.min(Math.max(event.clientY - offset, rect.top + geo.y - offset), rect.bottom - geo.y - offset), }; }; + var __getNavbarOffset = function() { + if (tools.browser.is_firefox) { + // На лисе наблюдается оффсет из-за навбара, хз почему + return wm.getViewGeometry().top; + } + return 0; + }; + var __resetSelection = function() { tools.hidden.setVisible($("stream-ocr-selection"), false); __start_pos = null; @@ -163,8 +175,8 @@ export function Ocr(__getGeometry) { if (http.status === 200) { navigator.clipboard.writeText(http.responseText).then(function() { wm.info("The text is copied to the clipboard"); - }, function() { - wm.error("Can't copy text to the clipboard"); + }, function(err) { + wm.error("Can't copy text to the clipboard:<br>", err); }); } else { wm.error("OCR error:<br>", http.responseText); |