Skip to content

Add the ability to collapse nodes in the outline for XML. #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ define(function (require, exports, module) {
var $entry = $(document.createElement("li"));
$entry.addClass("outline-entry");
$entry.addClass(entry.classes);
$entry.attr("id", entry.id);
$entry.append(entry.$html);
$entry.click({
line: entry.line,
Expand Down
37 changes: 28 additions & 9 deletions src/languages/XML.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@ define(function (require, exports, module) {
var $elements = [];
if (indent) {
var $indentation = $(document.createElement("span"));
$indentation.addClass("outline-entry-indent");
var interpunct = "";
for (var i = 0; i < indent; i++) {
interpunct += "·";
}
$indentation.text(interpunct);
$indentation.addClass("outline-entry-indent open")
.text(interpunct)
.attr("data-indent", indent)
.click(function(){
// Collapse the child nodes when this node is clicked.
var indentElementParent = $(this).parent();
var nextParent = indentElementParent.next();
// Look at all subsequent nodes with a greater indent than the current node
// to see if they should be hidden or shown.
while (Number(nextParent.children(".outline-entry-indent").attr("data-indent")) > indent ){
if(nextParent.attr("data-closed-by") === indentElementParent[0].id){
nextParent.removeAttr("data-closed-by");
indentElementParent.children(".outline-entry-indent.closed").addClass("open").removeClass("closed");
nextParent.show();
} else if(nextParent.attr("data-closed-by") === undefined) {
nextParent.attr("data-closed-by", indentElementParent[0].id);
indentElementParent.children(".outline-entry-indent.open").addClass("closed").removeClass("open");
nextParent.hide();
}
nextParent = nextParent.next();
}
});
$elements.push($indentation);
}
if (namespace) {
Expand Down Expand Up @@ -43,13 +63,7 @@ define(function (require, exports, module) {
if (!whitespace) {
return 0;
}
var indentSize = Editor.getUseTabChar() ? Editor.getTabSize() : Editor.getSpaceUnits();
var tmpSpaces = "";
for (var i = 0; i < indentSize; i++) {
tmpSpaces += " ";
}
whitespace = whitespace.replace(/\t/g, tmpSpaces);
return (whitespace.length / indentSize) | 0;
return whitespace.length;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation seems off here.

}

/**
Expand All @@ -62,9 +76,11 @@ define(function (require, exports, module) {
var lines = text.split("\n");
var regex = /^(\s*)<([\w]+:)?([\w.:-]+)(?:[^>]*?(id|class)=["']([\w- ]+)["'])?/g;
var result = [];
var idCounter = 0;
lines.forEach(function (line, index) {
var match = regex.exec(line);
while (match !== null) {
idCounter = idCounter + 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ++ or += 1 please.

var whitespace = match[1];
var namespace = showArguments ? (match[2] || "").trim() : "";
var name = match[3].trim();
Expand All @@ -73,6 +89,9 @@ define(function (require, exports, module) {
var entry = _createListEntry(namespace, name, type, args, _getIndentationLevel(whitespace));
entry.line = index;
entry.ch = line.length;
// Add an id so the collapse can mark the collapsed nodes and so control
// what can reopen them.
entry.id = "ListEntry" + idCounter.toString();
result.push(entry);
match = regex.exec(line);
}
Expand Down
10 changes: 10 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,13 @@
.outline-entry-xml-class {
color: #adb9bd;
}

.outline-entry-indent.open:before {
content: "\f30f";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent by 4 spaces.

font-family: Ionicons;
}

.outline-entry-indent.closed:before {
content: "\f366";
font-family: Ionicons;
}