Skip to content

Commit

Permalink
Merge branch 'main' into feature/allow-addon-page-url-as-code
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Oct 4, 2024
2 parents 3b2f75c + 9ced6be commit 77f977d
Show file tree
Hide file tree
Showing 25 changed files with 147 additions and 109 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,14 @@ Christian Donat <https://github.com/cdonat2>
Asuka Minato <https://asukaminato.eu.org>
Dillon Baldwin <https://github.com/DillBal>
Voczi <https://github.com/voczi>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Ben Nguyen <105088397+bpnguyen107@users.noreply.github.com>
Themis Demetriades <themis100@outlook.com>
Luke Bartholomew <lukesbart@icloud.com>
Gregory Abrasaldo <degeemon@gmail.com>
Taylor Obyen <162023405+taylorobyen@users.noreply.github.com>
Kris Cherven <krischerven@gmail.com>
twwn <github.com/twwn>
Shirish Pokhrel <singurty@gmail.com>
Park Hyunwoo <phu54321@naver.com>

********************
Expand Down
2 changes: 1 addition & 1 deletion qt/aqt/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def onHelp(self) -> None:

def on_create_copy(self) -> None:
if note := self.table.get_current_note():
deck_id = self.table.get_current_card().did
deck_id = self.table.get_current_card().current_deck_id()
aqt.dialogs.open("AddCards", self.mw).set_note(note, deck_id)

@no_arg_trigger
Expand Down
2 changes: 1 addition & 1 deletion qt/aqt/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ def reset_image_occlusion(self) -> None:
self.web.eval("resetIOImageLoaded()")

def update_occlusions_field(self) -> None:
self.web.eval("updateOcclusionsField()")
self.web.eval("saveOcclusions()")

def _setup_mask_editor(self, io_options: dict):
self.web.eval(
Expand Down
2 changes: 1 addition & 1 deletion qt/aqt/reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ def forget_current_card(self) -> None:
def on_create_copy(self) -> None:
if self.card:
aqt.dialogs.open("AddCards", self.mw).set_note(
self.card.note(), self.card.did
self.card.note(), self.card.current_deck_id()
)

def delete_current_note(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions rslib/src/import_export/text/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,9 @@ impl ForeignCard {
}

fn native_due(self, timing: &SchedTimingToday) -> i32 {
let day_start = timing.next_day_at.0 as i32 - 86_400;
let day_start = timing.next_day_at.0 - 86_400;
let due_delta = (self.due - day_start) / 86_400;
due_delta + timing.days_elapsed as i32
due_delta as i32 + timing.days_elapsed as i32
}
}

Expand Down
2 changes: 1 addition & 1 deletion rslib/src/import_export/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct ForeignNote {
#[serde(default)]
pub struct ForeignCard {
/// Seconds-based timestamp
pub due: i32,
pub due: i64,
/// In days
pub interval: u32,
pub ease_factor: f32,
Expand Down
5 changes: 3 additions & 2 deletions rslib/src/search/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ pub enum SearchNode {
EditedInDays(u32),
CardTemplate(TemplateKind),
Deck(String),
/// Matches cards in a list of decks (original_deck_id is not checked).
/// Matches cards in a list of deck ids. Cards are matched even if they are
/// in a filtered deck.
DeckIdsWithoutChildren(String),
/// Matches cards in a deck or its children (original_deck_id is not
/// checked).
/// checked, so filtered cards are not matched).
DeckIdWithChildren(DeckId),
IntroducedInDays(u32),
NotetypeId(NotetypeId),
Expand Down
7 changes: 6 additions & 1 deletion rslib/src/search/sqlwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ impl SqlWriter<'_> {
write!(self.sql, "n.mid = {}", ntid).unwrap();
}
SearchNode::DeckIdsWithoutChildren(dids) => {
write!(self.sql, "c.did in ({})", dids).unwrap();
write!(
self.sql,
"c.did in ({}) or (c.odid != 0 and c.odid in ({}))",
dids, dids
)
.unwrap();
}
SearchNode::DeckIdWithChildren(did) => self.write_deck_id_with_children(*did)?,
SearchNode::Notetype(notetype) => self.write_notetype(&norm(notetype)),
Expand Down
28 changes: 15 additions & 13 deletions rslib/src/typeanswer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ macro_rules! format_typeans {

// Public API
pub fn compare_answer(expected: &str, typed: &str, combining: bool) -> String {
if typed.is_empty() {
format_typeans!(htmlescape::encode_minimal(&prepare_expected(expected)))
} else if combining {
Diff::new(expected, typed).to_html()
} else {
DiffNonCombining::new(expected, typed).to_html()
let stripped = strip_expected(expected);

match typed.is_empty() {
true => format_typeans!(htmlescape::encode_minimal(&stripped)),
false if combining => Diff::new(&stripped, typed).to_html(),
false => DiffNonCombining::new(&stripped, typed).to_html(),
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ fn slice(chars: &[char], start: usize, end: usize) -> String {
chars[start..end].iter().collect()
}

fn prepare_expected(expected: &str) -> String {
fn strip_expected(expected: &str) -> String {
let no_av_tags = strip_av_tags(expected);
let no_linebreaks = LINEBREAKS.replace_all(&no_av_tags, " ");
strip_html(&no_linebreaks).trim().to_string()
Expand Down Expand Up @@ -167,7 +167,7 @@ impl DiffTrait for Diff {
fn new(expected: &str, typed: &str) -> Self {
Self {
typed: Self::normalize_typed(typed),
expected: normalize(&prepare_expected(expected)),
expected: normalize(expected),
}
}
fn normalize_typed(typed: &str) -> Vec<char> {
Expand Down Expand Up @@ -202,7 +202,7 @@ impl DiffTrait for DiffNonCombining {
let mut expected_stripped = String::new();
// tokenized into "char+combining" for final rendering
let mut expected_split: Vec<String> = Vec::new();
for c in normalize(&prepare_expected(expected)) {
for c in normalize(expected) {
if unicode_normalization::char::is_combining_mark(c) {
if let Some(last) = expected_split.last_mut() {
last.push(c);
Expand All @@ -219,7 +219,7 @@ impl DiffTrait for DiffNonCombining {
expected: expected_stripped.chars().collect(),
},
expected_split,
expected_original: prepare_expected(expected),
expected_original: expected.to_string(),
}
}

Expand Down Expand Up @@ -340,7 +340,8 @@ mod test {

#[test]
fn html_and_media() {
let ctx = Diff::new("[sound:foo.mp3]<b>1</b> &nbsp;2", "1 2");
let stripped = strip_expected("[sound:foo.mp3]<b>1</b> &nbsp;2");
let ctx = Diff::new(&stripped, "1 2");
// the spacing is handled by wrapping html output in white-space: pre-wrap
assert_eq!(ctx.to_tokens().expected_tokens, &[good("1 2")]);
}
Expand Down Expand Up @@ -387,9 +388,10 @@ mod test {

#[test]
fn tags_removed() {
assert_eq!(prepare_expected("<div>123</div>"), "123");
let stripped = strip_expected("<div>123</div>");
assert_eq!(stripped, "123");
assert_eq!(
Diff::new("<div>123</div>", "123").to_html(),
Diff::new(&stripped, "123").to_html(),
"<code id=typeans><span class=typeGood>123</span></code>"
);
}
Expand Down
6 changes: 3 additions & 3 deletions ts/editor/NoteEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}
globalThis.setImageField = setImageField;
function updateOcclusionsField(): void {
function saveOcclusions(): void {
if (isImageOcclusion && globalThis.canvas) {
const occlusionsData = exportShapesToClozeDeletions($hideAllGuessOne);
fieldStores[ioFields.occlusions].set(occlusionsData.clozes);
Expand Down Expand Up @@ -572,7 +572,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
triggerChanges,
setIsImageOcclusion,
setupMaskEditor,
updateOcclusionsField,
saveOcclusions,
...oldEditorAdapter,
});
Expand Down Expand Up @@ -637,7 +637,7 @@ the AddCards dialog) should be implemented in the user of this component.
<div style="display: {$ioMaskEditorVisible ? 'block' : 'none'};">
<ImageOcclusionPage
mode={imageOcclusionMode}
on:change={updateOcclusionsField}
on:save={saveOcclusions}
on:image-loaded={onImageLoaded}
/>
</div>
Expand Down
5 changes: 3 additions & 2 deletions ts/editor/editor-toolbar/BoldButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return match.remove();
}
const fontWeight = element.style.fontWeight;
if (fontWeight === "bold" || Number(fontWeight) >= 700) {
const fontWeight = getComputedStyle(element).fontWeight;
const threshold = 700;
if (fontWeight && Number(fontWeight) >= threshold) {
return match.clear((): void => {
if (
removeStyleProperties(element, "font-weight") &&
Expand Down
3 changes: 2 additions & 1 deletion ts/editor/editor-toolbar/ItalicButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
return match.remove();
}
if (["italic", "oblique"].includes(element.style.fontStyle)) {
const fontStyle = getComputedStyle(element).fontStyle;
if (["italic", "oblique"].includes(fontStyle)) {
return match.clear((): void => {
if (
removeStyleProperties(element, "font-style") &&
Expand Down
2 changes: 1 addition & 1 deletion ts/routes/image-occlusion/ImageOcclusionPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</div>

<div hidden={activeTabValue != 1}>
<MasksEditor {mode} on:change on:image-loaded />
<MasksEditor {mode} on:save on:image-loaded />
</div>

<div hidden={activeTabValue != 2}>
Expand Down
40 changes: 19 additions & 21 deletions ts/routes/image-occlusion/MaskEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script context="module" lang="ts">
import { writable } from "svelte/store";
const changeSignal = writable(Symbol());
export function emitChangeSignal() {
changeSignal.set(Symbol());
}
</script>

<script lang="ts">
import type { fabric } from "fabric";
Expand All @@ -25,6 +16,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Toolbar from "./Toolbar.svelte";
import { MaskEditorAPI } from "./tools/api";
import { onResize } from "./tools/tool-zoom";
import { saveNeededStore } from "./store";
export let mode: IOMode;
const iconSize = 80;
Expand All @@ -38,27 +30,29 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const dispatch = createEventDispatcher();
function onChange() {
dispatch("change", { canvas });
}
function onImageLoaded({ path, noteId }: ImageLoadedEvent) {
dispatch("image-loaded", { path, noteId });
}
$: $changeSignal, onChange();
const unsubscribe = saveNeededStore.subscribe((saveNeeded: boolean) => {
if (saveNeeded === false) {
return;
}
dispatch("save");
saveNeededStore.set(false);
});
function init(_node: HTMLDivElement) {
if (mode.kind == "add") {
setupMaskEditor(mode.imagePath, onChange, onImageLoaded).then((canvas1) => {
// Editing occlusions on a new note through the "Add" window
setupMaskEditor(mode.imagePath, onImageLoaded).then((canvas1) => {
canvas = canvas1;
});
} else {
setupMaskEditorForEdit(mode.noteId, onChange, onImageLoaded).then(
(canvas1) => {
canvas = canvas1;
},
);
// Editing occlusions on an existing note through the "Browser" window
setupMaskEditorForEdit(mode.noteId, onImageLoaded).then((canvas1) => {
canvas = canvas1;
});
}
}
Expand All @@ -68,10 +62,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
onDestroy(() => {
window.removeEventListener("resize", resizeEvent);
unsubscribe();
});
const resizeEvent = () => {
onResize(canvas!);
if (canvas === null) {
return;
}
onResize(canvas);
};
</script>

Expand Down
Loading

0 comments on commit 77f977d

Please sign in to comment.