Skip to content
Browse files

global history

  • Loading branch information...
1 parent bc35ca5 commit ae5ce1540d46ef83bf97201e903abdb40cd73ef9 @paulrouget committed
Showing with 34 additions and 4 deletions.
  1. +30 −3 bootstrap.js
  2. +4 −1 chrome/jsterm.js
  3. BIN jsterm.xpi
View
33 bootstrap.js
@@ -181,6 +181,7 @@ let JSTermManager = {
this.updateCheckboxStatus(aBrowser.ownerDocument.defaultView);
},
closeForBrowser: function(aBrowser) {
+ JSTermGlobalHistory.saveToPref();
let term = this._map.get(aBrowser);
if (!term)
return;
@@ -310,6 +311,7 @@ let JSTermGlobalHistory = {
}
}
},
+
add: function(aEntry) {
if (!aEntry) {
return;
@@ -325,12 +327,32 @@ let JSTermGlobalHistory = {
this._cut();
}
},
+
initFromPref: function() {
+ let history = [];
+
+ // Try to load history from pref
+ if (Services.prefs.prefHasUserValue("devtools.jsterm.history")) {
+ try {
+ history = JSON.parse(Services.prefs.getCharPref("devtools.jsterm.history"));
+ } catch(e) {
+ // User pref is malformated.
+ Cu.reportError("Could not parse pref `devtools.jsterm.history`: " + e);
+ }
+ }
+
+ if (Array.isArray(history)) {
+ this._entries = history;
+ } else {
+ Cu.reportError("History (devtools.jsterm.history) is malformated.");
+ this._entries = [];
+ }
},
+
saveToPref: function() {
+ Services.prefs.setCharPref("devtools.jsterm.history", JSON.stringify(this._entries));
},
-
_cursors: [],
getCursor: function(aInitialValue) {
let cursor = {idx: this._entries.length,
@@ -339,9 +361,11 @@ let JSTermGlobalHistory = {
this._cursors.push(cursor);
return cursor;
},
+
releaseCursor: function(cursor) {
this._cursors[cursor.idx] = null;
},
+
getEntryForCursor: function(cursor) {
if (cursor.idx < 0) {
return "";
@@ -351,12 +375,15 @@ let JSTermGlobalHistory = {
return cursor.initialEntry;
}
},
+
canGoBack: function(cursor) {
return (cursor.idx > 0)
},
+
canGoForward: function(cursor) {
return (cursor.idx < cursor.origin);
},
+
goBack: function(cursor) {
if (this.canGoBack(cursor)) {
cursor.idx--;
@@ -365,6 +392,7 @@ let JSTermGlobalHistory = {
return false;
}
},
+
goForward: function(cursor) {
if (this.canGoForward(cursor)) {
cursor.idx++;
@@ -374,5 +402,4 @@ let JSTermGlobalHistory = {
}
},
}
-
-
+JSTermGlobalHistory.initFromPref();
View
5 chrome/jsterm.js
@@ -7,13 +7,13 @@ Cu.import("resource:///modules/WebConsoleUtils.jsm");
* Todo
* . keybindings for linux & windows
* . print() is slow
- * . save history and share it
* . Use jsm's
* . make width/height persistent
* . delete listeners & map
* . underline the current autocompletion item
* . :connectToCurrentTab
* . :connect (remote protocole)
+ * . ctrl-r
*/
const JSTERM_MARK = "orion.annotation.jstermobject";
@@ -415,6 +415,9 @@ let JSTermUI = {
this.completion.destroy();
this.completion = null;
this.treeview = null;
+ this.input = null;
+ this.output = null;
+ this.objects = null;
},
inspect: function(obj, filter) {
View
BIN jsterm.xpi
Binary file not shown.

0 comments on commit ae5ce15

Please sign in to comment.
Something went wrong with that request. Please try again.