From 957a0aa873f2df13483a9b17589c064cc229a80a Mon Sep 17 00:00:00 2001 From: "NAGOYA, Yoshihiko" Date: Thu, 11 Oct 2012 23:39:01 +0900 Subject: [PATCH] fix Pita/etherpad-lite #1032 refact inInternationalComposition --- src/static/js/ace.js | 5 +++++ src/static/js/ace2_inner.js | 21 ++++++++++++++++++--- src/static/js/collab_client.js | 4 ++-- src/static/js/pad.js | 16 ---------------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/static/js/ace.js b/src/static/js/ace.js index e50f75c7..83ad9447 100644 --- a/src/static/js/ace.js +++ b/src/static/js/ace.js @@ -122,6 +122,11 @@ function Ace2Editor() return info.ace_getDebugProperty(prop); }; + editor.getInInternationalComposition = function() + { + return info.ace_getInInternationalComposition(); + }; + // prepareUserChangeset: // Returns null if no new changes or ACE not ready. Otherwise, bundles up all user changes // to the latest base text into a Changeset, which is returned (as a string if encodeAsString). diff --git a/src/static/js/ace2_inner.js b/src/static/js/ace2_inner.js index 652a3d25..2e56b950 100644 --- a/src/static/js/ace2_inner.js +++ b/src/static/js/ace2_inner.js @@ -1173,7 +1173,7 @@ function Ace2Inner(){ //if (! top.BEFORE) top.BEFORE = []; //top.BEFORE.push(magicdom.root.dom.innerHTML); //if (! isEditable) return; // and don't reschedule - if (window.parent.parent.inInternationalComposition) + if (inInternationalComposition) { // don't do idle input incorporation during international input composition idleWorkTimer.atLeast(500); @@ -3729,7 +3729,7 @@ function Ace2Inner(){ thisKeyDoesntTriggerNormalize = true; } - if ((!specialHandled) && (!thisKeyDoesntTriggerNormalize) && (!window.parent.parent.inInternationalComposition)) + if ((!specialHandled) && (!thisKeyDoesntTriggerNormalize) && (!inInternationalComposition)) { if (type != "keyup" || !incorpIfQuick()) { @@ -4589,9 +4589,24 @@ function Ace2Inner(){ } } + + var inInternationalComposition = false; function handleCompositionEvent(evt) { - window.parent.parent.handleCompositionEvent(evt); + // international input events, fired in FF3, at least; allow e.g. Japanese input + if (evt.type == "compositionstart") + { + inInternationalComposition = true; + } + else if (evt.type == "compositionend") + { + inInternationalComposition = false; + } + } + + editorInfo.ace_getInInternationalComposition = function () + { + return inInternationalComposition; } function bindTheEventHandlers() diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index b3e17c25..b700fc49 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -111,7 +111,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) function handleUserChanges() { - if (window.parent.parent.inInternationalComposition) return; + if (editor.getInInternationalComposition()) return; if ((!getSocket()) || channelState == "CONNECTING") { if (channelState == "CONNECTING" && (((+new Date()) - initialStartConnectTime) > 20000)) @@ -288,7 +288,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) var apool = msg.apool; // When inInternationalComposition, msg pushed msgQueue. - if (msgQueue.length > 0 || window.parent.parent.inInternationalComposition) { + if (msgQueue.length > 0 || editor.getInInternationalComposition()) { if (msgQueue.length > 0) oldRev = msgQueue[msgQueue.length - 1].newRev; else oldRev = rev; diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 21dea440..89777040 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -51,22 +51,6 @@ var randomString = require('./pad_utils').randomString; var hooks = require('./pluginfw/hooks'); -window.inInternationalComposition = false; -var inInternationalComposition = window.inInternationalComposition; - -window.handleCompositionEvent = function handleCompositionEvent(evt) - { - // international input events, fired in FF3, at least; allow e.g. Japanese input - if (evt.type == "compositionstart") - { - this.inInternationalComposition = true; - } - else if (evt.type == "compositionend") - { - this.inInternationalComposition = false; - } - } - function createCookie(name, value, days, path) { if (days)