Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Makes input tools and firststrong compatible.

R=shuchen,wuyingbing,nicksantos,ajp,nkerem
DELTA=85 (78 added, 0 deleted, 7 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6249


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2503 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
commit 44d7d0b62ff943c85cf9d3d9aa92f314414d0792 1 parent 8f91c4e
fengyuan@google.com authored
View
34 closure/goog/editor/plugins/firststrong.js
@@ -117,6 +117,15 @@ goog.editor.plugins.FirstStrong.prototype.handleSelectionChange =
};
+/**
+ * The name of the attribute which records the input text.
+ *
+ * @type {string}
+ * @const
+ */
+goog.editor.plugins.FirstStrong.INPUT_ATTRIBUTE = 'fs-input';
+
+
/** @override */
goog.editor.plugins.FirstStrong.prototype.handleKeyPress = function(e) {
if (!this.isNewBlock_) {
@@ -126,12 +135,27 @@ goog.editor.plugins.FirstStrong.prototype.handleKeyPress = function(e) {
if (e.ctrlKey || e.metaKey) {
return false;
}
- var newChar = goog.i18n.uChar.fromCharCode(e.charCode);
- if (!newChar) {
- return false; // Unrecognized key.
+ var newInput = goog.i18n.uChar.fromCharCode(e.charCode);
+
+ if (!newInput) {
+ var browserEvent = e.getBrowserEvent();
+ if (browserEvent) {
+ if (goog.userAgent.IE && browserEvent['getAttribute']) {
+ newInput = browserEvent['getAttribute'](
+ goog.editor.plugins.FirstStrong.INPUT_ATTRIBUTE);
+ } else {
+ newInput = browserEvent[
+ goog.editor.plugins.FirstStrong.INPUT_ATTRIBUTE];
+ }
+ }
+ }
+
+ if (!newInput) {
+ return false; // Unrecognized key.
}
- var isLtr = goog.i18n.bidi.isLtrChar(newChar);
- var isRtl = !isLtr && goog.i18n.bidi.isRtlChar(newChar);
+
+ var isLtr = goog.i18n.bidi.isLtrChar(newInput);
+ var isRtl = !isLtr && goog.i18n.bidi.isRtlChar(newInput);
if (!isLtr && !isRtl) {
return false; // This character cannot change anything (it is not Strong).
}
View
30 closure/goog/editor/plugins/firststrong_test.html
@@ -364,6 +364,36 @@
assertLTR();
}
+function testFirstStrongCharacterFromIME_RTL() {
+ field.setHtml(false, '<div id="text">123.7 3121, </div>');
+ field.focusAndPlaceCursorAtStart();
+ var attributes = {};
+ attributes[goog.editor.plugins.FirstStrong.INPUT_ATTRIBUTE] = 'אבג';
+ goog.testing.events.fireNonAsciiKeySequence(fieldElement, 0, 0, attributes);
+ if (goog.userAgent.IE) {
+ // goog.testing.events.fireNonAsciiKeySequence doesn't send KEYPRESS event
+ // so no command is expected.
+ assertNoCommand();
+ } else {
+ assertRTL();
+ }
+}
+
+function testFirstCharacterFromIME_LTR() {
+ field.setHtml(false, '<div dir="rtl" id="text"> 1234 </div>');
+ field.focusAndPlaceCursorAtStart();
+ var attributes = {};
+ attributes[goog.editor.plugins.FirstStrong.INPUT_ATTRIBUTE] = 'ABC';
+ goog.testing.events.fireNonAsciiKeySequence(fieldElement, 0, 0, attributes);
+ if (goog.userAgent.IE) {
+ // goog.testing.events.fireNonAsciiKeySequence doesn't send KEYPRESS event
+ // so no command is expected.
+ assertNoCommand();
+ } else {
+ assertLTR();
+ }
+}
+
function assertRTL() {
assertEquals(goog.editor.Command.DIR_RTL, triggeredCommand);
}
Please sign in to comment.
Something went wrong with that request. Please try again.