Add color picker gradient color stop duplication by holding Alt (#4291)

* Add color picker gradient color stop duplication by holding Alt

* Fix bugs

* Bug fix
This commit is contained in:
Keavon Chambers
2026-06-28 17:34:27 -07:00
committed by GitHub
parent a979ccd5bd
commit 244b25708d
5 changed files with 171 additions and 8 deletions

View File

@@ -274,6 +274,18 @@ impl GradientStops {
index
}
/// Insert a copy of the stop at `source_index` (same color and midpoint) at `position`, keeping the stops sorted by position.
/// Returns the index where the copy was inserted, or `None` if `source_index` is out of range.
pub fn duplicate_stop(&mut self, source_index: usize, position: f64) -> Option<usize> {
let color = *self.color.get(source_index)?;
let midpoint = *self.midpoint.get(source_index)?;
let index = self.position.iter().position(|p| *p > position).unwrap_or(self.position.len());
self.position.insert(index, position);
self.midpoint.insert(index, midpoint);
self.color.insert(index, color);
Some(index)
}
/// Reset the midpoint for the interval starting at `index` to its default `0.5`.
pub fn reset_midpoint(&mut self, index: usize) {
if let Some(midpoint) = self.midpoint.get_mut(index) {