importScript("ace/ace.js");
WebInspector.AceTextEditor = function(url, delegate)
{
WebInspector.View.call(this);
this._delegate = delegate;
this._url = url;
this.element.className = "ace-editor-container source-code";
var prefix = window.flattenImports ? "" : "ace/";
ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_javascript.js");
ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_css.js");
ace.config.setModuleUrl("ace/mode/javascript", prefix + "mode_html.js");
ace.config.setModuleUrl("ace/theme/textmate", prefix + "theme_textmate.js");
this._aceEditor = window.ace.edit(this.element);
this._aceEditor.setShowFoldWidgets(false);
this._aceEditor.session.setFixedGutterWidth(true);
this._aceEditor.on("gutterclick", this._gutterClick.bind(this));
this._aceEditor.on("change", this._onTextChange.bind(this));
this._aceEditor.setHighlightActiveLine(false);
this._aceEditor.session.setUseWorker(false);
this.registerRequiredCSS("ace/acedevtools.css");
this._attributes = [];
}
WebInspector.AceTextEditor.prototype = {
_updateBreakpoints: function()
{
this._aceEditor.session.clearBreakpoints();
for(var i in this._attributes) {
var breakpoint = this.getAttribute(i, "ace_breakpoint");
if (!breakpoint)
continue;
var className = breakpoint.conditional ? "webkit-breakpoint-conditional" : "webkit-breakpoint";
if (breakpoint.disabled) className += " webkit-breakpoint-disabled";
this._aceEditor.session.setBreakpoint(i, className);
}
},
_updateLineAttributes: function(delta) {
var range = delta.range;
var length, insertionIndex;
if (range.end.row === range.start.row)
return;
if (delta.action === "insertText") {
length = range.end.row - range.start.row;
insertionIndex = range.start.column === 0 ? range.start.row: range.start.row + 1;
} else if (delta.action === "insertLines") {
length = range.end.row - range.start.row;
insertionIndex = range.start.row;
} else if (delta.action === "removeText") {
length = range.start.row - range.end.row;
insertionIndex = range.start.row;
} else if (delta.action === "removeLines") {
length = range.start.row - range.end.row;
insertionIndex = range.start.row;
}
if (length > 0) {
var spliceArguments = new Array(length);
spliceArguments.unshift(insertionIndex, 0);
Array.prototype.splice.apply(this._attributes, spliceArguments);
} else if (length < 0) {
this._attributes.splice(insertionIndex, -length);
}
this._updateBreakpoints();
},
_onTextChange: function(event)
{
this._updateLineAttributes(event.data);
this._delegate.onTextChanged(null, null);
},
_gutterClick: function(event)
{
var lineNumber = parseInt(event.domEvent.target.textContent) - 1;
this.dispatchEventToListeners(WebInspector.TextEditor.Events.GutterClick, { lineNumber: lineNumber, event: event.domEvent });
},
set mimeType(mimeType)
{
switch(mimeType) {
case "text/html":
this._aceEditor.getSession().setMode("ace/mode/html");
break;
case "text/css":
this._aceEditor.getSession().setMode("ace/mode/css");
break;
case "text/javascript":
this._aceEditor.getSession().setMode("ace/mode/javascript");
break;
}
},
setReadOnly: function(readOnly)
{
this._aceEditor.setReadOnly(readOnly);
},
readOnly: function()
{
return this._aceEditor.getReadOnly();
},
focus: function()
{
this._aceEditor.focus();
},
defaultFocusedElement: function()
{
return this.element.firstChild;
},
highlightRegex: function(regex, cssClass)
{
console.log("aceEditor.highlightRegex not implemented");
},
highlightRange: function(range, cssClass)
{
console.log("aceEditor.highlightRange not implemented");
},
removeHighlight: function(highlightDescriptor)
{
console.log("aceEditor.removeHighlight not implemented");
},
revealLine: function(lineNumber) {
this._aceEditor.scrollToLine(lineNumber, false, true);
},
addBreakpoint: function(lineNumber, disabled, conditional)
{
this.setAttribute(lineNumber, "ace_breakpoint", {
disabled: disabled,
conditional: conditional
});
this._updateBreakpoints();
},
removeBreakpoint: function(lineNumber)
{
this.removeAttribute(lineNumber, "ace_breakpoint");
this._updateBreakpoints();
},
setExecutionLine: function(lineNumber)
{
this._executionLine = lineNumber;
const Range = ace.require('ace/range').Range;
this._executionLineMarker = this._aceEditor.session.addMarker(new Range(lineNumber, 0, lineNumber, Infinity), "webkit-execution-line", "fullLine");
this._aceEditor.session.addGutterDecoration(lineNumber, "webkit-gutter-execution-line");
},
copyRange: function(range)
{
console.log("aceEditor.copyRange not implemented");
return "";
},
clearExecutionLine: function()
{
this._aceEditor.session.removeMarker(this._executionLineMarker);
this._aceEditor.session.removeGutterDecoration(this._executionLine, "webkit-gutter-execution-line");
},
addDecoration: function(lineNumber, element)
{
console.log("aceEditor.addDecoration not implemented");
},
removeDecoration: function(lineNumber, element)
{
console.log("aceEditor.removeDecoration not implemented");
},
markAndRevealRange: function(range)
{
console.log("aceEditor.markAndRevealRange not implemented");
},
highlightLine: function(lineNumber)
{
console.log("aceEditor.highlightLine not implemented");
},
clearLineHighlight: function() {
console.log("aceEditor.clearLineHighlight not implemented");
},
elementsToRestoreScrollPositionsFor: function()
{
return [];
},
inheritScrollPositions: function(textEditor)
{
console.log("aceEditor.inheritScrollPositions not implemented");
},
beginUpdates: function() { },
endUpdates: function() { },
onResize: function() { },
editRange: function(range, text)
{
console.log("aceEditor.editRange not implemented");
},
scrollToLine: function(lineNumber)
{
this._aceEditor.scrollToLine(lineNumber, false, true);
},
selection: function()
{
console.log("aceEditor.selection not implemented");
},
lastSelection: function()
{
console.log("aceEditor.lastSelection not implemented");
},
setSelection: function(textRange)
{
this._aceEditor.scrollToLine(textRange.startLine, true);
},
setText: function(text)
{
this._aceEditor.getSession().setValue(text);
},
text: function()
{
return this._aceEditor.getSession().getValue();
},
range: function()
{
console.log("aceEditor.range not implemented");
},
line: function(lineNumber)
{
return this._aceEditor.getSession().getLine(lineNumber);
},
get linesCount() {
return this._aceEditor.getSession().getLength();
},
getAttribute: function(line, name)
{
var attrs = this._attributes[line];
return attrs ? attrs[name] : null;
},
setAttribute: function(line, name, value)
{
var attrs = this._attributes[line];
if (!attrs) {
attrs = {};
this._attributes[line] = attrs;
}
attrs[name] = value;
},
removeAttribute: function(line, name)
{
var attrs = this._attributes[line];
if (attrs)
delete attrs[name];
},
wasShown: function() { },
__proto__: WebInspector.View.prototype
}