Removes document.selection and its codepaths from the KMW engine.

This commit is contained in:
Joshua A. Horton 2018-01-25 08:36:54 +07:00
parent c65df69091
commit 983fe8ca6a
5 changed files with 20 additions and 135 deletions

View file

@ -415,10 +415,11 @@ class KeyboardInterface {
this.keymanweb['oninserttext'](dn,s);
}
var Ldoc: Document;
if(Pelem.body) {
var Ldoc=Pelem;
Ldoc=Pelem;
} else {
var Ldoc=Pelem.ownerDocument; // I1481 - integration with rich editors not working 100%
Ldoc=Pelem.ownerDocument; // I1481 - integration with rich editors not working 100%
}
var Li, Ldv;
@ -494,55 +495,6 @@ class KeyboardInterface {
this._DeadkeyDeleteMatched(); // I3318
this._DeadkeyAdjustPos(LselectionStart, -dn + s._kmwLength()); // I3318
} // Internet Explorer (including IE9)
} else if(Ldoc && (Ldv=Ldoc.selection)) { // build 77 - use elem.ownerDocument.selection
if(Ldoc.body.isContentEditable || Ldoc.designMode.toLowerCase()=='on') { // I1295 - isContentEditable
var _CacheableCommands = this._CacheCommands(Ldoc);
}
var Lrange = Ldv.createRange(), Ls1;
if(Lrange.text != '') {
Ldv.clear();
dn = 0;
} else {
Lrange.collapse(true);
}
if(dn > 0) {
Lrange.moveStart('character',-2*dn); // I3319 (next four lines
var s0=Lrange.text,s1=s0._kmwSubstr(-dn);
Lrange.collapse(false); //move start back to end
Lrange.moveStart('character',-s1.length);
} else {
dn = 0;
}
Lrange.text = s;
if(Ldoc.body.isContentEditable || Ldoc.designMode.toLowerCase()=='on') { // I1295 - isContentEditable
Lrange.moveStart('character',-s.length);
this._CacheCommandsReset(Ldoc, _CacheableCommands,Lrange.select);
Lrange.moveStart('character',s.length);
Lrange.select();
}
// Adjust deadkey positions
if(dn >= 0) {
// Pelem.selectionStart seems to exist here in IE 9 and is valid. This provides a possible approach, but may be wrong.
// It appears safe to model the deadkey adjustment based on the non-IE9 code path's calculations.
if(Pelem._KeymanWebSelectionStart != null) {// changed to allow a value of 0
LselectionStart = Pelem._KeymanWebSelectionStart;
} else {
LselectionStart = Pelem.value._kmwCodeUnitToCodePoint(Pelem.selectionStart); // I3319
}
this._DeadkeyDeleteMatched(); // I3318
this._DeadkeyAdjustPos(LselectionStart, -dn + s._kmwLength()); // I3318
}
DOMEventHandlers.states._Selection = Ldv.createRange();
DOMEventHandlers.states._Selection.select();
DOMEventHandlers.states._Selection.scrollIntoView();
// Mozilla et al; IE9+ also recognizes setSelectionRange, but does not seem to work in exactly the same way as Mozilla
} else if (Pelem.setSelectionRange) {
var LselectionStart, LselectionEnd;
@ -636,7 +588,7 @@ class KeyboardInterface {
* Description Build reate list of styles that can be applied in iframes
*/
private _CacheCommands = function(_Document: Document): StyleCommand[] { // I1204 - style application in IFRAMEs, I2192, I2134, I2192
//var _CacheableBackColor=(_Document.selection?'hilitecolor':'backcolor');
//var _CacheableBackColor='backcolor';
var _CacheableCommands=[
new StyleCommand('backcolor',1), new StyleCommand('fontname',1), new StyleCommand('fontsize',1),

View file

@ -140,9 +140,6 @@ if(!window['keyman']['initialized']) {
}
//Lelem.scrollIntoView(); //***temporarily disabled, JMD 23/12/11
//keymanweb._DivDebug.innerHTML = keymanweb._DivDebug.innerHTML + '<br>'+keymanweb._DebugDepth+Ps;
//if(!document.selection)
// keymanweb._DivDebug.scrollTop = (keymanweb._DivDebug.scrollHeight - keymanweb._DivDebug.clientHeight<0 ? 0 :
// keymanweb._DivDebug.scrollHeight - keymanweb._DivDebug.clientHeight);
}
}
@ -161,56 +158,25 @@ if(!window['keyman']['initialized']) {
_DebugDeadKeys = function(Pelem, Ps)
{
var Lt = "", Li, Lp = 0, Ls, Lj;
if(document.selection)
// if(!keymanweb._IE) return true; //added test to avoid compiler warning 27/8 JMD // Commented-out after removal of document.selection 25/01/18 JAH
// Mozilla debug (table formatting removed)
if(Pelem.tagName == 'HTML') Ls = Pelem.innerHTML; else Ls = Pelem.value; Lt = ''; //span style="font-size: 12pt">';
if(typeof(Ls) === 'undefined') return;
for(Li = 0; Li <= Ls._kmwLength(); Li++) Lt += "<"+Ls._kmwCharAt(Li)+">"; //I3319
for(Li = 0; Li <= Ls._kmwLength(); Li++) //I3319
{
// IE debug
for(Li = 0; Li < kbdInterface._DeadKeys.length; Li++)
for(var Lj = 0; Lj < kbdInterface._DeadKeys.length; Lj++)
{
if(kbdInterface._DeadKeys[Li].p > Lp) Lp = kbdInterface._DeadKeys[Li].p;
Lt = Lt + '['+kbdInterface._DeadKeys[Lj].p+':'+kbdInterface._DeadKeys[Lj].d+']';
}
Ls = kbdInterface.context(Lp+1, Lp+1, Pelem); Lt = '<span style="font-size: 12pt">';
if(Ls !== false && Ls._kmwLength() > Lp) //I3319
{
/* We want to show the previous character in the context */
Lt = Lt + Ls._kmwSubstr(0,1); Ls = Ls._kmwSlice(1); //I3319
}
for(Li = 0; Li <= Ls._kmwLength(); Li++) //I3319
{
for(Lj = 0; Lj < kbdInterface._DeadKeys.length; Lj++)
{
if(kbdInterface._DeadKeys[Lj].p == Ls._kmwLength() - Li) Lt = Lt + '<span style="color: red">'+kbdInterface._DeadKeys[Lj].d+'</span>'; //I3319
}
if(Li < Ls._kmwLength()) Lt = Lt + Ls._kmwCharAt(Li); //I3319
}
Lt = Lt + '</span> - ';
for(Li = 0; Li < kbdInterface._DeadKeys.length; Li++)
{
Lt = Lt + 'dk['+Li+'] = {pos: '+kbdInterface._DeadKeys[Li].p+', deadKey: '+kbdInterface._DeadKeys[Li].d+'} ';
}
_Debug(Ps + ': ' + Lt);
}
else
{
if(!keymanweb._IE) return true; //added test to avoid compiler warning 27/8 JMD
// Mozilla debug (table formatting removed)
if(Pelem.tagName == 'HTML') Ls = Pelem.innerHTML; else Ls = Pelem.value; Lt = ''; //span style="font-size: 12pt">';
if(typeof(Ls) === 'undefined') return;
for(Li = 0; Li <= Ls._kmwLength(); Li++) Lt += "<"+Ls._kmwCharAt(Li)+">"; //I3319
for(Li = 0; Li <= Ls._kmwLength(); Li++) //I3319
{
for(var Lj = 0; Lj < kbdInterface._DeadKeys.length; Lj++)
{
Lt = Lt + '['+kbdInterface._DeadKeys[Lj].p+':'+kbdInterface._DeadKeys[Lj].d+']';
}
if(Li < Ls._kmwLength()) Lt = Lt + Ls._kmwCharAt(Li);
}
//_Debug(Ps + ': ' + Lt);
//Lt = Lt + keymanweb._DebugDepth + ' &nbsp; dk['+Li+'] = {pos: '+kbdInterface._DeadKeys[Li].p+', deadKey: '+kbdInterface._DeadKeys[Li].d+'}<br>';
if(Li < Ls._kmwLength()) Lt = Lt + Ls._kmwCharAt(Li);
}
//_Debug(Ps + ': ' + Lt);
//Lt = Lt + keymanweb._DebugDepth + ' &nbsp; dk['+Li+'] = {pos: '+kbdInterface._DeadKeys[Li].p+', deadKey: '+kbdInterface._DeadKeys[Li].d+'}<br>';
/*
var Lt = "", Li, Lp = 0;

View file

@ -593,7 +593,7 @@ class DOMEventHandlers {
* Description Processes keydown event and passes data to keyboard.
*/
_KeyDown: (e: KeyboardEvent) => boolean = function(this: DOMEventHandlers, e: KeyboardEvent): boolean {
var Ldv, eClass='';
var Ldv: Document, eClass='';
var activeKeyboard = this.keyman.keyboardManager.activeKeyboard;
var osk = this.keyman.osk;
var util = this.keyman.util;
@ -648,11 +648,6 @@ class DOMEventHandlers {
this.keyman.keyboardManager.notifyKeyboard(0,Levent.Ltarg,1);
osk._UpdateVKShift(Levent, 0, 1);
}
// I1207
if((Ldv=Levent.Ltarg.ownerDocument) && (Ldv=Ldv.selection) && (Levent.Lcode<33 || Levent.Lcode>40)) {
Ldv.createRange().select();
}
if(!window.event) {
// I1466 - Convert the - keycode on mnemonic as well as positional layouts
@ -858,15 +853,6 @@ class DOMEventHandlers {
keyboardManager.notifyKeyboard(0,Levent.Ltarg,0);
osk._UpdateVKShift(Levent, 0, 1); // I2187
}
// I736 start
var Ldv;
if((Ldv=Levent.Ltarg.ownerDocument) && (Ldv=Ldv.selection) && Ldv.type != 'control') { // I1479 - avoid createRange on controls
Ldv=Ldv.createRange();
//if(Ldv.parentElement()==Levent.Ltarg) //I1505
DOMEventHandlers.states._Selection = Ldv;
}
// I736 end
return false;
}.bind(this);

View file

@ -166,18 +166,6 @@
//dbg(n+' '+ln+' '+Pelem.value._kmwSubstring(LselectionStart-n,LselectionStart-n+ln));
return Pelem.value._kmwSubstring(LselectionStart-n,LselectionStart-n+ln); //I3319, KMW-1
}
else if(Ldoc && (Ldv=Ldoc.selection)) // build 77 - use elem.ownerDocument instead of document
// I1481 - use Ldoc to get the ownerDocument when no selection is found
{
/* IE */
var Lrange = Ldv.createRange();
//if (Lrange.parentElement() == Pelem) { // build 77 - ignore parent of selection
Lrange.moveStart('character',-2*n); //I3319
return Lrange.text._kmwSubstr(-n)._kmwSubstring(0,ln); //I3319
//}
}
return "";
};

View file

@ -134,13 +134,6 @@ if(!window['keyman']['initialized']) {
LselectionEnd = keymanweb._CachedSelectionEnd; // I3319
}
tempContext = Pelem.value._kmwSubstr(0, LselectionStart);
} else if(Ldoc && (Ldv=Ldoc.selection)) { // build 77 - use elem.ownerDocument instead of document
// I1481 - use Ldoc to get the ownerDocument when no selection is found
/* IE */
var Lrange = Ldv.createRange();
//if (Lrange.parentElement() == Pelem) { // build 77 - ignore parent of selection
Lrange.moveStart('character',-2*n); // allows for supp chars //I3319
tempContext = Lrange.text;
}
if(tempContext._kmwLength() < n) {