Skip to content

Commit 33c223c

Browse files
committed
[bibtex] bibtex entry ux... get rid of double click
SQUASHED: AUTO-COMMIT-src-client-lively.js,AUTO-COMMIT-src-components-widgets-lively-bibtex-entry.html,AUTO-COMMIT-src-components-widgets-lively-bibtex-entry.js,AUTO-COMMIT-src-components-widgets-lively-morph.js,
1 parent 676fc83 commit 33c223c

File tree

4 files changed

+118
-64
lines changed

4 files changed

+118
-64
lines changed

src/client/lively.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ export default class Lively {
15161516
}
15171517
return pos.subPt(lively.getGlobalPosition(worldContext))
15181518
}
1519-
1519+
15201520
// lively.openBrowser("https://lively4/etc/mounts", true, "Github")
15211521
static async openBrowser(url, edit, patternOrPostion, replaceExisting, worldContext) {
15221522
worldContext = worldContext || document.body

src/components/widgets/lively-bibtex-entry.html

Lines changed: 94 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,106 @@
33
<style data-src="/templates/livelystyle.css"></style>
44
<style>
55
:host {
6-
width: fill-available;
7-
}
8-
:host(.selected) #root {
9-
background-color: rgba(150,150,255,0.1);
10-
outline: 1px solid rgba(150,150,255,0.3);
11-
}
12-
#content {
13-
display: none
14-
}
15-
#title {
16-
font-style: italic
17-
}
18-
#entry {
19-
text-indent: -20px;
20-
margin-left: 20px;
21-
padding: 3px;
22-
}
23-
#key {
24-
font-weight: bold
25-
}
26-
27-
:host([mode="edit"]) #content {
28-
display: block;
29-
white-space: pre;
30-
font-family: courier;
31-
font-size: 9pt;
32-
overflow: scroll;
33-
width: 600px;
34-
}
35-
36-
:host([mode="edit"]) #entry {
37-
display: none;
38-
}
39-
40-
#filename {
41-
/* display: none; */
42-
}
43-
44-
:host([mode="edit"]) #filename {
45-
display: block;
46-
}
6+
width: fill-available;
7+
}
8+
:host(.selected) #root {
9+
background-color: rgba(150,150,255,0.1);
10+
outline: 1px solid rgba(150,150,255,0.3);
11+
}
12+
#root {
13+
position: relative;
14+
}
15+
16+
#content {
17+
display: none
18+
}
19+
20+
#title {
21+
font-style: italic
22+
}
23+
24+
#entry {
25+
text-indent: -20px;
26+
margin-left: 20px;
27+
padding: 3px;
28+
}
29+
30+
#entry > * {
31+
text-indent: 0px;
32+
margin-left: 0px;
33+
margin: 0px
34+
}
35+
36+
#key {
37+
font-weight: bold
38+
}
39+
40+
:host([mode="edit"]) #content {
41+
display: block;
42+
white-space: pre;
43+
font-family: courier;
44+
font-size: 9pt;
45+
overflow: scroll;
46+
width: 100%;
47+
background: white;
48+
}
49+
50+
:host([mode="edit"]) #entry {
51+
display: none;
52+
}
53+
54+
:host([mode="readonly"]) #edit {
55+
display: none;
56+
}
57+
58+
#cancel {
59+
display: none;
60+
}
61+
62+
:host([mode="edit"]) #cancel {
63+
display: block;
64+
}
65+
66+
#edit {
67+
color: lightgray;
68+
}
69+
70+
#key:hover, .academic:hover, #edit:hover, #cancel:hover {
71+
color: darkblue;
72+
text-decoration: underline currentcolor;
73+
}
74+
75+
76+
#cancel {
77+
position: absolute;
78+
top: 0px;
79+
right: 0px;
80+
}
81+
82+
83+
#draghandle {
84+
width: 6px;
85+
height: 6px;
86+
background: darkblue;
87+
display: inline-block;
88+
border-radius: 4px;
89+
border: 1px solid darkblue;
90+
91+
}
92+
93+
#draghandle:hover {
94+
border: 1px solid orange;
95+
}
4796
</style>
4897
<div id="root">
4998
<div id="entry">
99+
<div id="draghandle"></div>
50100
[<span id="key"></span>] <span id="author"></span>. <span id="year"></span>.
51101
<span id="title"></span>
52102
<span id="misc"></span>
103+
<span id="edit" title="edit entry"><i class="fa fa-pencil" aria-hidden="true"></i></span>
53104
</div>
54-
<div id="content">
55-
<div id="filename"></div>
56-
<slot></slot>
57-
</div>
105+
<div id="cancel" title="cancel editing"><i class="fa fa-ban" aria-hidden="true"></i></div>
106+
<div id="content"><slot></slot></div>
58107
</div>
59108
</template>

src/components/widgets/lively-bibtex-entry.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ export default class LivelyBibtexEntry extends Morph {
1919
} catch(e) {
2020
console.warn("[lively-bibtex-entry] initialize failed, could not parse ", this.textContent)
2121
}
22-
this.addEventListener("dblclick", evt => this.onDblClick(evt));
23-
2422
this.get("#entry").addEventListener("dragstart", evt => this.onDragStart(evt));
2523

26-
this.get("#entry").draggable = true;
24+
this.get("#draghandle").draggable = true;
2725
}
2826

29-
async onDragStart(evt) {
30-
27+
async onDragStart(evt) {
3128
evt.dataTransfer.setData("application/lively4id", lively.ensureID(this));
3229

3330
if (evt.ctrlKey) {
@@ -37,10 +34,9 @@ export default class LivelyBibtexEntry extends Morph {
3734
}
3835
}
3936

40-
onDblClick(evt) {
41-
if (this.getAttribute("mode") == "readonly") return
42-
if (this.getAttribute("mode") == "edit") {
43-
var newvalue;
37+
38+
disableEditing() {
39+
var newvalue;
4440
try {
4541
newvalue = Parser.toJSON(this.textContent);
4642
} catch (e) {
@@ -51,10 +47,10 @@ export default class LivelyBibtexEntry extends Morph {
5147
this.setAttribute("mode", "view");
5248
this.removeAttribute("contenteditable");
5349
}
54-
} else {
55-
this.setAttribute("mode", "edit");
56-
this.setAttribute("contenteditable", "true");
57-
}
50+
}
51+
enableEditing() {
52+
this.setAttribute("mode", "edit");
53+
this.setAttribute("contenteditable", "true");
5854
}
5955

6056
get value() {
@@ -82,7 +78,9 @@ export default class LivelyBibtexEntry extends Morph {
8278
updateView() {
8379
if (!this.value || !this.value.entryTags) return;
8480
this.get("#key").textContent = this.key;
85-
this.get("#key").addEventListener("click", () => lively.openBrowser("bib://" + this.key))
81+
this.followURLonClick(this.get("#key"), "bib://" + this.key)
82+
this.get("#edit").addEventListener("click", () => this.enableEditing())
83+
this.get("#cancel").addEventListener("click", () => this.disableEditing())
8684
try {
8785
this.get("#author").textContent = this.parseAuthors(latexconv.convertLaTeXToUnicode(this.author)).join(", ");
8886
} catch (e) {
@@ -101,10 +99,6 @@ export default class LivelyBibtexEntry extends Morph {
10199
this.get("#misc").appendChild(<span class="academic"
102100
click={() => lively.openBrowser(url)}>[academic]</span>)
103101
}
104-
105-
106-
107-
this.get("#filename").textContent = "// " + this.generateFilename() + "";
108102
}
109103

110104
generateFilename() {

src/components/widgets/lively-morph.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ export default class Morph extends HTMLElement {
8989
return "[" + this.constructor.name + "]"
9090
}
9191

92+
followURLonClick(element, url) {
93+
lively.removeEventListener("followurl", element, "click")
94+
lively.addEventListener("followurl", element, "click", (evt) => {
95+
// distinguish between clicking and selecting text
96+
if(window.getSelection().toString().length == 0) {
97+
lively.openBrowser(url)
98+
}
99+
})
100+
}
101+
102+
92103
// another option is 'inplace'
93104
get livelyUpdateStrategy() { return 'migrate'; }
94105
}

0 commit comments

Comments
 (0)