Skip to content

Commit

Permalink
fix the bits that I missed
Browse files Browse the repository at this point in the history
  • Loading branch information
alsuren committed Sep 9, 2023
1 parent 2dd7a31 commit 649a921
Showing 1 changed file with 89 additions and 36 deletions.
125 changes: 89 additions & 36 deletions src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ impl Editor {
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
// FIXME: not sure whether this should append or prepend
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
Expand All @@ -259,10 +260,18 @@ impl Editor {
fn cut_from_start(&mut self) {
let insertion_offset = self.line_buffer.insertion_point();
if insertion_offset > 0 {
self.cut_buffer.set(
&self.line_buffer.get_buffer()[..insertion_offset],
ClipboardMode::Normal,
);
let cut_slice = &self.line_buffer.get_buffer()[..insertion_offset];
let combined;
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
&combined
} else {
cut_slice
}
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_to_insertion_point();
}
}
Expand Down Expand Up @@ -295,7 +304,7 @@ impl Editor {
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
Expand All @@ -314,7 +323,7 @@ impl Editor {
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
Expand All @@ -330,10 +339,16 @@ impl Editor {
let left_index = self.line_buffer.word_left_index();
if left_index < insertion_offset {
let cut_range = left_index..insertion_offset;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
self.line_buffer.set_insertion_point(left_index);
}
Expand All @@ -344,10 +359,16 @@ impl Editor {
let left_index = self.line_buffer.big_word_left_index();
if left_index < insertion_offset {
let cut_range = left_index..insertion_offset;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
self.line_buffer.set_insertion_point(left_index);
}
Expand All @@ -358,10 +379,16 @@ impl Editor {
let right_index = self.line_buffer.word_right_index();
if right_index > insertion_offset {
let cut_range = insertion_offset..right_index;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
}
}
Expand All @@ -371,10 +398,16 @@ impl Editor {
let right_index = self.line_buffer.next_whitespace();
if right_index > insertion_offset {
let cut_range = insertion_offset..right_index;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
}
}
Expand All @@ -384,10 +417,16 @@ impl Editor {
let right_index = self.line_buffer.word_right_start_index();
if right_index > insertion_offset {
let cut_range = insertion_offset..right_index;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
}
}
Expand All @@ -397,10 +436,16 @@ impl Editor {
let right_index = self.line_buffer.big_word_right_start_index();
if right_index > insertion_offset {
let cut_range = insertion_offset..right_index;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let combined;
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
}
}
Expand All @@ -409,11 +454,19 @@ impl Editor {
let insertion_offset = self.line_buffer.insertion_point();
let right_index = self.line_buffer.grapheme_right_index();
if right_index > insertion_offset {
let combined;
let cut_range = insertion_offset..right_index;
self.cut_buffer.set(
&self.line_buffer.get_buffer()[cut_range.clone()],
ClipboardMode::Normal,
);
let cut_slice = &self.line_buffer.get_buffer()[cut_range.clone()];
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
}
};
self.cut_buffer.set(cut_slice, ClipboardMode::Normal);
self.line_buffer.clear_range(cut_range);
}
}
Expand Down Expand Up @@ -484,7 +537,7 @@ impl Editor {
let cut_slice = {
if self.last_edit_was_cut {
let existing = self.cut_buffer.get().0;
combined = format!("{cut_slice}{existing}");
combined = format!("{existing}{cut_slice}");
&combined
} else {
cut_slice
Expand Down

0 comments on commit 649a921

Please sign in to comment.