1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Fix text editor for Internet Explorer

By switching from text events to execCommand.
This commit is contained in:
Jermolene 2016-04-30 14:36:53 +01:00
parent 3bd5d49933
commit 1515fd42ed
2 changed files with 16 additions and 20 deletions

View File

@ -176,20 +176,16 @@ FramedEngine.prototype.executeTextOperation = function(operation) {
// Perform the required changes to the text area and the underlying tiddler // Perform the required changes to the text area and the underlying tiddler
var newText = operation.text; var newText = operation.text;
if(operation.replacement !== null) { if(operation.replacement !== null) {
// Work around the problem that textInput can't be used directly to delete text without also replacing it with a non-zero length string
if(operation.replacement === "") {
operation.replacement = operation.text.substring(0,operation.cutStart) + operation.text.substring(operation.cutEnd);
operation.cutStart = 0;
operation.cutEnd = operation.text.length;
}
newText = operation.text.substring(0,operation.cutStart) + operation.replacement + operation.text.substring(operation.cutEnd); newText = operation.text.substring(0,operation.cutStart) + operation.replacement + operation.text.substring(operation.cutEnd);
// Attempt to use a TextEvent to modify the value of the control // Attempt to use a execCommand to modify the value of the control
var textEvent = this.domNode.ownerDocument.createEvent("TextEvent"); if(this.iframeDoc.queryCommandSupported("insertText") && this.iframeDoc.queryCommandSupported("delete") && !$tw.browser.isFirefox) {
if(textEvent.initTextEvent) {
textEvent.initTextEvent("textInput", true, true, null, operation.replacement, 9, "en-US");
this.domNode.focus(); this.domNode.focus();
this.domNode.setSelectionRange(operation.cutStart,operation.cutEnd); this.domNode.setSelectionRange(operation.cutStart,operation.cutEnd);
this.domNode.dispatchEvent(textEvent); if(operation.replacement === "") {
this.iframeDoc.execCommand("delete",false,"");
} else {
this.iframeDoc.execCommand("insertText",false,operation.replacement);
}
} else { } else {
this.domNode.value = newText; this.domNode.value = newText;
} }
@ -204,20 +200,19 @@ FramedEngine.prototype.executeTextOperation = function(operation) {
Execute a command Execute a command
*/ */
FramedEngine.prototype.execCommand = function(command) { FramedEngine.prototype.execCommand = function(command) {
var isFirefox = !!document.mozFullScreenEnabled, var msg = "Warning: the '" + command + "' button does not work in Firefox without installing the CodeMirror plugin.\n\n(Standard operating system keyboard shortcuts will work correctly)";
msg = "Warning: the '" + command + "' button does not work in Firefox without installing the CodeMirror plugin.\n\n(Standard operating system keyboard shortcuts will work correctly)";
this.iframeNode.focus(); this.iframeNode.focus();
this.domNode.focus(); this.domNode.focus();
switch(command) { switch(command) {
case "undo": case "undo":
if(isFirefox) { if($tw.browser.isFirefox) {
alert(msg); alert(msg);
} else { } else {
this.iframeDoc.execCommand("undo",false,null); this.iframeDoc.execCommand("undo",false,null);
} }
break; break;
case "redo": case "redo":
if(isFirefox) { if($tw.browser.isFirefox) {
alert(msg); alert(msg);
} else { } else {
this.iframeDoc.execCommand("redo",false,null); this.iframeDoc.execCommand("redo",false,null);

View File

@ -27,6 +27,7 @@ exports.startup = function() {
// Minimal browser detection // Minimal browser detection
if($tw.browser) { if($tw.browser) {
$tw.browser.isIE = (/msie|trident/i.test(navigator.userAgent)); $tw.browser.isIE = (/msie|trident/i.test(navigator.userAgent));
$tw.browser.isFirefox = !!document.mozFullScreenEnabled;
} }
// Platform detection // Platform detection
$tw.platform = {}; $tw.platform = {};