[Pkg-mozext-commits] [autofill-forms] 02/13: fixing #4

David Prévot taffit at moszumanska.debian.org
Thu Oct 29 20:57:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository autofill-forms.

commit 0f826ac44b160c02f13d79d2ad70e9c351214d98
Author: Sarah Avilov <sarah.avilov at gmail.com>
Date:   Sun Jul 12 12:23:13 2015 +0430

    fixing #4
---
 aff.xpi                         | Bin 152327 -> 152468 bytes
 chrome/content/autofillForms.js |  14 +++++++++++---
 chrome/content/inject.js        |  21 +++++++++++++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/aff.xpi b/aff.xpi
index f198e4b..d476ab2 100644
Binary files a/aff.xpi and b/aff.xpi differ
diff --git a/chrome/content/autofillForms.js b/chrome/content/autofillForms.js
index a2fec47..1778d65 100644
--- a/chrome/content/autofillForms.js
+++ b/chrome/content/autofillForms.js
@@ -91,8 +91,8 @@ var autofillForms = {
   // current version number
   version: "1.0.4",
 
-  action: function (elem, cmd) {
-    elem.setAttribute('data-aff-' + cmd, true);
+  action: function (elem, cmd, val) {
+    elem.setAttribute('data-aff-' + cmd, val || true);
     var wm = Components.classes['@mozilla.org/appshell/window-mediator;1']
       .getService(Components.interfaces.nsIWindowMediator);
     var browser = wm.getMostRecentWindow('navigator:browser').gBrowser.selectedBrowser;
@@ -1668,12 +1668,20 @@ var autofillForms = {
       try {
         // Try to use selection information:
         var newCursorPos = this.targetFormField.selectionStart + value.length;
-        this.targetFormField.value =   this.targetFormField.value.substr(0, this.targetFormField.selectionStart)
+/*        this.targetFormField.value =   this.targetFormField.value.substr(0, this.targetFormField.selectionStart)
                         + value
                         + this.targetFormField.value.substr(this.targetFormField.selectionEnd);
         // Adjust the cursor position:
         this.targetFormField.selectionEnd = newCursorPos;
         this.targetFormField.selectionStart = newCursorPos;
+*/
+        autofillForms.action(this.targetFormField, 'value',
+          this.targetFormField.value.substr(0, this.targetFormField.selectionStart)
+            + value
+            + this.targetFormField.value.substr(this.targetFormField.selectionEnd)
+        );
+        autofillForms.action(this.targetFormField, 'selectionEnd', newCursorPos);
+        autofillForms.action(this.targetFormField, 'selectionStart', newCursorPos);
       } catch(e) {
         // This input field does not support selections - just try to set the value:
         try {
diff --git a/chrome/content/inject.js b/chrome/content/inject.js
index 52e226a..414a1b6 100644
--- a/chrome/content/inject.js
+++ b/chrome/content/inject.js
@@ -22,3 +22,24 @@ addMessageListener('focus', function () {
     elem.focus();
   });
 });
+addMessageListener('value', function () {
+  var elems = content.document.querySelectorAll('[data-aff-value]');
+  [].forEach.call(elems, function (elem) {
+    elem.value = elem.dataset.affValue;
+    elem.removeAttribute('data-aff-value');
+  });
+});
+addMessageListener('selectionEnd', function () {
+  var elems = content.document.querySelectorAll('[data-aff-selectionEnd]');
+  [].forEach.call(elems, function (elem) {
+    elem.selectionEnd = elem.dataset.affSelectionEnd;
+    elem.removeAttribute('data-aff-selectionEnd');
+  });
+});
+addMessageListener('selectionStart', function () {
+  var elems = content.document.querySelectorAll('[data-aff-selectionStart]');
+  [].forEach.call(elems, function (elem) {
+    elem.selectionStart = elem.dataset.affSelectionStart;
+    elem.removeAttribute('data-aff-selectionStart');
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/autofill-forms.git



More information about the Pkg-mozext-commits mailing list