Skip to content

Commit f303495

Browse files
committed
Partial preceding
1 parent bdc36d4 commit f303495

8 files changed

Lines changed: 61 additions & 63 deletions

File tree

bin/ankiutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import fields, is_dataclass, asdict
33
from types import GenericAlias
44
from typing import TypeVar
5-
#from aqt import mw
5+
from aqt import mw
66

77

88
# Versioning ######################################################################

bin/fc2-back.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,24 @@
317317
this.viewport.insertAdjacentElement('beforebegin', title);
318318
}
319319
}
320-
this.content.querySelectorAll('.cloze').forEach(((cloze) => {
321-
if (this.expose(cloze))
320+
let active_found = false;
321+
this.content.querySelectorAll('.cloze-inactive, .cloze').forEach(((cloze) => {
322+
const active = cloze.classList.contains('.cloze');
323+
active_found || (active_found = active);
324+
if (this.expose(cloze) || !active && cloze.querySelector('.cloze')) {
325+
cloze.classList.remove('cloze-inactive');
322326
return;
323-
if (this.cfg.front) {
327+
}
328+
if (active && this.cfg.front) {
324329
cloze.dataset.hint = cloze.innerHTML === '[...]'
325330
? this.cfg.prompt
326331
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || "";
327332
this.hide(cloze);
328333
}
329334
else
330335
cloze.dataset.hint = this.cfg.prompt;
331-
}));
332-
this.content.querySelectorAll('.cloze-inactive').forEach(((cloze) => {
333-
if (this.expose(cloze) || cloze.querySelector('.cloze')) {
334-
cloze.classList.remove('cloze-inactive');
335-
return;
336-
}
337-
cloze.dataset.hint = this.cfg.prompt;
338-
if (!this.cfg.show.inactive)
336+
if (!active && (!this.cfg.show.inactive ||
337+
active_found && this.cfg.show.inactive === 'preceding'))
339338
this.hide(cloze);
340339
}));
341340
if (!this.cfg.show.additional)

bin/fc2-front.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,24 @@
317317
this.viewport.insertAdjacentElement('beforebegin', title);
318318
}
319319
}
320-
this.content.querySelectorAll('.cloze').forEach(((cloze) => {
321-
if (this.expose(cloze))
320+
let active_found = false;
321+
this.content.querySelectorAll('.cloze-inactive, .cloze').forEach(((cloze) => {
322+
const active = cloze.classList.contains('.cloze');
323+
active_found || (active_found = active);
324+
if (this.expose(cloze) || !active && cloze.querySelector('.cloze')) {
325+
cloze.classList.remove('cloze-inactive');
322326
return;
323-
if (this.cfg.front) {
327+
}
328+
if (active && this.cfg.front) {
324329
cloze.dataset.hint = cloze.innerHTML === '[...]'
325330
? this.cfg.prompt
326331
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || "";
327332
this.hide(cloze);
328333
}
329334
else
330335
cloze.dataset.hint = this.cfg.prompt;
331-
}));
332-
this.content.querySelectorAll('.cloze-inactive').forEach(((cloze) => {
333-
if (this.expose(cloze) || cloze.querySelector('.cloze')) {
334-
cloze.classList.remove('cloze-inactive');
335-
return;
336-
}
337-
cloze.dataset.hint = this.cfg.prompt;
338-
if (!this.cfg.show.inactive)
336+
if (!active && (!this.cfg.show.inactive ||
337+
active_found && this.cfg.show.inactive === 'preceding'))
339338
this.hide(cloze);
340339
}));
341340
if (!this.cfg.show.additional)

bin/fc2m-back.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,24 @@
302302
this.viewport.insertAdjacentElement('beforebegin', title);
303303
}
304304
}
305-
this.content.querySelectorAll('.cloze').forEach(((cloze) => {
306-
if (this.expose(cloze))
305+
let active_found = false;
306+
this.content.querySelectorAll('.cloze-inactive, .cloze').forEach(((cloze) => {
307+
const active = cloze.classList.contains('.cloze');
308+
active_found || (active_found = active);
309+
if (this.expose(cloze) || !active && cloze.querySelector('.cloze')) {
310+
cloze.classList.remove('cloze-inactive');
307311
return;
308-
if (this.cfg.front) {
312+
}
313+
if (active && this.cfg.front) {
309314
cloze.dataset.hint = cloze.innerHTML === '[...]'
310315
? this.cfg.prompt
311316
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || "";
312317
this.hide(cloze);
313318
}
314319
else
315320
cloze.dataset.hint = this.cfg.prompt;
316-
}));
317-
this.content.querySelectorAll('.cloze-inactive').forEach(((cloze) => {
318-
if (this.expose(cloze) || cloze.querySelector('.cloze')) {
319-
cloze.classList.remove('cloze-inactive');
320-
return;
321-
}
322-
cloze.dataset.hint = this.cfg.prompt;
323-
if (!this.cfg.show.inactive)
321+
if (!active && (!this.cfg.show.inactive ||
322+
active_found && this.cfg.show.inactive === 'preceding'))
324323
this.hide(cloze);
325324
}));
326325
if (!this.cfg.show.additional)

bin/fc2m-front.html

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,24 @@
302302
this.viewport.insertAdjacentElement('beforebegin', title);
303303
}
304304
}
305-
this.content.querySelectorAll('.cloze').forEach(((cloze) => {
306-
if (this.expose(cloze))
305+
let active_found = false;
306+
this.content.querySelectorAll('.cloze-inactive, .cloze').forEach(((cloze) => {
307+
const active = cloze.classList.contains('.cloze');
308+
active_found || (active_found = active);
309+
if (this.expose(cloze) || !active && cloze.querySelector('.cloze')) {
310+
cloze.classList.remove('cloze-inactive');
307311
return;
308-
if (this.cfg.front) {
312+
}
313+
if (active && this.cfg.front) {
309314
cloze.dataset.hint = cloze.innerHTML === '[...]'
310315
? this.cfg.prompt
311316
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || "";
312317
this.hide(cloze);
313318
}
314319
else
315320
cloze.dataset.hint = this.cfg.prompt;
316-
}));
317-
this.content.querySelectorAll('.cloze-inactive').forEach(((cloze) => {
318-
if (this.expose(cloze) || cloze.querySelector('.cloze')) {
319-
cloze.classList.remove('cloze-inactive');
320-
return;
321-
}
322-
cloze.dataset.hint = this.cfg.prompt;
323-
if (!this.cfg.show.inactive)
321+
if (!active && (!this.cfg.show.inactive ||
322+
active_found && this.cfg.show.inactive === 'preceding'))
324323
this.hide(cloze);
325324
}));
326325
if (!this.cfg.show.additional)

src/py/ankiutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import fields, is_dataclass, asdict
33
from types import GenericAlias
44
from typing import TypeVar
5-
#from aqt import mw
5+
from aqt import mw
66

77

88
# Versioning ######################################################################

src/ts/configuration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export interface Configuration {
2121
previous: string // Iterate to previous cloze
2222
toggle_all: string // Toggle all clozes and fields
2323
}
24-
show: { // `false` means initially collapsed/hidden
25-
inactive: boolean // Inactive clozes
26-
additional: boolean // Additional fields (Note, Mnemonics etc.)
24+
show: { // `false` means initially collapsed/hidden
25+
inactive: boolean|'preceding' // Inactive clozes
26+
additional: boolean // Additional fields (Note, Mnemonics etc.)
2727
},
2828
fields: {
2929
title: boolean|undefined

src/ts/fc2.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,26 @@ export class FC2 {
8080
}
8181

8282
// Prepare active clozes: strip cloze when exposed, store hint and hide as required
83-
this.content.querySelectorAll('.cloze').forEach(((cloze: HTMLElement) => {
84-
if (this.expose(cloze)) return
85-
if (this.cfg.front) {
86-
cloze.dataset.hint = cloze.innerHTML === '[...]'
87-
? this.cfg.prompt
88-
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || ""
89-
this.hide(cloze)
90-
} else cloze.dataset.hint = this.cfg.prompt
91-
}) as any)
92-
9383
// Prepare inactive clozes: expose from expose char or containing active cloze
94-
this.content.querySelectorAll('.cloze-inactive').forEach(((cloze: HTMLElement) => {
95-
if (this.expose(cloze) || cloze.querySelector('.cloze')) {
84+
let active_found = false
85+
this.content.querySelectorAll('.cloze-inactive, .cloze').forEach(((cloze: HTMLElement) => {
86+
const active = cloze.classList.contains('.cloze')
87+
active_found ||= active
88+
if (this.expose(cloze) || !active && cloze.querySelector('.cloze')) {
9689
cloze.classList.remove('cloze-inactive')
9790
return
9891
}
99-
cloze.dataset.hint = this.cfg.prompt
100-
if (!this.cfg.show.inactive) this.hide(cloze)
92+
if (active && this.cfg.front) {
93+
cloze.dataset.hint = cloze.innerHTML === '[...]'
94+
? this.cfg.prompt
95+
: this.cfg.hint.replace('%h', cloze.innerHTML.slice(1, cloze.innerHTML.length - 1)) || ""
96+
this.hide(cloze)
97+
} else cloze.dataset.hint = this.cfg.prompt
98+
if (
99+
!active && (!this.cfg.show.inactive ||
100+
active_found && this.cfg.show.inactive === 'preceding')
101+
)
102+
this.hide(cloze)
101103
}) as any)
102104

103105
// Show additional fields per default depending on config

0 commit comments

Comments
 (0)