Skip to content

Commit 9cff008

Browse files
committed
Fix errors when a comment is selected. Also disable autocomplete when editing a comment
1 parent f8341b8 commit 9cff008

File tree

2 files changed

+75
-59
lines changed

2 files changed

+75
-59
lines changed

ide/main/src/content/editor.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,13 @@ Editor.prototype.reload = function () {
10911091
};
10921092

10931093
Editor.prototype.showReference = function (command) {
1094-
var def = command.getDefinition();
1095-
if (def) {
1096-
this.infoPanel.switchView(this.infoPanel.helpView);
1097-
this.log.debug("showReference: " + def.name);
1098-
this.reference.show(def, command);
1094+
if (command.type == 'command') {
1095+
var def = command.getDefinition();
1096+
if (def) {
1097+
this.infoPanel.switchView(this.infoPanel.helpView);
1098+
this.log.debug("showReference: " + def.name);
1099+
this.reference.show(def, command);
1100+
}
10991101
}
11001102
};
11011103

ide/main/src/content/treeView.js

+68-54
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ objectExtend(TreeView.prototype, {
8787
onEvent : function(evt) {}
8888
};
8989
this.tree.controllers.appendController(controller);
90-
91-
// this.atomService = Components.classes["@mozilla.org/atom-service;1"].
92-
// getService(Components.interfaces.nsIAtomService);
93-
9490
this._loadSeleniumCommands();
9591
},
9692

@@ -123,13 +119,22 @@ objectExtend(TreeView.prototype, {
123119
return this.clipboard;
124120
},
125121

126-
setTextBox: function(id,value,disabled) {
127-
this.document.getElementById(id).value = value;
128-
this.document.getElementById(id).disabled = disabled;
122+
updateTextBox: function(id, value, disabled, autoComplete) {
123+
var e = this.document.getElementById(id);
124+
e.value = value;
125+
e.disabled = disabled;
126+
if (arguments.length == 4) {
127+
e.disableAutoComplete = !autoComplete;
128+
if (autoComplete) {
129+
e.setAttribute("enablehistory", 'true');
130+
} else {
131+
e.removeAttribute("enablehistory");
132+
}
133+
}
129134
},
130135

131136
updateTarget: function(value, disabled) {
132-
this.setTextBox("commandTarget", value, disabled);
137+
this.updateTextBox("commandTarget", value, disabled);
133138
this.document.getElementById('selectElementButton').disabled = disabled;
134139
this.document.getElementById('findElementButton').disabled = disabled;
135140
},
@@ -202,21 +207,21 @@ objectExtend(TreeView.prototype, {
202207
var command = this.currentCommand;
203208
var candidates = [];
204209
var targetBox = this.document.getElementById("commandTarget");
205-
206-
// various strategies for auto-populating the target field
207-
if (command.isRollup() && Editor.rollupManager) {
208-
candidates = Editor.rollupManager.getRollupRulesForDropdown();
209-
}
210-
else {
211-
if (command.targetCandidates) {
212-
candidates = candidates.concat(command.targetCandidates);
213-
}
214-
// if lastURL exists, load only those targets associated with it.
215-
// Otherwise, show all possible targets.
216-
if (Editor.uiMap) {
217-
candidates = candidates
218-
.concat(Editor.uiMap.getUISpecifierStringStubs());
219-
}
210+
211+
if (command.type == 'command') {
212+
// various strategies for auto-populating the target field
213+
if (command.isRollup() && Editor.rollupManager) {
214+
candidates = Editor.rollupManager.getRollupRulesForDropdown();
215+
} else {
216+
if (command.targetCandidates) {
217+
candidates = candidates.concat(command.targetCandidates);
218+
}
219+
// if lastURL exists, load only those targets associated with it.
220+
// Otherwise, show all possible targets.
221+
if (Editor.uiMap) {
222+
candidates = candidates.concat(Editor.uiMap.getUISpecifierStringStubs());
223+
}
224+
}
220225
}
221226

222227
if (candidates.length > 0) {
@@ -233,7 +238,7 @@ objectExtend(TreeView.prototype, {
233238
XulUtils.toXPCOMArray(types));
234239
this.updateTarget(this.encodeText(command.target), false);
235240
} else {
236-
targetBox.setAttribute("enablehistory", "false");
241+
targetBox.removeAttribute("enablehistory");
237242
targetBox.disableAutoComplete = true;
238243
this.updateTarget(this.encodeText(command.target), false);
239244
}
@@ -257,8 +262,7 @@ objectExtend(TreeView.prototype, {
257262
args[name] = "";
258263
keys.push(name);
259264
}
260-
this.setTextBox('commandValue',
261-
this.encodeText(to_kwargs(args, keys)), false);
265+
this.updateTextBox('commandValue', this.encodeText(to_kwargs(args, keys)), false);
262266
}
263267
}
264268
},
@@ -274,15 +278,21 @@ objectExtend(TreeView.prototype, {
274278
},
275279

276280
encodeText: function(text) {
277-
text = text.replace(/\\/g, "\\\\");
278-
text = text.replace(/\n/g, "\\n");
279-
return text;
281+
if (text) {
282+
text = text.replace(/\\/g, "\\\\");
283+
text = text.replace(/\n/g, "\\n");
284+
return text;
285+
}
286+
return '';
280287
},
281288

282289
decodeText: function(text) {
283-
text = text.replace(/\\n/g, "\n");
284-
text = text.replace(/\\\\/g, "\\");
285-
return text;
290+
if (text) {
291+
text = text.replace(/\\n/g, "\n");
292+
text = text.replace(/\\\\/g, "\\");
293+
return text;
294+
}
295+
return '';
286296
},
287297

288298
/*
@@ -326,23 +336,25 @@ objectExtend(TreeView.prototype, {
326336
var command = this.getCommand(this.tree.currentIndex);
327337
this.currentCommand = command;
328338
if (command.type == 'command') {
329-
this.setTextBox("commandAction", command.command, false);
339+
this.updateTextBox("commandAction", command.command, false, true);
330340
this.updateSeleniumTargets();
331-
this.setTextBox("commandValue", this.encodeText(command.value), false);
341+
this.updateTextBox("commandValue", this.encodeText(command.value), false);
332342
} else if (command.type == 'comment') {
333-
this.setTextBox("commandAction", command.comment, false);
343+
this.updateTextBox("commandAction", command.comment, false, false);
334344
this.updateTarget('', true);
335-
this.setTextBox("commandValue", '', true);
345+
this.updateTextBox("commandValue", '', true);
336346
}
337-
347+
338348
this.selectRecordIndex(this.tree.currentIndex);
339-
this.editor.showReference(command);
340-
this.editor.showUIReference(command.target);
341-
this.editor.showRollupReference(command);
349+
if (command.type == 'command') {
350+
this.editor.showReference(command);
351+
this.editor.showUIReference(command.target);
352+
this.editor.showRollupReference(command);
353+
}
342354
} else {
343-
this.setTextBox("commandAction", '', true);
355+
this.updateTextBox("commandAction", '', true);
344356
this.updateTarget('', true);
345-
this.setTextBox("commandValue", '', true);
357+
this.updateTextBox("commandValue", '', true);
346358
this.currentCommand = null;
347359
}
348360
window.updateCommands('select');
@@ -358,8 +370,10 @@ objectExtend(TreeView.prototype, {
358370
if (this.currentCommand != null) {
359371
this.executeAction(new TreeView.UpdateCommandAction(this, key, value));
360372
if (key == 'command') {
361-
this.updateSeleniumTargets();
362-
this.editor.showReference(this.currentCommand);
373+
if (this.currentCommand.type == 'command') {
374+
this.updateSeleniumTargets();
375+
this.editor.showReference(this.currentCommand);
376+
}
363377
}
364378
else if (key == 'targetCandidates') {
365379
this.updateSeleniumTargets();
@@ -379,9 +393,9 @@ objectExtend(TreeView.prototype, {
379393
}
380394
},
381395
onHide: function() {
382-
this.setTextBox("commandAction", '', true);
396+
this.updateTextBox("commandAction", '', true);
383397
this.updateTarget('', true);
384-
this.setTextBox("commandValue", '', true);
398+
this.updateTextBox("commandValue", '', true);
385399
this.currentCommand = null;
386400
},
387401
getRecordIndex: function() {
@@ -646,7 +660,7 @@ TreeView.UpdateCommandAction = function(treeView, key, value) {
646660
this.value = value;
647661
this.index = this.treeView.tree.currentIndex;
648662
this.wasNewCommand = this.command == treeView.newCommand;
649-
}
663+
};
650664

651665
TreeView.UpdateCommandAction.prototype = {
652666
execute: function() {
@@ -689,12 +703,12 @@ TreeView.UpdateCommandAction.prototype = {
689703
this.treeView.selectCommand();
690704
}
691705
}
692-
}
706+
};
693707

694708
TreeView.DeleteCommandAction = function(treeView, ranges) {
695709
this.treeView = treeView;
696710
this.ranges = ranges;
697-
}
711+
};
698712

699713
TreeView.DeleteCommandAction.prototype = {
700714
execute: function() {
@@ -730,13 +744,13 @@ TreeView.DeleteCommandAction.prototype = {
730744
}
731745
this.treeView.selection.select(currentIndex);
732746
}
733-
}
747+
};
734748

735749
TreeView.PasteCommandAction = function(treeView, index, commands) {
736750
this.treeView = treeView;
737751
this.index = index;
738752
this.commands = commands;
739-
}
753+
};
740754

741755
TreeView.PasteCommandAction.prototype = {
742756
execute: function() {
@@ -767,7 +781,7 @@ TreeView.PasteCommandAction.prototype = {
767781
this.treeView.selection.select(currentIndex);
768782
this.treeView.treebox.ensureRowIsVisible(currentIndex);
769783
}
770-
}
784+
};
771785

772786
//D'n'D action for the undo/redo process
773787
TreeView.dndCommandAction = function(treeView, sourceIndex, dropIndex, orientation){
@@ -786,7 +800,7 @@ TreeView.dndCommandAction = function(treeView, sourceIndex, dropIndex, orientati
786800
this.sourceIndexU++;
787801
}
788802
this.orientationU = this.orientation == Ci.nsITreeView.DROP_BEFORE ? Ci.nsITreeView.DROP_AFTER : Ci.nsITreeView.DROP_BEFORE;
789-
}
803+
};
790804

791805
TreeView.dndCommandAction.prototype = {
792806

@@ -834,4 +848,4 @@ TreeView.dndCommandAction.prototype = {
834848
}
835849

836850
}
837-
}
851+
};

0 commit comments

Comments
 (0)