Skip to content

Commit b83d430

Browse files
committed
fix: handle negative translations correctly
1 parent 01f7019 commit b83d430

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

crates/rnote-engine/src/engine/mod.rs

+4-27
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,7 @@ impl Engine {
369369
});
370370

371371
if let Pen::Typewriter(typewriter) = self.penholder.current_pen_ref() {
372-
typewriter.refresh_spellcheck_cache_in_modifying_stroke(&mut EngineViewMut {
373-
tasks_tx: self.tasks_tx.clone(),
374-
pens_config: &mut self.pens_config,
375-
document: &mut self.document,
376-
store: &mut self.store,
377-
camera: &mut self.camera,
378-
audioplayer: &mut self.audioplayer,
379-
spellcheck: &mut self.spellcheck,
380-
});
372+
typewriter.refresh_spellcheck_cache_in_modifying_stroke(&mut engine_view_mut!(self));
381373

382374
widget_flags.redraw = true;
383375
}
@@ -387,15 +379,8 @@ impl Engine {
387379

388380
pub fn get_spellcheck_corrections(&self) -> Option<Vec<String>> {
389381
if let Pen::Typewriter(typewriter) = self.penholder.current_pen_ref() {
390-
return typewriter.get_spellcheck_correction_in_modifying_stroke(&mut EngineView {
391-
tasks_tx: self.tasks_tx.clone(),
392-
pens_config: &self.pens_config,
393-
document: &self.document,
394-
store: &self.store,
395-
camera: &self.camera,
396-
audioplayer: &self.audioplayer,
397-
spellcheck: &self.spellcheck,
398-
});
382+
return typewriter
383+
.get_spellcheck_correction_in_modifying_stroke(&mut engine_view!(self));
399384
}
400385

401386
None
@@ -405,15 +390,7 @@ impl Engine {
405390
if let Pen::Typewriter(typewriter) = self.penholder.current_pen_mut() {
406391
return typewriter.apply_spellcheck_correction_in_modifying_stroke(
407392
correction,
408-
&mut EngineViewMut {
409-
tasks_tx: self.tasks_tx.clone(),
410-
pens_config: &mut self.pens_config,
411-
document: &mut self.document,
412-
store: &mut self.store,
413-
camera: &mut self.camera,
414-
audioplayer: &mut self.audioplayer,
415-
spellcheck: &mut self.spellcheck,
416-
},
393+
&mut engine_view_mut!(self),
417394
);
418395
}
419396

crates/rnote-engine/src/strokes/textstroke.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -906,13 +906,16 @@ impl TextStroke {
906906
/// Translate the ranged text attributes after the given cursor.
907907
///
908908
/// Overlapping ranges are extended / shrunk
909+
///
910+
/// * `from_pos` is always the start of the range to translate.
911+
/// * `offset` is the translation. The end of the range is calculated by adding the **absolute** value of the offset.
909912
fn translate_attrs_after_cursor(&mut self, from_pos: usize, offset: i32) {
910913
let translated_words = if offset < 0 {
911-
let to_pos = from_pos.saturating_add_signed(offset as isize);
914+
let to_pos = from_pos.saturating_add(offset.unsigned_abs() as usize);
912915
self.spellcheck_result
913916
.errors
914-
.split_off(&to_pos)
915917
.split_off(&from_pos)
918+
.split_off(&to_pos)
916919
} else {
917920
self.spellcheck_result.errors.split_off(&from_pos)
918921
};

0 commit comments

Comments
 (0)