Skip to content

Commit 6a5d3cc

Browse files
TrueDoctorKeavon
authored andcommitted
Various small fixes and cleanups (#299)
1 parent dca8474 commit 6a5d3cc

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

client/web/wasm/src/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub fn set_blend_mode_for_selected_layers(blend_mode_svg_style_name: String) ->
233233
"saturation" => BlendMode::Saturation,
234234
"color" => BlendMode::Color,
235235
"luminosity" => BlendMode::Luminosity,
236-
_ => return Err(convert_error(EditorError::Misc("UnknownBlendMode".to_string())).into()),
236+
_ => return Err(convert_error(EditorError::Misc("UnknownBlendMode".to_string()))),
237237
};
238238

239239
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SetBlendModeForSelectedLayers(blend_mode)).map_err(convert_error))

core/document/src/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl fmt::Display for DocumentResponse {
1616
let name = match self {
1717
DocumentResponse::DocumentChanged { .. } => "DocumentChanged",
1818
DocumentResponse::FolderChanged { .. } => "FolderChanged",
19-
DocumentResponse::CreatedLayer { .. } => "SelectLayer",
19+
DocumentResponse::CreatedLayer { .. } => "CreatedLayer",
2020
DocumentResponse::DeletedLayer { .. } => "DeleteLayer",
2121
};
2222

core/editor/src/document/document_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn layer_data<'a>(layer_data: &'a mut HashMap<Vec<LayerId>, LayerData>, path: &[
3939
}
4040

4141
pub fn layer_panel_entry(layer_data: &mut LayerData, layer: &mut Layer, path: Vec<LayerId>) -> LayerPanelEntry {
42-
let blend_mode = layer.blend_mode.clone();
42+
let blend_mode = layer.blend_mode;
4343
let layer_type: LayerType = (&layer.data).into();
4444
let name = layer.name.clone().unwrap_or_else(|| format!("Unnamed {}", layer_type));
4545
let arr = layer.current_bounding_box().unwrap_or([DVec2::ZERO, DVec2::ZERO]);

core/editor/src/document/document_message_handler.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,6 @@ impl DocumentMessageHandler {
118118
fn layerdata_mut(&mut self, path: &[LayerId]) -> &mut LayerData {
119119
self.active_document_mut().layer_data.entry(path.to_vec()).or_insert_with(|| LayerData::new(true))
120120
}
121-
#[allow(dead_code)]
122-
fn create_transform_from_layerdata(&self, path: Vec<u64>, responses: &mut VecDeque<Message>) {
123-
let layerdata = self.layerdata(&path);
124-
responses.push_back(
125-
DocumentOperation::SetLayerTransform {
126-
path,
127-
transform: layerdata.calculate_transform().to_cols_array(),
128-
}
129-
.into(),
130-
);
131-
}
132121
fn create_document_transform_from_layerdata(&self, viewport_size: &ViewportPosition, responses: &mut VecDeque<Message>) {
133122
let half_viewport = viewport_size.as_dvec2() / 2.;
134123
let layerdata = self.layerdata(&[]);
@@ -142,18 +131,18 @@ impl DocumentMessageHandler {
142131
);
143132
}
144133

145-
/// Returns the paths to all layers in order, optionally including only selected layers
134+
/// Returns the paths to all layers in order, optionally including only selected or non
135+
/// selected layers.
146136
fn layers_sorted(&self, selected: Option<bool>) -> Vec<Vec<LayerId>> {
147137
// Compute the indices for each layer to be able to sort them
148-
// TODO: Replace with drain_filter https://github.com/rust-lang/rust/issues/59618
149138
let mut layers_with_indices: Vec<(Vec<LayerId>, Vec<usize>)> = self
150139
.active_document()
151140
.layer_data
152141
.iter()
153142
// 'path.len() > 0' filters out root layer since it has no indices
154143
.filter_map(|(path, data)| (!path.is_empty() && (data.selected == selected.unwrap_or(data.selected))).then(|| path.clone()))
155144
.filter_map(|path| {
156-
// Currently it is possible that layer_data contains layers that are don't actually exist
145+
// Currently it is possible that layer_data contains layers that are don't actually exist (has been partially fixed in #281)
157146
// and thus indices_for_path can return an error. We currently skip these layers and log a warning.
158147
// Once this problem is solved this code can be simplified
159148
match self.active_document().document.indices_for_path(&path) {
@@ -180,7 +169,8 @@ impl DocumentMessageHandler {
180169
self.layers_sorted(Some(true))
181170
}
182171

183-
/// Returns the paths to all selected layers in order
172+
/// Returns the paths to all non_selected layers in order
173+
#[allow(dead_code)] // used for test cases
184174
pub fn non_selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
185175
self.layers_sorted(Some(false))
186176
}

0 commit comments

Comments
 (0)