Skip to content

Commit

Permalink
fix: handle negative translations correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Kneemund committed Nov 28, 2024
1 parent 01f7019 commit b83d430
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
31 changes: 4 additions & 27 deletions crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,7 @@ impl Engine {
});

if let Pen::Typewriter(typewriter) = self.penholder.current_pen_ref() {
typewriter.refresh_spellcheck_cache_in_modifying_stroke(&mut EngineViewMut {
tasks_tx: self.tasks_tx.clone(),
pens_config: &mut self.pens_config,
document: &mut self.document,
store: &mut self.store,
camera: &mut self.camera,
audioplayer: &mut self.audioplayer,
spellcheck: &mut self.spellcheck,
});
typewriter.refresh_spellcheck_cache_in_modifying_stroke(&mut engine_view_mut!(self));

widget_flags.redraw = true;
}
Expand All @@ -387,15 +379,8 @@ impl Engine {

pub fn get_spellcheck_corrections(&self) -> Option<Vec<String>> {
if let Pen::Typewriter(typewriter) = self.penholder.current_pen_ref() {
return typewriter.get_spellcheck_correction_in_modifying_stroke(&mut EngineView {
tasks_tx: self.tasks_tx.clone(),
pens_config: &self.pens_config,
document: &self.document,
store: &self.store,
camera: &self.camera,
audioplayer: &self.audioplayer,
spellcheck: &self.spellcheck,
});
return typewriter
.get_spellcheck_correction_in_modifying_stroke(&mut engine_view!(self));
}

None
Expand All @@ -405,15 +390,7 @@ impl Engine {
if let Pen::Typewriter(typewriter) = self.penholder.current_pen_mut() {
return typewriter.apply_spellcheck_correction_in_modifying_stroke(
correction,
&mut EngineViewMut {
tasks_tx: self.tasks_tx.clone(),
pens_config: &mut self.pens_config,
document: &mut self.document,
store: &mut self.store,
camera: &mut self.camera,
audioplayer: &mut self.audioplayer,
spellcheck: &mut self.spellcheck,
},
&mut engine_view_mut!(self),
);
}

Expand Down
7 changes: 5 additions & 2 deletions crates/rnote-engine/src/strokes/textstroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,13 +906,16 @@ impl TextStroke {
/// Translate the ranged text attributes after the given cursor.
///
/// Overlapping ranges are extended / shrunk
///
/// * `from_pos` is always the start of the range to translate.
/// * `offset` is the translation. The end of the range is calculated by adding the **absolute** value of the offset.
fn translate_attrs_after_cursor(&mut self, from_pos: usize, offset: i32) {
let translated_words = if offset < 0 {
let to_pos = from_pos.saturating_add_signed(offset as isize);
let to_pos = from_pos.saturating_add(offset.unsigned_abs() as usize);
self.spellcheck_result
.errors
.split_off(&to_pos)
.split_off(&from_pos)
.split_off(&to_pos)
} else {
self.spellcheck_result.errors.split_off(&from_pos)
};
Expand Down

0 comments on commit b83d430

Please sign in to comment.