From fa3ebe5538cc0dc21d66928f19e8c107631a9f33 Mon Sep 17 00:00:00 2001 From: Wilmer Ricciotti Date: Wed, 13 Jul 2011 15:28:54 +0000 Subject: [PATCH] more tests on keyboard events. --- matitaB/matita/matitaweb.js | 46 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/matitaB/matita/matitaweb.js b/matitaB/matita/matitaweb.js index 4b99a23a2..4c4d0a406 100644 --- a/matitaB/matita/matitaweb.js +++ b/matitaB/matita/matitaweb.js @@ -107,6 +107,29 @@ function suppressdefault(e,flag) } return !flag; } + +function restoreSelection() { + unlocked.focus(); + if (savedRange != null) { + if (window.getSelection)//non IE and there is already a selection + { + var s = window.getSelection(); + if (s.rangeCount > 0) + s.removeAllRanges(); + s.addRange(savedRange); + } + else + if (document.createRange)//non IE and no selection + { + window.getSelection().addRange(savedRange); + } + else + if (document.selection)//IE + { + savedRange.select(); + } + } +} function keypress(e) { @@ -122,29 +145,10 @@ function keypress(e) post = unlocked.innerHTML.substring(j); if (match == '\\to') { unlocked.innerHTML = pre + "-> " + post; - unlocked.focus(); - if (savedRange != null) { - if (window.getSelection)//non IE and there is already a selection - { - var s = window.getSelection(); - if (s.rangeCount > 0) - s.removeAllRanges(); - s.addRange(savedRange); - } - else - if (document.createRange)//non IE and no selection - { - window.getSelection().addRange(savedRange); - } - else - if (document.selection)//IE - { - savedRange.select(); - } - } - + restoreSelection(); return suppressdefault(e,true); } + restoreSelection(); else return suppressdefault(e,false); } else return suppressdefault(e,false); -- 2.39.2