Skip to content

Commit cf6b2c4

Browse files
authored
Selection bugs fix (#51)
1 parent 722650c commit cf6b2c4

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

index.html

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
.accordion-collapse.show .accordion-body {
7474
opacity: 1;
7575
}
76-
7776
</style>
7877
</head>
7978

@@ -86,7 +85,8 @@
8685
<a class="navbar-brand" href="#">JabMap</a>
8786

8887
<!--Save and Load Buttons-->
89-
<button id="openBtn" class="btn btn-light me-2" type="button" data-bs-toggle="modal" title="Open" data-bs-target="#selectMindmapModal">
88+
<button id="openBtn" class="btn btn-light me-2" type="button" data-bs-toggle="modal" title="Open"
89+
data-bs-target="#selectMindmapModal">
9090
<i class="bi bi-folder2-open"></i> Open
9191
</button>
9292
<button id="saveBtn" class="btn btn-light me-2" type="button" data-bs-toggle="tooltip" title="Save">
@@ -102,28 +102,30 @@
102102
<div class="d-flex justify-content-center" style="flex-basis: 33%; max-width: 33%;">
103103
<!--Button class explanation: class = "btn color theme margin to the right (me-2)"-->
104104
<!--Undo Button-->
105-
<button id="undoBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip" title="Undo">
105+
<button id="undoBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip" title="Undo"
106+
disabled>
106107
<i class="bi bi-arrow-counterclockwise"></i>
107108
</button>
108109
<!--Redo Button-->
109-
<button id="redoBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip" title="Redo">
110+
<button id="redoBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip" title="Redo"
111+
disabled>
110112
<i class="bi bi-arrow-clockwise"></i>
111113
</button>
112114
<!--New Topic (sibling node) Button-->
113115
<button id="newSiblingBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip"
114-
title="New sibling node">
116+
title="New sibling node" disabled>
115117
<i class="bi bi-node-plus-fill"></i>
116118
</button>
117119
<!--New Subtopic (child node) Button (icon rotated 90 degrees)-->
118120
<button id="newChildBtn" class="btn btn-secondary me-2" type="button" data-bs-toggle="tooltip"
119-
title="New child node">
121+
title="New child node" disabled>
120122
<i class="bi bi-diagram-2-fill" style="transform: rotate(-90deg); display: inline-block;"></i>
121123
</button>
122124

123125
<!--Tags Dropdown-->
124126
<div class="dropdown">
125127
<button class="btn btn-secondary dropdown-toggle me-2" type="button" id="tagsDropdownMenuButton"
126-
data-bs-toggle="dropdown" data-bs-auto-close="outside">
128+
data-bs-toggle="dropdown" data-bs-auto-close="outside" disabled>
127129
<i class="bi bi-tags"></i>
128130
</button>
129131
<div class="dropdown-menu">
@@ -155,7 +157,7 @@ <h6 class="dropdown-header">Icons for nodes</h6>
155157
<!--BibEntry nodes Dropdown-->
156158
<div class="dropdown">
157159
<button class="btn btn-secondary dropdown-toggle me-2" id="BibEntryDropdownMenuButton"
158-
data-bs-toggle="dropdown">
160+
data-bs-toggle="dropdown" disabled>
159161
<i class="bi bi-file-earmark-text"></i>
160162
</button>
161163
<div class="dropdown-menu">
@@ -172,16 +174,20 @@ <h6 class="dropdown-header">New BibTeX node</h6>
172174
</div>
173175

174176
<div class="dropdown">
175-
<button class="btn btn-secondary dropdown-toggle me-2" id="PDFDropDownMenuButton" data-bs-toggle="dropdown">
177+
<button class="btn btn-secondary dropdown-toggle me-2" id="PDFDropDownMenuButton" data-bs-toggle="dropdown"
178+
disabled>
176179
<i class="bi bi-file-pdf"></i></i>
177180
</button>
178181
<div class="dropdown-menu">
179182
<h6 class="dropdown-header">New PDF node</h6>
180-
<button id="addPDFAsSiblingBtn" class="btn dropdown-item" data-bs-toggle="modal" data-bs-target="#selectPDFModal">
183+
<button id="addPDFAsSiblingBtn" class="btn dropdown-item" data-bs-toggle="modal"
184+
data-bs-target="#selectPDFModal">
181185
<i class="bi bi-node-plus-fill"> </i> As sibling node
182186
</button>
183-
<button id="addPDFAsChildBtn" class="btn dropdown-item" data-bs-toggle="modal" data-bs-target="#selectPDFModal">
184-
<i class="bi bi-diagram-2-fill" style="transform: rotate(-90deg); display: inline-block;"> </i> As child node
187+
<button id="addPDFAsChildBtn" class="btn dropdown-item" data-bs-toggle="modal"
188+
data-bs-target="#selectPDFModal">
189+
<i class="bi bi-diagram-2-fill" style="transform: rotate(-90deg); display: inline-block;"> </i> As child
190+
node
185191
<span class="shortcut">Ctrl + P</span>
186192
</button>
187193
</div>
@@ -275,8 +281,7 @@ <h2 class="accordion-header" id="headingThree">
275281
<ol class="list-group list-group-flush list-group-numbered">
276282
<li class="list-group-item">
277283
Ensure you followed
278-
<a
279-
href="https://github.com/jabref/jabmap/#running-locally">
284+
<a href="https://github.com/jabref/jabmap/#running-locally">
280285
running it locally</a>
281286
step of the documentation.
282287
</li>

src/jsmind/src/jsmind.view_provider.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,14 @@ export class ViewProvider {
505505
// Wrapping node's topic
506506
const maxTopicLength = 45;
507507
let topic = node.topic;
508-
if (topic.length > maxTopicLength) {
509-
topic = topic.slice(0, maxTopicLength - 1 - 3) + '...';
508+
let applied_icons = node.data.icons || [];
509+
if (topic.length + applied_icons.length > maxTopicLength) {
510+
// The "5" = '...'.length + 2 chars for left-right padding
511+
topic = topic.slice(0, maxTopicLength - 5 - applied_icons.length * 2) + '...';
510512
}
511513

512514
// Building HTML <img> tags to attach to the node
513-
let icons = (node.data.icons || [])
515+
let icons = applied_icons
514516
.map(iconKey => `<img src="${this.resourceManager.TAG_ICONS[iconKey]}" style="width: 16px; height: 16px; margin-right: 2px; vertical-align: middle;">`)
515517
.join('');
516518
if (!!node.data.type && node.data.type !== 'Text') {

src/main.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ const jm = new jsMind(options);
113113
jm.add_event_listener((type, data) => {
114114
if (type === jsMind.event_type.show) {
115115
addPopoversToBibEntryNodes();
116-
jm.select_clear();
117116

118117
redoBtn.disabled = !jm.actionStack.isRedoable;
119118
undoBtn.disabled = !jm.actionStack.isUndoable;
@@ -132,15 +131,19 @@ jm.add_event_listener((type, data) => {
132131
hidePopovers();
133132

134133
// disable nodes' buttons, if no node's selected
135-
let isNodeSelected = !!jm.get_selected_node();
134+
let selectedNode = jm.get_selected_node();
136135
let buttons = [
137136
newChildBtn,
138137
newSiblingBtn,
139138
tagsDropdownMenuButton,
140139
BibEntryDropdownMenuButton,
141140
PDFDropDownMenuButton
142141
];
143-
toggleButtonsEnabled(buttons, isNodeSelected);
142+
toggleButtonsEnabled(buttons, !!selectedNode);
143+
144+
if (selectedNode?.isroot) {
145+
toggleButtonsEnabled([newSiblingBtn], false);
146+
}
144147
}
145148
});
146149

@@ -420,6 +423,11 @@ addBibEntryAsSiblingBtn.onclick = async function () {
420423
});
421424
}
422425

426+
// disable siblings' option if root's selected
427+
BibEntryDropdownMenuButton.onclick = function () {
428+
addBibEntryAsSiblingBtn.disabled = jm.get_selected_node()?.isroot;
429+
}
430+
423431
//#endregion
424432
//#region [PDF Nodes]
425433

@@ -505,6 +513,11 @@ addSelectedPDFBtn.onclick = function () {
505513
jm.saveState();
506514
};
507515

516+
// disable siblings' option if root's selected
517+
PDFDropDownMenuButton.onclick = function () {
518+
addPDFAsSiblingBtn.disabled = jm.get_selected_node()?.isroot;
519+
}
520+
508521
//#endregion
509522
//#region [Icons & Tags]
510523

@@ -620,4 +633,4 @@ document.addEventListener('show.bs.modal', function (event) {
620633
}
621634
});
622635

623-
//#endregion
636+
//#endregion

0 commit comments

Comments
 (0)