Browse Source

It works!

Douglas William Thrift 9 years ago
parent
commit
ea7ce22fb5
2 changed files with 48 additions and 5 deletions
  1. 46 3
      bootstrap.js
  2. 2 2
      install.rdf

+ 46 - 3
bootstrap.js

@@ -69,6 +69,9 @@ let observer = {
         if (!binding || !("editor" in binding) || !binding.editor)
             return;
 
+        binding._inputHistory = [];
+        binding._inputHistoryIndex = 0;
+
         binding.editor.addEventListener("keypress", this.onKeyPress, true);
     },
     removeArrowListener: function(browser)
@@ -79,15 +82,55 @@ let observer = {
             return;
 
         binding.editor.removeEventListener("keypress", this.onKeyPress, true);
+
+        delete binding._inputHistoryIndex;
+        delete binding._inputHistory;
     },
     onKeyPress: function(event)
     {
-        if (!event.ctrlKey || ((event.keyCode != event.DOM_VK_UP) && (event.keyCode != event.DOM_VK_DOWN)) || event.altKey || event.metaKey || event.shiftKey)
+        var editor = event.target;
+        var binding = editor.ownerDocument.getBindingParent(editor);
+
+        switch (event.keyCode)
+        {
+        case event.DOM_VK_RETURN:
+        case event.DOM_VK_ENTER:
+            if (!event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey && editor.value.length != 0 && editor.value != binding._inputHistory[binding._inputHistory.length - 1])
+            {
+                binding._inputHistory.push(editor.value);
+
+                binding._inputHistoryIndex = binding._inputHistory.length;
+            }
+
             return;
+        case event.DOM_VK_UP:
+        case event.DOM_VK_DOWN:
+            if (event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && binding._inputHistory.length != 0)
+                break;
+
+        default:
+            return;
+        }
+
+        switch (event.keyCode)
+        {
+        case event.DOM_VK_UP:
+            if (binding._inputHistoryIndex == 0)
+                return;
+
+            --binding._inputHistoryIndex;
+
+            break;
+        case event.DOM_VK_DOWN:
+            if (binding._inputHistoryIndex == binding._inputHistory.length)
+                return;
+
+            ++binding._inputHistoryIndex;
+        }
 
-        event.preventDefault();
+        editor.value = binding._inputHistoryIndex != binding._inputHistory.length ? binding._inputHistory[binding._inputHistoryIndex] : "";
 
-        Services.console.logStringMessage(event);
+        editor.setSelectionRange(editor.value.length, editor.value.length);
     },
 };
 

+ 2 - 2
install.rdf

@@ -8,8 +8,8 @@
         <em:targetApplication>
             <Description>
                 <em:id>{33cb9019-c295-46dd-be21-8c4936574bee}</em:id>
-                <em:minVersion>0.3b1</em:minVersion>
-                <em:maxVersion>1.0.*</em:maxVersion>
+                <em:minVersion>1.0</em:minVersion>
+                <em:maxVersion>1.*</em:maxVersion>
             </Description>
         </em:targetApplication>
         <em:name>Input History</em:name>