Skip to content

Commit

Permalink
Keep text layers selected after editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidharth-Singh10 authored and Keavon committed Dec 20, 2024
1 parent 4e6a1f9 commit aaf08eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::messages::portfolio::document::properties_panel::utility_types::Prope
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
use crate::messages::portfolio::document::utility_types::nodes::RawBuffer;
use crate::messages::portfolio::utility_types::PanelType;
use crate::messages::portfolio::utility_types::PersistentData;
use crate::messages::prelude::*;
use crate::messages::tool::common_functionality::graph_modification_utils::{self, get_blend_mode, get_opacity};
Expand Down Expand Up @@ -91,8 +90,6 @@ pub struct DocumentMessageHandler {
pub graph_view_overlay_open: bool,
/// The current opacity of the faded node graph background that covers up the artwork.
pub graph_fade_artwork_percentage: f64,
/// Tracks the currently active panel in the application interface.
pub active_panel: PanelType,

// =============================================
// Fields omitted from the saved document format
Expand Down Expand Up @@ -147,7 +144,7 @@ impl Default for DocumentMessageHandler {
graph_view_overlay_open: false,
snapping_state: SnappingState::default(),
graph_fade_artwork_percentage: 80.,
active_panel: PanelType::Document,

// =============================================
// Fields omitted from the saved document format
// =============================================
Expand Down Expand Up @@ -998,7 +995,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
}
DocumentMessage::SetActivePanel { active_panel: panel } => {
use crate::messages::portfolio::utility_types::PanelType;
self.active_panel = panel;
match panel {
PanelType::Document => {
if self.graph_view_overlay_open {
Expand Down Expand Up @@ -1381,10 +1377,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
}

impl DocumentMessageHandler {
/// Returns the currently active panel in the application interface.
pub fn get_active_panel(&self) -> PanelType {
self.active_panel
}
/// Runs an intersection test with all layers and a viewport space quad
pub fn intersect_quad<'a>(&'a self, viewport_quad: graphene_core::renderer::Quad, ipp: &InputPreprocessorMessageHandler) -> impl Iterator<Item = LayerNodeIdentifier> + 'a {
let document_to_viewport = self.navigation_handler.calculate_offset_transform(ipp.viewport_bounds.center(), &self.document_ptz);
Expand Down
31 changes: 12 additions & 19 deletions editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::messages::portfolio::document::graph_operation::utility_types::Transf
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::network_interface::InputConnector;
use crate::messages::portfolio::utility_types::PanelType;
use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, ToolColorType};
use crate::messages::tool::common_functionality::graph_modification_utils::{self, is_layer_fed_by_node_of_name};

Expand Down Expand Up @@ -243,7 +242,7 @@ struct TextToolData {

impl TextToolData {
/// Set the editing state of the currently modifying layer
fn set_editing(&self, document: &DocumentMessageHandler, editable: bool, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
fn set_editing(&self, editable: bool, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
if let Some(editing_text) = self.editing_text.as_ref().filter(|_| editable) {
responses.add(FrontendMessage::DisplayEditableTextbox {
text: editing_text.text.clone(),
Expand All @@ -254,18 +253,12 @@ impl TextToolData {
transform: editing_text.transform.to_cols_array(),
});
} else {
// Check if DisplayRemoveEditableTextbox is already in the responses queue
let has_remove_textbox = responses.iter().any(|msg| matches!(msg, Message::Frontend(FrontendMessage::DisplayRemoveEditableTextbox)));
responses.add(FrontendMessage::DisplayRemoveEditableTextbox);
let panel_type = document.get_active_panel();
match panel_type {
// If Properties panel is clicked, keep the nodes selected
PanelType::Properties => {
// Do nothing, keep current selection
}
// For other panels, clear selected nodes
_ => {
// Clear all selected nodes when no longer editing
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: Vec::new() });
}

if has_remove_textbox {
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: Vec::new() });
}
}
}
Expand Down Expand Up @@ -293,14 +286,14 @@ impl TextToolData {
}

if tool_state == TextToolFsmState::Editing {
self.set_editing(document, false, font_cache, responses);
self.set_editing(false, font_cache, responses);
}

self.layer = layer;
if self.load_layer_text_node(document).is_some() {
responses.add(DocumentMessage::AddTransaction);

self.set_editing(document, true, font_cache, responses);
self.set_editing(true, font_cache, responses);

responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![self.layer.to_node()] });
// Make the rendered text invisible while editing
Expand Down Expand Up @@ -354,15 +347,15 @@ impl TextToolData {
skip_rerender: true,
});

self.set_editing(document, true, font_cache, responses);
self.set_editing(true, font_cache, responses);

responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![self.layer.to_node()] });

responses.add(NodeGraphMessage::RunDocumentGraph);
TextToolFsmState::Editing
} else {
// Removing old text as editable
self.set_editing(document, false, font_cache, responses);
self.set_editing(false, font_cache, responses);

TextToolFsmState::Ready
}
Expand Down Expand Up @@ -463,7 +456,7 @@ impl Fsm for TextToolFsmState {
}
(state, TextToolMessage::Abort) => {
if state == TextToolFsmState::Editing {
tool_data.set_editing(document, false, font_cache, responses);
tool_data.set_editing(false, font_cache, responses);
}

TextToolFsmState::Ready
Expand All @@ -474,7 +467,7 @@ impl Fsm for TextToolFsmState {
TextToolFsmState::Editing
}
(TextToolFsmState::Editing, TextToolMessage::TextChange { new_text }) => {
tool_data.set_editing(document, false, font_cache, responses);
tool_data.set_editing(false, font_cache, responses);

responses.add(NodeGraphMessage::SetInput {
input_connector: InputConnector::node(graph_modification_utils::get_text_id(tool_data.layer, &document.network_interface).unwrap(), 1),
Expand Down

0 comments on commit aaf08eb

Please sign in to comment.